diff --git a/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/devui/EndpointBuildItem.java b/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/devui/EndpointBuildItem.java index 0d29b74a..f73f2d18 100644 --- a/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/devui/EndpointBuildItem.java +++ b/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/devui/EndpointBuildItem.java @@ -30,4 +30,10 @@ public EndpointBuildItem(List endpoints) { public List getEndpoints() { return endpoints; } + + public int getEndpointMethodCount() { + return endpoints.stream() + .mapToInt(a -> a.children().size()) + .sum(); + } } diff --git a/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/devui/QuarkusHillaDevUICommonsProcessor.java b/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/devui/QuarkusHillaDevUICommonsProcessor.java new file mode 100644 index 00000000..54f144aa --- /dev/null +++ b/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/devui/QuarkusHillaDevUICommonsProcessor.java @@ -0,0 +1,90 @@ +/* + * Copyright 2024 Marco Collovati, Dario Götze + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.github.mcollovati.quarkus.hilla.deployment.devui; + +import io.quarkus.deployment.IsDevelopment; +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.CombinedIndexBuildItem; +import io.quarkus.devui.deployment.BuildTimeConstBuildItem; +import io.quarkus.devui.deployment.DevUIWebJarBuildItem; +import io.quarkus.maven.dependency.GACT; +import io.quarkus.vertx.http.deployment.webjar.WebJarBuildItem; +import io.quarkus.vertx.http.deployment.webjar.WebJarResourcesFilter; +import org.jboss.jandex.AnnotationInstance; +import org.jboss.jandex.AnnotationTarget; +import org.jboss.jandex.DotName; + +import java.io.ByteArrayInputStream; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Stream; + +public class QuarkusHillaDevUICommonsProcessor { + + private static final GACT UI_JAR = new GACT("com.github.mcollovati", "quarkus-hilla-commons-deployment", null, "jar"); + private static final String NAMESPACE = UI_JAR.getGroupId() + "." + UI_JAR.getArtifactId(); + private static final String DEV_UI = "dev-ui"; + + private static final DotName SIGNALS_HANDLER = + DotName.createSimple("com.vaadin.hilla.signals.handler.SignalsHandler"); + + @BuildStep(onlyIf = IsDevelopment.class) + public EndpointBuildItem collectEndpoints(CombinedIndexBuildItem combinedIndexBuildItem) { + final var endpointAnnotated = + combinedIndexBuildItem.getComputingIndex().getAnnotations(EndpointInfo.ENDPOINT_ANNOTATION); + final var browserCallableAnnotated = + combinedIndexBuildItem.getComputingIndex().getAnnotations(EndpointInfo.BROWSER_CALLABLE_ANNOTATION); + final var endpoints = Stream.concat(endpointAnnotated.stream(), browserCallableAnnotated.stream()) + .map(AnnotationInstance::target) + .filter(target -> target.kind().equals(AnnotationTarget.Kind.CLASS)) + .map(AnnotationTarget::asClass) + .filter(c -> !SIGNALS_HANDLER.equals(c.name())) + .map(EndpointInfo::from) + .toList(); + return new EndpointBuildItem(endpoints); + } + + @BuildStep(onlyIf = IsDevelopment.class) + void createShared( + BuildProducer webJarBuildProducer, + BuildProducer devUIWebJarProducer, + BuildProducer buildTimeConstProducer, + EndpointBuildItem endpointBuildItem) { + + final Map buildTimeData = new HashMap<>(); + buildTimeData.put("hillaEndpoints", endpointBuildItem.getEndpoints()); + buildTimeConstProducer.produce(new BuildTimeConstBuildItem(NAMESPACE, buildTimeData)); + + String buildTimeDataImport = NAMESPACE + "-data"; + + webJarBuildProducer.produce(WebJarBuildItem.builder() + .artifactKey(UI_JAR) + .root(DEV_UI + "/") + .filter((fileName, file) -> { + if (fileName.endsWith(".js")) { + String content = new String(file.readAllBytes(), StandardCharsets.UTF_8); + content = content.replaceAll("build-time-data", buildTimeDataImport); + return new WebJarResourcesFilter.FilterResult( + new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)), true); + } + return new WebJarResourcesFilter.FilterResult(file, false); + }) + .build()); + devUIWebJarProducer.produce(new DevUIWebJarBuildItem(UI_JAR, DEV_UI)); + } +} diff --git a/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/devui/QuarkusHillaDevUIProcessor.java b/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/devui/QuarkusHillaDevUIProcessor.java deleted file mode 100644 index f87fcaea..00000000 --- a/commons/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/deployment/devui/QuarkusHillaDevUIProcessor.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2024 Marco Collovati, Dario Götze - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.github.mcollovati.quarkus.hilla.deployment.devui; - -import java.util.stream.Stream; - -import io.quarkus.deployment.IsDevelopment; -import io.quarkus.deployment.annotations.BuildStep; -import io.quarkus.deployment.builditem.CombinedIndexBuildItem; -import io.quarkus.devui.spi.page.CardPageBuildItem; -import io.quarkus.devui.spi.page.Page; -import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.AnnotationTarget; -import org.jboss.jandex.DotName; - -public class QuarkusHillaDevUIProcessor { - - private static final DotName SIGNALS_HANDLER = - DotName.createSimple("com.vaadin.hilla.signals.handler.SignalsHandler"); - - @BuildStep(onlyIf = IsDevelopment.class) - public EndpointBuildItem collectEndpoints(CombinedIndexBuildItem combinedIndexBuildItem) { - final var endpointAnnotated = - combinedIndexBuildItem.getComputingIndex().getAnnotations(EndpointInfo.ENDPOINT_ANNOTATION); - final var browserCallableAnnotated = - combinedIndexBuildItem.getComputingIndex().getAnnotations(EndpointInfo.BROWSER_CALLABLE_ANNOTATION); - final var endpoints = Stream.concat(endpointAnnotated.stream(), browserCallableAnnotated.stream()) - .map(AnnotationInstance::target) - .filter(target -> target.kind().equals(AnnotationTarget.Kind.CLASS)) - .map(AnnotationTarget::asClass) - .filter(c -> !SIGNALS_HANDLER.equals(c.name())) - .map(EndpointInfo::from) - .toList(); - return new EndpointBuildItem(endpoints); - } - - @BuildStep(onlyIf = IsDevelopment.class) - public CardPageBuildItem pages(EndpointBuildItem endpointBuildItems) { - CardPageBuildItem cardPageBuildItem = new CardPageBuildItem(); - cardPageBuildItem.addBuildTimeData("hillaEndpoints", endpointBuildItems.getEndpoints()); - cardPageBuildItem.addPage(Page.webComponentPageBuilder() - .title("Browser callables") - .icon("font-awesome-solid:table-list") - .componentLink("qwc-quarkus-hilla-browser-callables.js") - .staticLabel(String.valueOf(endpointBuildItems.getEndpoints().stream() - .mapToInt(a -> a.children().size()) - .sum()))); - return cardPageBuildItem; - } -} diff --git a/lit/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/devui/QuarkusHillaDevUIProcessor.java b/lit/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/devui/QuarkusHillaDevUIProcessor.java new file mode 100644 index 00000000..eded8a03 --- /dev/null +++ b/lit/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/devui/QuarkusHillaDevUIProcessor.java @@ -0,0 +1,25 @@ +package com.github.mcollovati.quarkus.hilla.devui; + +import com.github.mcollovati.quarkus.hilla.deployment.devui.EndpointBuildItem; +import io.quarkus.deployment.IsDevelopment; +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.devui.spi.page.CardPageBuildItem; +import io.quarkus.devui.spi.page.Page; + +public class QuarkusHillaDevUIProcessor { + + @BuildStep(onlyIf = IsDevelopment.class) + public void pages( + BuildProducer cardPageProducer, + EndpointBuildItem endpointBuildItem) { + CardPageBuildItem cardPageBuildItem = new CardPageBuildItem(); + final var page = Page.webComponentPageBuilder() + .title("Browser callables") + .icon("font-awesome-solid:table-list") + .componentLink("qwc-quarkus-hilla.js") + .staticLabel(String.valueOf(endpointBuildItem.getEndpointMethodCount())); + cardPageBuildItem.addPage(page); + cardPageProducer.produce(cardPageBuildItem); + } +} diff --git a/lit/deployment/src/main/resources/dev-ui/qwc-quarkus-hilla.js b/lit/deployment/src/main/resources/dev-ui/qwc-quarkus-hilla.js new file mode 100644 index 00000000..a7b86037 --- /dev/null +++ b/lit/deployment/src/main/resources/dev-ui/qwc-quarkus-hilla.js @@ -0,0 +1,12 @@ +import { LitElement, html} from 'lit'; +import './../com.github.mcollovati.quarkus-hilla-commons/qwc-quarkus-hilla-browser-callables.js'; + +export class QwcQuarkusHilla extends LitElement { + + render() { + return html` + `; + } +} +customElements.define('qwc-quarkus-hilla', QwcQuarkusHilla); diff --git a/react/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/devui/QuarkusHillaDevUIProcessor.java b/react/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/devui/QuarkusHillaDevUIProcessor.java new file mode 100644 index 00000000..0db2ae71 --- /dev/null +++ b/react/deployment/src/main/java/com/github/mcollovati/quarkus/hilla/devui/QuarkusHillaDevUIProcessor.java @@ -0,0 +1,25 @@ +package com.github.mcollovati.quarkus.hilla.devui; + +import com.github.mcollovati.quarkus.hilla.deployment.devui.EndpointBuildItem; +import io.quarkus.deployment.IsDevelopment; +import io.quarkus.deployment.annotations.BuildProducer; +import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.devui.spi.page.CardPageBuildItem; +import io.quarkus.devui.spi.page.Page; + +public class QuarkusHillaDevUIProcessor { + + @BuildStep(onlyIf = IsDevelopment.class) + public void pages( + BuildProducer cardPageProducer, + EndpointBuildItem endpointBuildItem) { + CardPageBuildItem cardPageBuildItem = new CardPageBuildItem(); + final var page = Page.webComponentPageBuilder() + .title("Browser callables") + .icon("font-awesome-solid:table-list") + .componentLink("qwc-quarkus-hilla-react.js") + .staticLabel(String.valueOf(endpointBuildItem.getEndpointMethodCount())); + cardPageBuildItem.addPage(page); + cardPageProducer.produce(cardPageBuildItem); + } +} diff --git a/react/deployment/src/main/resources/dev-ui/qwc-quarkus-hilla-react.js b/react/deployment/src/main/resources/dev-ui/qwc-quarkus-hilla-react.js new file mode 100644 index 00000000..879066d2 --- /dev/null +++ b/react/deployment/src/main/resources/dev-ui/qwc-quarkus-hilla-react.js @@ -0,0 +1,12 @@ +import { LitElement, html} from 'lit'; +import './../com.github.mcollovati.quarkus-hilla-commons/qwc-quarkus-hilla-browser-callables.js'; + +export class QwcQuarkusHillaReact extends LitElement { + + render() { + return html` + `; + } +} +customElements.define('qwc-quarkus-hilla-react', QwcQuarkusHillaReact);