From bf28a6d2cda91c9ad6bf6efb81630899da78f4ea Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Tue, 12 Jan 2021 12:43:22 +0200 Subject: [PATCH 01/19] Non-application path and Dev console fixes Signed-off-by: Phillip Kruger --- .../deployment/SmallRyeGraphQLProcessor.java | 12 ++++--- extensions/smallrye-health/deployment/pom.xml | 5 ++- .../deployment/SmallRyeHealthProcessor.java | 7 ++-- .../resources/dev-templates/embedded.html | 12 +++++++ extensions/smallrye-health/runtime/pom.xml | 4 --- .../resources/dev-templates/embedded.html | 4 +-- .../deployment/SwaggerUiProcessor.java | 19 +++++++---- .../devmode/console/DevConsole.java | 13 +++++++- .../devmode/console/DevConsoleProcessor.java | 32 ++++++++++++++----- .../main/resources/dev-templates/main.html | 2 +- 10 files changed, 79 insertions(+), 31 deletions(-) create mode 100644 extensions/smallrye-health/deployment/src/main/resources/dev-templates/embedded.html diff --git a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java index 3edb2d3955bc3..28d3187b0d09d 100644 --- a/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java +++ b/extensions/smallrye-graphql/deployment/src/main/java/io/quarkus/smallrye/graphql/deployment/SmallRyeGraphQLProcessor.java @@ -454,7 +454,7 @@ void getGraphqlUiFinalDestination( String graphQLPath = httpRootPath.adjustPath(graphQLConfig.rootPath); String graphQLUiPath = nonApplicationRootPathBuildItem - .adjustPath(httpRootPath.adjustPath(graphQLConfig.ui.rootPath)); + .adjustPath(graphQLConfig.ui.rootPath); AppArtifact artifact = WebJarUtil.getAppArtifact(curateOutcomeBuildItem, GRAPHQL_UI_WEBJAR_GROUP_ID, GRAPHQL_UI_WEBJAR_ARTIFACT_ID); @@ -462,10 +462,11 @@ void getGraphqlUiFinalDestination( Path tempPath = WebJarUtil.copyResourcesForDevOrTest(curateOutcomeBuildItem, launchMode, artifact, GRAPHQL_UI_WEBJAR_PREFIX); WebJarUtil.updateUrl(tempPath.resolve(FILE_TO_UPDATE), graphQLPath, LINE_TO_UPDATE, LINE_FORMAT); - WebJarUtil.updateUrl(tempPath.resolve(FILE_TO_UPDATE), graphQLUiPath, UI_LINE_TO_UPDATE, UI_LINE_FORMAT); + WebJarUtil.updateUrl(tempPath.resolve(FILE_TO_UPDATE), httpRootPath.adjustPath(graphQLUiPath), + UI_LINE_TO_UPDATE, UI_LINE_FORMAT); smallRyeGraphQLBuildProducer.produce(new SmallRyeGraphQLBuildItem(tempPath.toAbsolutePath().toString(), - graphQLUiPath)); + httpRootPath.adjustPath(graphQLUiPath))); notFoundPageDisplayableEndpointProducer .produce(new NotFoundPageDisplayableEndpointBuildItem(graphQLUiPath + "/", "MicroProfile GraphQL UI")); @@ -483,7 +484,8 @@ void getGraphqlUiFinalDestination( LINE_FORMAT) .getBytes(StandardCharsets.UTF_8); content = WebJarUtil - .updateUrl(new String(content, StandardCharsets.UTF_8), graphQLPath, UI_LINE_TO_UPDATE, + .updateUrl(new String(content, StandardCharsets.UTF_8), httpRootPath.adjustPath(graphQLUiPath), + UI_LINE_TO_UPDATE, UI_LINE_FORMAT) .getBytes(StandardCharsets.UTF_8); } @@ -494,7 +496,7 @@ void getGraphqlUiFinalDestination( } smallRyeGraphQLBuildProducer.produce(new SmallRyeGraphQLBuildItem(GRAPHQL_UI_FINAL_DESTINATION, - graphQLUiPath)); + httpRootPath.adjustPath(graphQLUiPath))); } } } diff --git a/extensions/smallrye-health/deployment/pom.xml b/extensions/smallrye-health/deployment/pom.xml index 2fe1435a084bb..8e331d54fe120 100644 --- a/extensions/smallrye-health/deployment/pom.xml +++ b/extensions/smallrye-health/deployment/pom.xml @@ -41,7 +41,10 @@ io.quarkus quarkus-smallrye-health - + + io.smallrye + smallrye-health-ui + io.quarkus diff --git a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java index e4e789c2b7eff..a2ee22feb18c9 100644 --- a/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java +++ b/extensions/smallrye-health/deployment/src/main/java/io/quarkus/smallrye/health/deployment/SmallRyeHealthProcessor.java @@ -261,12 +261,13 @@ public void defineHealthRoutes(BuildProducer routes, @BuildStep(onlyIf = OpenAPIIncluded.class) public void includeInOpenAPIEndpoint(BuildProducer openAPIProducer, NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem, + HttpRootPathBuildItem httpRootPath, Capabilities capabilities, SmallRyeHealthConfig healthConfig) { // Add to OpenAPI if OpenAPI is available if (capabilities.isPresent(Capability.SMALLRYE_OPENAPI)) { - String basePath = nonApplicationRootPathBuildItem.adjustPath(healthConfig.rootPath); + String basePath = httpRootPath.adjustPath(nonApplicationRootPathBuildItem.adjustPath(healthConfig.rootPath)); HealthOpenAPIFilter filter = new HealthOpenAPIFilter(basePath, basePath + healthConfig.livenessPath, basePath + healthConfig.readinessPath); @@ -383,7 +384,7 @@ void registerUiExtension( "quarkus.smallrye-health.root-path-ui was set to \"/\", this is not allowed as it blocks the application from serving anything else."); } - String healthPath = nonApplicationRootPathBuildItem.adjustPath(httpRootPath.adjustPath(healthConfig.rootPath)); + String healthPath = httpRootPath.adjustPath(nonApplicationRootPathBuildItem.adjustPath(healthConfig.rootPath)); AppArtifact artifact = WebJarUtil.getAppArtifact(curateOutcomeBuildItem, HEALTH_UI_WEBJAR_GROUP_ID, HEALTH_UI_WEBJAR_ARTIFACT_ID); @@ -399,7 +400,7 @@ void registerUiExtension( notFoundPageDisplayableEndpointProducer .produce(new NotFoundPageDisplayableEndpointBuildItem( nonApplicationRootPathBuildItem - .adjustPath(httpRootPath.adjustPath(healthConfig.ui.rootPath + "/")))); + .adjustPath(healthConfig.ui.rootPath + "/"))); } else { Map files = WebJarUtil.copyResourcesForProduction(curateOutcomeBuildItem, artifact, HEALTH_UI_WEBJAR_PREFIX); diff --git a/extensions/smallrye-health/deployment/src/main/resources/dev-templates/embedded.html b/extensions/smallrye-health/deployment/src/main/resources/dev-templates/embedded.html new file mode 100644 index 0000000000000..bf06991306e00 --- /dev/null +++ b/extensions/smallrye-health/deployment/src/main/resources/dev-templates/embedded.html @@ -0,0 +1,12 @@ + + + + + + + Health + + + + + Health UI diff --git a/extensions/smallrye-health/runtime/pom.xml b/extensions/smallrye-health/runtime/pom.xml index 7a6e8d89f82ad..05731aecef6cc 100644 --- a/extensions/smallrye-health/runtime/pom.xml +++ b/extensions/smallrye-health/runtime/pom.xml @@ -18,10 +18,6 @@ io.smallrye smallrye-health - - io.smallrye - smallrye-health-ui - io.smallrye smallrye-health-provided-checks diff --git a/extensions/smallrye-openapi/deployment/src/main/resources/dev-templates/embedded.html b/extensions/smallrye-openapi/deployment/src/main/resources/dev-templates/embedded.html index f2c047d1e42fa..143b0287a29ec 100644 --- a/extensions/smallrye-openapi/deployment/src/main/resources/dev-templates/embedded.html +++ b/extensions/smallrye-openapi/deployment/src/main/resources/dev-templates/embedded.html @@ -1,11 +1,11 @@ - + OpenAPI - + diff --git a/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java b/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java index e7d4b184d0680..82e2acdecdbc7 100644 --- a/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java +++ b/extensions/swagger-ui/deployment/src/main/java/io/quarkus/swaggerui/deployment/SwaggerUiProcessor.java @@ -22,6 +22,7 @@ import io.quarkus.smallrye.openapi.common.deployment.SmallRyeOpenApiConfig; import io.quarkus.swaggerui.runtime.SwaggerUiRecorder; import io.quarkus.swaggerui.runtime.SwaggerUiRuntimeConfig; +import io.quarkus.vertx.http.deployment.HttpRootPathBuildItem; import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem; import io.quarkus.vertx.http.deployment.RouteBuildItem; import io.quarkus.vertx.http.deployment.devmode.NotFoundPageDisplayableEndpointBuildItem; @@ -57,7 +58,8 @@ public void getSwaggerUiFinalDestination( CurateOutcomeBuildItem curateOutcomeBuildItem, LaunchModeBuildItem launchMode, SwaggerUiConfig swaggerUiConfig, - SmallRyeOpenApiConfig openapi) throws Exception { + SmallRyeOpenApiConfig openapi, + HttpRootPathBuildItem httpRootPathBuildItem) throws Exception { if (shouldInclude(launchMode, swaggerUiConfig)) { if ("/".equals(swaggerUiConfig.path)) { @@ -65,7 +67,10 @@ public void getSwaggerUiFinalDestination( "quarkus.swagger-ui.path was set to \"/\", this is not allowed as it blocks the application from serving anything else."); } - String openApiPath = nonApplicationRootPathBuildItem.adjustPath(openapi.path); + String openApiPath = httpRootPathBuildItem.adjustPath(nonApplicationRootPathBuildItem.adjustPath(openapi.path)); + String swaggerUiPath = httpRootPathBuildItem + .adjustPath(nonApplicationRootPathBuildItem.adjustPath(swaggerUiConfig.path)); + AppArtifact artifact = WebJarUtil.getAppArtifact(curateOutcomeBuildItem, SWAGGER_UI_WEBJAR_GROUP_ID, SWAGGER_UI_WEBJAR_ARTIFACT_ID); @@ -73,7 +78,8 @@ public void getSwaggerUiFinalDestination( Path tempPath = WebJarUtil.copyResourcesForDevOrTest(curateOutcomeBuildItem, launchMode, artifact, SWAGGER_UI_WEBJAR_PREFIX); // Update index.html - WebJarUtil.updateFile(tempPath.resolve("index.html"), generateIndexHtml(openApiPath, swaggerUiConfig)); + WebJarUtil.updateFile(tempPath.resolve("index.html"), + generateIndexHtml(openApiPath, swaggerUiPath, swaggerUiConfig)); swaggerUiBuildProducer.produce(new SwaggerUiBuildItem(tempPath.toAbsolutePath().toString(), nonApplicationRootPathBuildItem.adjustPath(swaggerUiConfig.path))); @@ -89,7 +95,7 @@ public void getSwaggerUiFinalDestination( if (fileName.equals(theme.toString()) || !fileName.startsWith("theme-")) { byte[] content; if (fileName.endsWith("index.html")) { - content = generateIndexHtml(openApiPath, swaggerUiConfig); + content = generateIndexHtml(openApiPath, swaggerUiPath, swaggerUiConfig); } else { content = file.getValue(); } @@ -133,11 +139,12 @@ public void registerSwaggerUiHandler(SwaggerUiRecorder recorder, } } - private byte[] generateIndexHtml(String openApiPath, SwaggerUiConfig swaggerUiConfig) throws IOException { + private byte[] generateIndexHtml(String openApiPath, String swaggerUiPath, SwaggerUiConfig swaggerUiConfig) + throws IOException { Map options = new HashMap<>(); Map urlsMap = null; - options.put(Option.selfHref, swaggerUiConfig.path); + options.put(Option.selfHref, swaggerUiPath); // Only add the url if the user did not specified urls if (swaggerUiConfig.urls != null && !swaggerUiConfig.urls.isEmpty()) { diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsole.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsole.java index 6b79387c4f02f..20e9353cb7c97 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsole.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsole.java @@ -35,8 +35,13 @@ public class DevConsole implements Handler { final Engine engine; final Map> extensions = new HashMap<>(); - DevConsole(Engine engine) { + final Map globalData = new HashMap<>(); + + DevConsole(Engine engine, String httpRootPath, String frameworkRootPath) { this.engine = engine; + this.globalData.put("httpRootPath", httpRootPath); + this.globalData.put("frameworkRootPath", frameworkRootPath); + try { Enumeration extensionDescriptors = getClass().getClassLoader() .getResources("/META-INF/quarkus-extension.yaml"); @@ -88,6 +93,11 @@ private String getExtensionName(String namespace) { } protected void renderTemplate(RoutingContext event, TemplateInstance template) { + // Add some global variables + for (Map.Entry global : globalData.entrySet()) { + template.data(global.getKey(), global.getValue()); + } + template.renderAsync().handle(new BiFunction() { @Override public Object apply(String s, Throwable throwable) { @@ -119,6 +129,7 @@ public void sendMainPage(RoutingContext event) { if (hasConsoleEntry || hasGuide) { if (hasConsoleEntry) { Map data = new HashMap<>(); + data.putAll(globalData); data.put("urlbase", groupId + "." + artifactId); String result = simpleTemplate.render(data); loaded.put("_dev", result); diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java index 155380e170202..2aa005050b86b 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java @@ -57,6 +57,8 @@ import io.quarkus.qute.UserTagSectionHelper; import io.quarkus.qute.ValueResolvers; import io.quarkus.qute.Variant; +import io.quarkus.vertx.http.deployment.HttpRootPathBuildItem; +import io.quarkus.vertx.http.deployment.NonApplicationRootPathBuildItem; import io.quarkus.vertx.http.deployment.RouteBuildItem; import io.quarkus.vertx.http.deployment.devmode.NotFoundPageDisplayableEndpointBuildItem; import io.quarkus.vertx.http.runtime.devmode.DevConsoleFilter; @@ -158,7 +160,17 @@ public void handle(HttpServerRequest event) { } - protected static void newRouter(Engine engine) { + protected static void newRouter(Engine engine, + HttpRootPathBuildItem httpRootPathBuildItem, + NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem) { + + // "" or "/myroot" + String httpRootPath = httpRootPathBuildItem.adjustPath("/"); + httpRootPath = httpRootPath.substring(0, httpRootPath.lastIndexOf("/")); + // "" or "/myroot" or "/q" or "/myroot/q" + String frameworkRootPath = httpRootPathBuildItem.adjustPath(nonApplicationRootPathBuildItem.adjustPath("/")); + frameworkRootPath = frameworkRootPath.substring(0, frameworkRootPath.lastIndexOf("/")); + Handler errorHandler = new Handler() { @Override public void handle(RoutingContext event) { @@ -172,10 +184,11 @@ public void handle(RoutingContext event) { .handler(new FlashScopeHandler()); router.route().method(HttpMethod.GET) .order(Integer.MIN_VALUE + 1) - .handler(new DevConsole(engine)); + .handler(new DevConsole(engine, httpRootPath, frameworkRootPath)); mainRouter = Router.router(devConsoleVertx); mainRouter.errorHandler(500, errorHandler); - mainRouter.route("/q/dev/*").subRouter(router); + mainRouter.route(httpRootPathBuildItem.adjustPath(nonApplicationRootPathBuildItem.adjustPath("/dev/*"))) + .subRouter(router); } @BuildStep(onlyIf = IsDevelopment.class) @@ -230,9 +243,12 @@ public void setupActions(List routes, List devTemplatePaths, BuildProducer displayableEndpoints, Optional devTemplateVariants, - CurateOutcomeBuildItem curateOutcomeBuildItem) { + CurateOutcomeBuildItem curateOutcomeBuildItem, + HttpRootPathBuildItem httpRootPathBuildItem, + NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem) { initializeVirtual(); - newRouter(buildEngine(devTemplatePaths, devTemplateVariants)); + + newRouter(buildEngine(devTemplatePaths), httpRootPathBuildItem, nonApplicationRootPathBuildItem); for (DevConsoleRouteBuildItem i : routes) { Entry groupAndArtifact = i.groupIdAndArtifactId(curateOutcomeBuildItem); // if the handler is a proxy, then that means it's been produced by a recorder and therefore belongs in the regular runtime Vert.x instance @@ -261,11 +277,11 @@ public void setupActions(List routes, .nonApplicationRoute(false) .build()); - displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem("/q/dev/", "Quarkus DEV Console")); + displayableEndpoints.produce(new NotFoundPageDisplayableEndpointBuildItem( + nonApplicationRootPathBuildItem.adjustPath("/dev/"), "Quarkus DEV Console")); } - private Engine buildEngine(List devTemplatePaths, - Optional devTemplateVariants) { + private Engine buildEngine(List devTemplatePaths) { EngineBuilder builder = Engine.builder().addDefaults(); // Escape some characters for HTML templates diff --git a/extensions/vertx-http/deployment/src/main/resources/dev-templates/main.html b/extensions/vertx-http/deployment/src/main/resources/dev-templates/main.html index 7b2d6101cdd8c..0215a42d4df12 100644 --- a/extensions/vertx-http/deployment/src/main/resources/dev-templates/main.html +++ b/extensions/vertx-http/deployment/src/main/resources/dev-templates/main.html @@ -19,7 +19,7 @@