From 82cb5edc3a65cf190cf9c7aa224495a2ab5d486e Mon Sep 17 00:00:00 2001 From: Alexey Loubyansky Date: Wed, 19 Apr 2023 10:00:59 +0200 Subject: [PATCH] Collect META-INF/resources only from the runtime classpath --- .../UndertowStaticResourcesBuildStep.java | 18 ++++++++++++------ .../classloading/QuarkusClassLoader.java | 10 +++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/extensions/undertow/spi/src/main/java/io/quarkus/undertow/deployment/UndertowStaticResourcesBuildStep.java b/extensions/undertow/spi/src/main/java/io/quarkus/undertow/deployment/UndertowStaticResourcesBuildStep.java index f0db4f8b07070..5846c627da36b 100644 --- a/extensions/undertow/spi/src/main/java/io/quarkus/undertow/deployment/UndertowStaticResourcesBuildStep.java +++ b/extensions/undertow/spi/src/main/java/io/quarkus/undertow/deployment/UndertowStaticResourcesBuildStep.java @@ -12,6 +12,8 @@ import java.util.List; import java.util.Set; +import io.quarkus.bootstrap.classloading.ClassPathElement; +import io.quarkus.bootstrap.classloading.QuarkusClassLoader; import io.quarkus.deployment.ApplicationArchive; import io.quarkus.deployment.Capabilities; import io.quarkus.deployment.Capability; @@ -22,7 +24,6 @@ import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem; import io.quarkus.runtime.LaunchMode; -import io.quarkus.runtime.util.ClassPathUtils; /** * NOTE: Shared with Resteasy standalone! @@ -56,8 +57,8 @@ void scanStaticResources(Capabilities capabilities, ApplicationArchivesBuildItem } //we need to check for web resources in order to get welcome files to work //this kinda sucks - Set knownFiles = new HashSet<>(); - Set knownDirectories = new HashSet<>(); + final Set knownFiles = new HashSet<>(); + final Set knownDirectories = new HashSet<>(); for (ApplicationArchive i : applicationArchivesBuildItem.getAllApplicationArchives()) { i.accept(tree -> { Path resource = tree.getPath(META_INF_RESOURCES); @@ -67,9 +68,14 @@ void scanStaticResources(Capabilities capabilities, ApplicationArchivesBuildItem }); } - ClassPathUtils.consumeAsPaths(META_INF_RESOURCES, resource -> { - collectKnownPaths(resource, knownFiles, knownDirectories); - }); + for (ClassPathElement e : QuarkusClassLoader.getElements(META_INF_RESOURCES, false)) { + if (e.isRuntime()) { + e.apply(tree -> { + collectKnownPaths(tree.getPath(META_INF_RESOURCES), knownFiles, knownDirectories); + return null; + }); + } + } for (GeneratedWebResourceBuildItem genResource : generatedWebResources) { String sub = genResource.getName(); diff --git a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java index 440a8d6f5f238..8b653f334f3c5 100644 --- a/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java +++ b/independent-projects/bootstrap/core/src/main/java/io/quarkus/bootstrap/classloading/QuarkusClassLoader.java @@ -39,19 +39,19 @@ public class QuarkusClassLoader extends ClassLoader implements Closeable { registerAsParallelCapable(); } - public static List getElements(String resourceName, boolean localOnly) { + public static List getElements(String resourceName, boolean onlyFromCurrentClassLoader) { final ClassLoader ccl = Thread.currentThread().getContextClassLoader(); if (!(ccl instanceof QuarkusClassLoader)) { throw new IllegalStateException("The current classloader is not an instance of " + QuarkusClassLoader.class.getName() + " but " + ccl.getClass().getName()); } - return ((QuarkusClassLoader) ccl).getElementsWithResource(resourceName, localOnly); + return ((QuarkusClassLoader) ccl).getElementsWithResource(resourceName, onlyFromCurrentClassLoader); } - public List getAllElements(boolean localOnly) { + public List getAllElements(boolean onlyFromCurrentClassLoader) { List ret = new ArrayList<>(); - if (parent instanceof QuarkusClassLoader && !localOnly) { - ret.addAll(((QuarkusClassLoader) parent).getAllElements(localOnly)); + if (parent instanceof QuarkusClassLoader && !onlyFromCurrentClassLoader) { + ret.addAll(((QuarkusClassLoader) parent).getAllElements(onlyFromCurrentClassLoader)); } ret.addAll(elements); return ret;