From 9c5adf7d5cb4c268e020fa1ed99e7760df908ee8 Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Wed, 27 Nov 2024 12:36:38 +1100 Subject: [PATCH] Fix not-found links when management enabled Signed-off-by: Phillip Kruger --- .../quarkus/runtime/TemplateHtmlBuilder.java | 50 ++++++++++++++++--- .../META-INF/template-html-builder.css | 13 ++++- .../deployment/devmode/NotFoundProcessor.java | 2 + .../runtime/devmode/ResourceNotFoundData.java | 22 +++----- 4 files changed, 62 insertions(+), 25 deletions(-) diff --git a/core/runtime/src/main/java/io/quarkus/runtime/TemplateHtmlBuilder.java b/core/runtime/src/main/java/io/quarkus/runtime/TemplateHtmlBuilder.java index 9db9cca9af3b8..cc25977432451 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/TemplateHtmlBuilder.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/TemplateHtmlBuilder.java @@ -75,6 +75,37 @@ function changeViewMode() { """; + private static final String NOT_FOUND_SORTING = """ + """; + + private static final String SORT_NOT_FOUND_LINKS = """ +

+ +

"""; + private static final String UTILITIES = """

@@ -108,6 +139,7 @@ function changeViewMode() { " \n" + " \n" + SCRIPT_STACKTRACE_MANIPULATION + + NOT_FOUND_SORTING + "\n" + "\n" + "

\n" + @@ -185,9 +217,12 @@ function changeViewMode() { private static final String RESOURCES_START = "
%1$s
"; + private static final String RESOURCES_START_WITH_CLASS = "
%1$s " + SORT_NOT_FOUND_LINKS + + "
"; + private static final String ANCHOR_TEMPLATE_ABSOLUTE = "%2$s"; - private static final String DESCRIPTION_TEMPLATE = "%1$s — %2$s"; + private static final String DESCRIPTION_TEMPLATE = "%1$s %2$s"; private static final String RESOURCE_TEMPLATE = "

%1$s

\n"; @@ -372,6 +407,11 @@ public TemplateHtmlBuilder resourcesStart(String title) { return this; } + public TemplateHtmlBuilder resourcesStart(String title, String cssclass) { + result.append(String.format(RESOURCES_START_WITH_CLASS, title, cssclass)); + return this; + } + public TemplateHtmlBuilder resourcesEnd() { result.append(RESOURCES_END); return this; @@ -401,7 +441,6 @@ public TemplateHtmlBuilder servletMapping(String title) { private TemplateHtmlBuilder resourcePath(String title, boolean withListStart, boolean withAnchor, String description) { String content; if (withAnchor) { - String text = title; if (title.startsWith("/")) { title = title.substring(1); } @@ -409,12 +448,7 @@ private TemplateHtmlBuilder resourcePath(String title, boolean withListStart, bo if (!title.startsWith("http") && baseUrl != null) { title = baseUrl + title; } - if (title.startsWith("http")) { - int firstSlashIndex = title.indexOf("/", title.indexOf("//") + 2); - text = title.substring(firstSlashIndex); - } - - content = String.format(ANCHOR_TEMPLATE_ABSOLUTE, title, escapeHtml(text)); + content = String.format(ANCHOR_TEMPLATE_ABSOLUTE, title, escapeHtml(title)); } else { content = escapeHtml(title); } diff --git a/core/runtime/src/main/resources/META-INF/template-html-builder.css b/core/runtime/src/main/resources/META-INF/template-html-builder.css index 77a86dbc4f47d..5717fb6283733 100644 --- a/core/runtime/src/main/resources/META-INF/template-html-builder.css +++ b/core/runtime/src/main/resources/META-INF/template-html-builder.css @@ -78,6 +78,8 @@ h2 { .intro { font-size: 1.1rem; + display: flex; + justify-content: space-between; } h3 { font-size: 1.2rem; @@ -85,6 +87,8 @@ h3 { font-weight: 400; color: #555; margin: 0.25em 0 0.25em 0; + display: grid; + grid-template-columns: 50% 50%; } .trace { @@ -151,7 +155,7 @@ h3 { a, a:visited, a:focus, a:active { text-decoration: none; color:hsla(211, 63%, 54%, 1.0); } -a:hover { +a:hover, h3:hover { text-decoration: none; color:hsla(343, 100%, 50%, 1.0); } .header { @@ -264,6 +268,13 @@ a:hover { border: 1px inset rgba(28,110,164,0.41); } + .sorticon { + margin: unset; + width: 20px; + padding-right: 5px; + cursor: pointer; + } + .tooltip { position: relative; display: inline-block; diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/NotFoundProcessor.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/NotFoundProcessor.java index b8eeff64add21..74972f061b52e 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/NotFoundProcessor.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/NotFoundProcessor.java @@ -107,6 +107,8 @@ private String concatenateUrl(String part1, String part2) { return part2; if (part1 != null && part2 == null) return part1; + if (part2.startsWith("http://") || part2.startsWith("https://")) + return part2; if (part1.endsWith("/") && part2.startsWith("/")) { return part1.substring(0, part1.length() - 1) + part2; } else if (!part1.endsWith("/") && !part2.startsWith("/")) { diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/devmode/ResourceNotFoundData.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/devmode/ResourceNotFoundData.java index d17b2ddcf9e8b..7c4a453fcc09a 100644 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/devmode/ResourceNotFoundData.java +++ b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/devmode/ResourceNotFoundData.java @@ -124,9 +124,8 @@ public String getHTMLContent() { // Additional Endpoints if (!this.additionalEndpoints.isEmpty()) { - List endpoints = getSortedAdditionalRouteDescriptions(); - builder.resourcesStart(ADDITIONAL_ENDPOINTS); - for (AdditionalRouteDescription additionalEndpoint : endpoints) { + builder.resourcesStart(ADDITIONAL_ENDPOINTS, "sortable"); + for (AdditionalRouteDescription additionalEndpoint : this.additionalEndpoints) { builder.staticResourcePath(additionalEndpoint.getUri(), additionalEndpoint.getDescription()); } builder.resourcesEnd(); @@ -190,8 +189,7 @@ public JsonObject getJsonContent() { // Additional Endpoints if (!this.additionalEndpoints.isEmpty()) { JsonArray ae = new JsonArray(); - List endpoints = getSortedAdditionalRouteDescriptions(); - for (AdditionalRouteDescription additionalEndpoint : endpoints) { + for (AdditionalRouteDescription additionalEndpoint : this.additionalEndpoints) { ae.add(JsonObject.of(URI, additionalEndpoint.getUri(), DESCRIPTION, additionalEndpoint.getDescription())); } infoMap.put(ADDITIONAL_ENDPOINTS, ae); @@ -252,8 +250,7 @@ public String getTextContent() { // Additional Endpoints if (!this.additionalEndpoints.isEmpty()) { sw.write(ADDITIONAL_ENDPOINTS + NL); - List endpoints = getSortedAdditionalRouteDescriptions(); - for (AdditionalRouteDescription additionalEndpoint : endpoints) { + for (AdditionalRouteDescription additionalEndpoint : this.additionalEndpoints) { sw.write(TAB + "- " + additionalEndpoint.getUri() + NL); sw.write(TAB + TAB + "- " + additionalEndpoint.getDescription() + NL); } @@ -269,8 +266,8 @@ public String getTextContent() { private List getCombinedRoutes() { // Endpoints List combinedRoutes = new ArrayList<>(); - if (this.runtimeRoutes != null) { - combinedRoutes.addAll(this.runtimeRoutes); + if (ResourceNotFoundData.runtimeRoutes != null) { + combinedRoutes.addAll(ResourceNotFoundData.runtimeRoutes); } if (endpointRoutes != null) { combinedRoutes.addAll(this.endpointRoutes); @@ -344,13 +341,6 @@ private boolean isHtmlFileName(String fileName) { return fileName.endsWith(".html") || fileName.endsWith(".htm") || fileName.endsWith(".xhtml"); } - private List getSortedAdditionalRouteDescriptions() { - return this.additionalEndpoints.stream().sorted( - Comparator.comparingInt((AdditionalRouteDescription desc) -> desc.getUri().split("/").length) - .thenComparing(AdditionalRouteDescription::getUri)) - .toList(); - } - private static final String HEADING = "404 - Resource Not Found"; private static final String RESOURCE_ENDPOINTS = "Resource Endpoints"; private static final String SERVLET_MAPPINGS = "Servlet mappings";