Skip to content

Commit

Permalink
Allow adding and removing extensions from Dev UI
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Oct 17, 2024
1 parent 5c3944b commit d9fa5e4
Show file tree
Hide file tree
Showing 35 changed files with 1,062 additions and 33 deletions.
17 changes: 16 additions & 1 deletion extensions/vertx-http/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,28 @@
<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>
<artifactId>quarkus-vertx-http-dev-ui-tests</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-devtools-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-security-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
package io.quarkus.devui.deployment.menu;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
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 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.messagewriter.MessageWriter;
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 +49,157 @@ 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)) {

Path projectRoot = Paths.get(System.getProperty("user.dir")).toAbsolutePath();
QuarkusProject quarkusProject = QuarkusProjectHelper.getProject(projectRoot);

BuildTimeActionBuildItem buildTimeActions = new BuildTimeActionBuildItem(NAMESPACE);

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

private void getCategories(BuildTimeActionBuildItem buildTimeActions, QuarkusProject quarkusProject) {
buildTimeActions.addAction(new Object() {
}.getClass().getEnclosingMethod().getName(), ignored -> {

try {
QuarkusCommandOutcome outcome = new ListCategories(quarkusProject)
.format("object")
.execute();

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

private void getInstallableExtensions(BuildTimeActionBuildItem buildTimeActions, QuarkusProject quarkusProject) {
buildTimeActions.addAction(new Object() {
}.getClass().getEnclosingMethod().getName(), ignored -> {

try {
QuarkusCommandOutcome outcome = new ListExtensions(quarkusProject)
.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, QuarkusProject quarkusProject) {
buildTimeActions.addAction(new Object() {
}.getClass().getEnclosingMethod().getName(), ignored -> {

try {

QuarkusCommandOutcome outcome = new ListExtensions(quarkusProject)
.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, QuarkusProject quarkusProject) {
buildTimeActions.addAction(new Object() {
}.getClass().getEnclosingMethod().getName(), params -> {
String extensionArtifactId = params.get("extensionArtifactId");

try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(byteArrayOutputStream)) {

QuarkusCommandOutcome outcome = new RemoveExtensions(quarkusProject, MessageWriter.info(printStream))
.extensions(Set.of(extensionArtifactId))
.execute();

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

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

try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(byteArrayOutputStream)) {

QuarkusCommandOutcome outcome = new AddExtensions(quarkusProject, MessageWriter.info(printStream))
.extensions(Set.of(extensionArtifactId))
.execute();

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

private static final String NAMESPACE = "devui-extensions";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import jakarta.inject.Inject;
import jakarta.inject.Named;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.devtools.testing.RegistryClientTestHelper;
import io.quarkus.runtime.StartupEvent;
import io.quarkus.test.QuarkusDevModeTest;
import io.quarkus.vertx.http.runtime.HttpBuildTimeConfig;
Expand All @@ -26,6 +29,16 @@ public class ArcEndpointTest {
.withApplicationRoot((jar) -> jar
.addClasses(Foo.class));

@BeforeAll
public static void setupTestRegistry() {
RegistryClientTestHelper.enableRegistryClientTestConfig();
}

@AfterAll
public static void cleanupTestRegistry() {
RegistryClientTestHelper.disableRegistryClientTestConfig();
}

@Test
public void testBeans() {
String debugPath = RestAssured.get("/console-path").asString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import static org.hamcrest.Matchers.equalTo;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.devtools.testing.RegistryClientTestHelper;
import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;

Expand All @@ -19,6 +22,16 @@ public class CompileProblemTest {
.withApplicationRoot((jar) -> jar
.addClasses(CompileErrorEndpoint.class, CompileCorrectlyEndpoint.class));

@BeforeAll
public static void setupTestRegistry() {
RegistryClientTestHelper.enableRegistryClientTestConfig();
}

@AfterAll
public static void cleanupTestRegistry() {
RegistryClientTestHelper.disableRegistryClientTestConfig();
}

@Test
public void test() {
RestAssured.get("/error").then().body(equalTo("error"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import org.hamcrest.Matchers;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.devtools.testing.RegistryClientTestHelper;
import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;

Expand All @@ -24,6 +27,16 @@ public class GeneratedStaticResourcesDevModeTest {
.addAsResource("static-file.html", "META-INF/generated-resources-test/index.html")
.addAsResource("static-file.html", "META-INF/generated-resources-test/image.svg"));

@BeforeAll
public static void setupTestRegistry() {
RegistryClientTestHelper.enableRegistryClientTestConfig();
}

@AfterAll
public static void cleanupTestRegistry() {
RegistryClientTestHelper.disableRegistryClientTestConfig();
}

@Test
void shouldUpdateResourceIndexHtmlOnUserChange() {
RestAssured.given()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.quarkus.vertx.http.devmode;

import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.devtools.testing.RegistryClientTestHelper;
import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;

Expand All @@ -20,6 +23,16 @@ public class LiveReloadArtifactTest {
"application.properties")
.addClasses(LiveReloadEndpoint.class));

@BeforeAll
public static void setupTestRegistry() {
RegistryClientTestHelper.enableRegistryClientTestConfig();
}

@AfterAll
public static void cleanupTestRegistry() {
RegistryClientTestHelper.disableRegistryClientTestConfig();
}

@Test
public void test() {
String firstClassToString = RestAssured.get("/test").then().statusCode(200).extract().body().asString();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.quarkus.vertx.http.devmode;

import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.devtools.testing.RegistryClientTestHelper;
import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;

Expand All @@ -20,6 +23,16 @@ public class ParentFirstArtifactTest {
"application.properties")
.addClasses(ParentFirstEndpoint.class));

@BeforeAll
public static void setupTestRegistry() {
RegistryClientTestHelper.enableRegistryClientTestConfig();
}

@AfterAll
public static void cleanupTestRegistry() {
RegistryClientTestHelper.disableRegistryClientTestConfig();
}

@Test
public void test() {
String firstClassToString = RestAssured.get("/test").then().statusCode(200).extract().body().asString();
Expand Down
Loading

0 comments on commit d9fa5e4

Please sign in to comment.