-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add browser callables to each dev-ui card page
- Loading branch information
Showing
7 changed files
with
170 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...m/github/mcollovati/quarkus/hilla/deployment/devui/QuarkusHillaDevUICommonsProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<WebJarBuildItem> webJarBuildProducer, | ||
BuildProducer<DevUIWebJarBuildItem> devUIWebJarProducer, | ||
BuildProducer<BuildTimeConstBuildItem> buildTimeConstProducer, | ||
EndpointBuildItem endpointBuildItem) { | ||
|
||
final Map<String, Object> 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)); | ||
} | ||
} |
63 changes: 0 additions & 63 deletions
63
...java/com/github/mcollovati/quarkus/hilla/deployment/devui/QuarkusHillaDevUIProcessor.java
This file was deleted.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
...t/src/main/java/com/github/mcollovati/quarkus/hilla/devui/QuarkusHillaDevUIProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CardPageBuildItem> 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); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
lit/deployment/src/main/resources/dev-ui/qwc-quarkus-hilla.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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` | ||
<qwc-quarkus-hilla-browser-callables | ||
namespace='com.github.mcollovati.quarkus-hilla'></qwc-quarkus-hilla-browser-callables>`; | ||
} | ||
} | ||
customElements.define('qwc-quarkus-hilla', QwcQuarkusHilla); |
25 changes: 25 additions & 0 deletions
25
...t/src/main/java/com/github/mcollovati/quarkus/hilla/devui/QuarkusHillaDevUIProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<CardPageBuildItem> 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); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
react/deployment/src/main/resources/dev-ui/qwc-quarkus-hilla-react.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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` | ||
<qwc-quarkus-hilla-browser-callables | ||
namespace='com.github.mcollovati.quarkus-hilla-react'></qwc-quarkus-hilla-browser-callables>`; | ||
} | ||
} | ||
customElements.define('qwc-quarkus-hilla-react', QwcQuarkusHillaReact); |