Skip to content

Commit

Permalink
Collect META-INF/resources only from the runtime classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
aloubyansky committed Apr 19, 2023
1 parent f571ba9 commit 82cb5ed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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!
Expand Down Expand Up @@ -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<String> knownFiles = new HashSet<>();
Set<String> knownDirectories = new HashSet<>();
final Set<String> knownFiles = new HashSet<>();
final Set<String> knownDirectories = new HashSet<>();
for (ApplicationArchive i : applicationArchivesBuildItem.getAllApplicationArchives()) {
i.accept(tree -> {
Path resource = tree.getPath(META_INF_RESOURCES);
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ public class QuarkusClassLoader extends ClassLoader implements Closeable {
registerAsParallelCapable();
}

public static List<ClassPathElement> getElements(String resourceName, boolean localOnly) {
public static List<ClassPathElement> 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<ClassPathElement> getAllElements(boolean localOnly) {
public List<ClassPathElement> getAllElements(boolean onlyFromCurrentClassLoader) {
List<ClassPathElement> 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;
Expand Down

0 comments on commit 82cb5ed

Please sign in to comment.