Skip to content

Commit

Permalink
Easy way to add deployment methods in Dev UI
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <phillip.kruger@gmail.com>
  • Loading branch information
phillip-kruger committed Mar 16, 2024
1 parent 5a38253 commit 5385586
Show file tree
Hide file tree
Showing 23 changed files with 273 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.dev.console.DevConsoleManager;
import io.quarkus.dev.console.TempSystemProperties;
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
import io.quarkus.devui.spi.buildtime.BuildTimeActionBuildItem;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.Page;
import io.quarkus.openshift.runtime.devui.OpenshiftDeploymentJsonRpcService;
import io.vertx.core.json.JsonArray;

public class OpenshiftDevUIProcessor {
Expand All @@ -35,9 +34,10 @@ CardPageBuildItem create(List<AvailableContainerImageExtensionBuildItem> extensi
}

@BuildStep(onlyIf = IsDevelopment.class)
JsonRPCProvidersBuildItem createJsonRPCServiceForContainerBuild() {
DevConsoleManager.register("openshift-deployment-action", build());
return new JsonRPCProvidersBuildItem(OpenshiftDeploymentJsonRpcService.class);
BuildTimeActionBuildItem createBuildTimeActionsForContainerBuild() {
BuildTimeActionBuildItem deployActions = new BuildTimeActionBuildItem();
deployActions.addAction("build", build());
return deployActions;
}

private Function<Map<String, String>, String> build() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
import io.quarkus.dev.console.DevConsoleManager;
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
import io.quarkus.devui.spi.buildtime.BuildTimeActionBuildItem;
import io.quarkus.devui.spi.page.CardPageBuildItem;
import io.quarkus.devui.spi.page.Page;
import io.quarkus.kubernetes.deployment.SelectedKubernetesDeploymentTargetBuildItem;
import io.quarkus.kubernetes.runtime.devui.KubernetesManifestService;
import io.quarkus.kubernetes.spi.GeneratedKubernetesResourceBuildItem;

public class KubernetesDevUIProcessor {
Expand All @@ -39,8 +38,9 @@ CardPageBuildItem create(CurateOutcomeBuildItem bi) {
}

@BuildStep(onlyIf = IsDevelopment.class)
JsonRPCProvidersBuildItem createJsonRPCServiceForCache() {
DevConsoleManager.register("kubernetes-generate-manifest", ignored -> {
BuildTimeActionBuildItem createBuildTimeActions() {
BuildTimeActionBuildItem generateManifestActions = new BuildTimeActionBuildItem();
generateManifestActions.addAction("generateManifests", ignored -> {
try {
List<Manifest> manifests = holder.getManifests();
// Avoid relying on databind.
Expand All @@ -53,7 +53,8 @@ JsonRPCProvidersBuildItem createJsonRPCServiceForCache() {
throw new RuntimeException(e);
}
});
return new JsonRPCProvidersBuildItem(KubernetesManifestService.class);

return generateManifestActions;
}

public static final class Holder {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
import io.quarkus.devui.deployment.extension.Extension;
import io.quarkus.devui.spi.AbstractDevUIBuildItem;
import io.quarkus.devui.spi.DevUIContent;
import io.quarkus.devui.spi.buildtime.BuildTimeAction;
import io.quarkus.devui.spi.buildtime.BuildTimeActionBuildItem;
import io.quarkus.devui.spi.buildtime.QuteTemplateBuildItem;
import io.quarkus.devui.spi.buildtime.StaticContentBuildItem;
import io.quarkus.devui.spi.page.AbstractPageBuildItem;
Expand Down Expand Up @@ -181,6 +183,24 @@ void mapPageBuildTimeData(List<CardPageBuildItem> cards,
}
}

@BuildStep(onlyIf = IsDevelopment.class)
DeploymentMethodBuildItem mapDeploymentMethods(
List<BuildTimeActionBuildItem> buildTimeActions,
CurateOutcomeBuildItem curateOutcomeBuildItem) {

List<String> methodNames = new ArrayList<>();
for (BuildTimeActionBuildItem actions : buildTimeActions) {
String extensionPathName = actions.getExtensionPathName(curateOutcomeBuildItem);
for (BuildTimeAction bta : actions.getActions()) {
String fullName = extensionPathName + "." + bta.getMethodName();
DevConsoleManager.register(fullName, bta.getAction());
methodNames.add(fullName);
}
}

return new DeploymentMethodBuildItem(methodNames);
}

private Map<String, Object> getBuildTimeDataForPage(AbstractPageBuildItem pageBuildItem) {
Map<String, Object> m = new HashMap<>();
if (pageBuildItem.hasBuildTimeData()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.quarkus.devui.deployment;

import java.util.List;

import io.quarkus.builder.item.SimpleBuildItem;

/**
* Hold add discovered build time methods that can be executed via json-rpc
*/
public final class DeploymentMethodBuildItem extends SimpleBuildItem {

private final List<String> methods;

public DeploymentMethodBuildItem(List<String> methods) {
this.methods = methods;
}

public List<String> getMethods() {
return this.methods;
}

public boolean hasMethods() {
return this.methods != null && !this.methods.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,13 @@ void additionalBean(BuildProducer<AdditionalBeanBuildItem> additionalBeanProduce
* This goes through all jsonRPC methods and discover the methods using Jandex
*/
@BuildStep(onlyIf = IsDevelopment.class)
void findAllJsonRPCMethods(BuildProducer<JsonRPCMethodsBuildItem> jsonRPCMethodsProvider,
void findAllJsonRPCMethods(BuildProducer<JsonRPCRuntimeMethodsBuildItem> jsonRPCMethodsProvider,
BuildProducer<BuildTimeConstBuildItem> buildTimeConstProducer,
LaunchModeBuildItem launchModeBuildItem,
CombinedIndexBuildItem combinedIndexBuildItem,
CurateOutcomeBuildItem curateOutcomeBuildItem,
List<JsonRPCProvidersBuildItem> jsonRPCProvidersBuildItems) {
List<JsonRPCProvidersBuildItem> jsonRPCProvidersBuildItems,
DeploymentMethodBuildItem deploymentMethodBuildItem) {

if (launchModeBuildItem.isNotLocalDevModeType()) {
return;
Expand Down Expand Up @@ -369,8 +370,12 @@ void findAllJsonRPCMethods(BuildProducer<JsonRPCMethodsBuildItem> jsonRPCMethods
}
}

if (deploymentMethodBuildItem.hasMethods()) {
requestResponseMethods.addAll(deploymentMethodBuildItem.getMethods());
}

if (!extensionMethodsMap.isEmpty()) {
jsonRPCMethodsProvider.produce(new JsonRPCMethodsBuildItem(extensionMethodsMap));
jsonRPCMethodsProvider.produce(new JsonRPCRuntimeMethodsBuildItem(extensionMethodsMap));
}

BuildTimeConstBuildItem methodInfo = new BuildTimeConstBuildItem("devui-jsonrpc");
Expand All @@ -390,15 +395,16 @@ void findAllJsonRPCMethods(BuildProducer<JsonRPCMethodsBuildItem> jsonRPCMethods
@Record(ExecutionTime.STATIC_INIT)
void createJsonRpcRouter(DevUIRecorder recorder,
BeanContainerBuildItem beanContainer,
JsonRPCMethodsBuildItem jsonRPCMethodsBuildItem) {
JsonRPCRuntimeMethodsBuildItem jsonRPCMethodsBuildItem,
DeploymentMethodBuildItem deploymentMethodBuildItem) {

if (jsonRPCMethodsBuildItem != null) {
Map<String, Map<JsonRpcMethodName, JsonRpcMethod>> extensionMethodsMap = jsonRPCMethodsBuildItem
.getExtensionMethodsMap();

DevConsoleManager.setGlobal(DevUIRecorder.DEV_MANAGER_GLOBALS_JSON_MAPPER_FACTORY,
JsonMapper.Factory.deploymentLinker().createLinkData(new DevUIDatabindCodec.Factory()));
recorder.createJsonRpcRouter(beanContainer.getValue(), extensionMethodsMap);
recorder.createJsonRpcRouter(beanContainer.getValue(), extensionMethodsMap, deploymentMethodBuildItem.getMethods());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
/**
* Simple holder for all discovered Json RPC Methods
*/
public final class JsonRPCMethodsBuildItem extends SimpleBuildItem {
public final class JsonRPCRuntimeMethodsBuildItem extends SimpleBuildItem {

private final Map<String, Map<JsonRpcMethodName, JsonRpcMethod>> extensionMethodsMap;

public JsonRPCMethodsBuildItem(Map<String, Map<JsonRpcMethodName, JsonRpcMethod>> extensionMethodsMap) {
public JsonRPCRuntimeMethodsBuildItem(Map<String, Map<JsonRpcMethodName, JsonRpcMethod>> extensionMethodsMap) {
this.extensionMethodsMap = extensionMethodsMap;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.ide.EffectiveIdeBuildItem;
import io.quarkus.deployment.ide.Ide;
import io.quarkus.dev.console.DevConsoleManager;
import io.quarkus.devui.runtime.ide.IdeJsonRPCService;
import io.quarkus.devui.spi.JsonRPCProvidersBuildItem;
import io.quarkus.devui.spi.buildtime.BuildTimeActionBuildItem;
import io.quarkus.utilities.OS;
import io.quarkus.vertx.http.deployment.HttpRootPathBuildItem;
import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem;
Expand All @@ -32,20 +30,28 @@ public class IdeProcessor {
private static final Map<String, String> LANG_TO_EXT = Map.of("java", "java", "kotlin", "kt");

@BuildStep(onlyIf = IsDevelopment.class)
void createJsonRPCService(BuildProducer<JsonRPCProvidersBuildItem> JsonRPCProvidersProducer,
void createJsonRPCService(BuildProducer<BuildTimeActionBuildItem> buildTimeActionProducer,
Optional<EffectiveIdeBuildItem> effectiveIdeBuildItem) {

if (effectiveIdeBuildItem.isPresent()) {
Ide ide = effectiveIdeBuildItem.get().getIde();
if (ide != null) {
DevConsoleManager.register("dev-ui-ide-open", map -> {
BuildTimeActionBuildItem ideActions = new BuildTimeActionBuildItem(NAMESPACE);

ideActions.addAction("open", map -> {
String fileName = map.get("fileName");
String lang = map.get("lang");
String lineNumber = map.get("lineNumber");

if (isNullOrEmpty(fileName) || isNullOrEmpty(lang)) {
return false;
}

return typicalProcessLaunch(fileName, lang, lineNumber, ide);
});

buildTimeActionProducer.produce(ideActions);
}
JsonRPCProvidersProducer.produce(new JsonRPCProvidersBuildItem("devui-ide-interaction", IdeJsonRPCService.class));
}
}

Expand Down Expand Up @@ -145,4 +151,6 @@ public static void openBrowser(HttpRootPathBuildItem rp, NonApplicationRootPathB
private boolean isNullOrEmpty(String arg) {
return arg == null || arg.isBlank();
}

private static final String NAMESPACE = "devui-ide-interaction";
}
Loading

0 comments on commit 5385586

Please sign in to comment.