Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adding and removing extensions from Dev UI #43840

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion extensions/vertx-http/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,17 @@
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
</dependency>

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devtools-common</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-connector-basic</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
package io.quarkus.devui.deployment.menu;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;

import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.dev.spi.DevModeType;
import io.quarkus.devtools.commands.AddExtensions;
import io.quarkus.devtools.commands.ListCategories;
import io.quarkus.devtools.commands.ListExtensions;
import io.quarkus.devtools.commands.RemoveExtensions;
import io.quarkus.devtools.commands.data.QuarkusCommandException;
import io.quarkus.devtools.commands.data.QuarkusCommandOutcome;
import io.quarkus.devtools.project.QuarkusProject;
import io.quarkus.devtools.project.QuarkusProjectHelper;
import io.quarkus.devui.deployment.ExtensionsBuildItem;
import io.quarkus.devui.deployment.InternalPageBuildItem;
import io.quarkus.devui.deployment.extension.Extension;
import io.quarkus.devui.deployment.extension.ExtensionGroup;
import io.quarkus.devui.spi.buildtime.BuildTimeActionBuildItem;
import io.quarkus.devui.spi.page.Page;

/**
Expand All @@ -30,11 +47,160 @@ InternalPageBuildItem createExtensionsPages(ExtensionsBuildItem extensionsBuildI

// Page
extensionsPages.addPage(Page.webComponentPageBuilder()
.namespace("devui-extensions")
.namespace(NAMESPACE)
.title("Extensions")
.icon("font-awesome-solid:puzzle-piece")
.componentLink("qwc-extensions.js"));

return extensionsPages;
}
}

@BuildStep(onlyIf = IsDevelopment.class)
void createBuildTimeActions(BuildProducer<BuildTimeActionBuildItem> buildTimeActionProducer,
LaunchModeBuildItem launchModeBuildItem) {

if (launchModeBuildItem.getDevModeType().isPresent()
&& launchModeBuildItem.getDevModeType().get().equals(DevModeType.LOCAL)) {

BuildTimeActionBuildItem buildTimeActions = new BuildTimeActionBuildItem(NAMESPACE);

getCategories(buildTimeActions);
getInstallableExtensions(buildTimeActions);
getInstalledNamespaces(buildTimeActions);
removeExtension(buildTimeActions);
addExtension(buildTimeActions);
buildTimeActionProducer.produce(buildTimeActions);
}
}

private void getCategories(BuildTimeActionBuildItem buildTimeActions) {
buildTimeActions.addAction(new Object() {
}.getClass().getEnclosingMethod().getName(), ignored -> {
return CompletableFuture.supplyAsync(() -> {
try {
QuarkusCommandOutcome outcome = new ListCategories(getQuarkusProject())
.format("object")
.execute();

if (outcome.isSuccess()) {
return outcome.getResult();
}
} catch (QuarkusCommandException ex) {
throw new RuntimeException(ex);
}
return null;
});
});
}

private void getInstallableExtensions(BuildTimeActionBuildItem buildTimeActions) {
buildTimeActions.addAction(new Object() {
}.getClass().getEnclosingMethod().getName(), ignored -> {
return CompletableFuture.supplyAsync(() -> {
try {
QuarkusCommandOutcome outcome = new ListExtensions(getQuarkusProject())
.installed(false)
.all(false)
.format("object")
.execute();

if (outcome.isSuccess()) {
return outcome.getResult();
}

return null;
} catch (QuarkusCommandException e) {
throw new RuntimeException(e);
}
});
});
}

private void getInstalledNamespaces(BuildTimeActionBuildItem buildTimeActions) {
buildTimeActions.addAction(new Object() {
}.getClass().getEnclosingMethod().getName(), ignored -> {
return CompletableFuture.supplyAsync(() -> {
try {
QuarkusCommandOutcome outcome = new ListExtensions(getQuarkusProject())
.installed(true)
.all(false)
.format("object")
.execute();

if (outcome.isSuccess()) {

List<io.quarkus.registry.catalog.Extension> extensionList = (List<io.quarkus.registry.catalog.Extension>) outcome
.getResult();

List<String> namespaceList = new ArrayList<>();

if (!extensionList.isEmpty()) {
for (io.quarkus.registry.catalog.Extension e : extensionList) {
String groupId = e.getArtifact().getGroupId();
String artifactId = e.getArtifact().getArtifactId();
namespaceList.add(groupId + "." + artifactId);
}
}
return namespaceList;
}

return null;
} catch (QuarkusCommandException e) {
throw new RuntimeException(e);
}
});
});
}

private void removeExtension(BuildTimeActionBuildItem buildTimeActions) {
buildTimeActions.addAction(new Object() {
}.getClass().getEnclosingMethod().getName(), params -> {
return CompletableFuture.supplyAsync(() -> {
String extensionArtifactId = params.get("extensionArtifactId");
try {
QuarkusCommandOutcome outcome = new RemoveExtensions(getQuarkusProject())
.extensions(Set.of(extensionArtifactId))
.execute();

if (outcome.isSuccess()) {
return true;
} else {
return false;
}
} catch (QuarkusCommandException e) {
throw new RuntimeException(e);
}
});
});
}

private void addExtension(BuildTimeActionBuildItem buildTimeActions) {
buildTimeActions.addAction(new Object() {
}.getClass().getEnclosingMethod().getName(), params -> {
return CompletableFuture.supplyAsync(() -> {
String extensionArtifactId = params.get("extensionArtifactId");

try {
QuarkusCommandOutcome outcome = new AddExtensions(getQuarkusProject())
.extensions(Set.of(extensionArtifactId))
.execute();

if (outcome.isSuccess()) {
return true;
} else {
return false;
}
} catch (QuarkusCommandException e) {
throw new RuntimeException(e);
}
});
});
}

private QuarkusProject getQuarkusProject() {
Path projectRoot = Paths.get(System.getProperty("user.dir")).toAbsolutePath();
return QuarkusProjectHelper.getCachedProject(projectRoot);
}

private static final String NAMESPACE = "devui-extensions";
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,9 @@ export class QwcConfiguration extends observeState(LitElement) {
return html`<vaadin-grid .items="${this._filtered}" style="width: 100%;" class="${className}" theme="row-stripes"
.detailsOpenedItems="${this._detailsOpenedItem}"
@active-item-changed="${(event) => {
const prop = event.detail.value;
this._detailsOpenedItem = prop ? [prop] : [];
}}"
const prop = event.detail.value;
this._detailsOpenedItem = prop ? [prop] : [];
}}"
${gridRowDetailsRenderer(this._descriptionRenderer, [])}
>
<vaadin-grid-sort-column auto-width class="cell" flex-grow="0" path="configPhase" header='Phase'
Expand Down
Loading
Loading