From: Andreas Rudolph Date: Sat, 5 Jan 2019 12:30:56 +0000 (+0100) Subject: ServiceProviderExtensionFinder should scan the whole classpath (#273) X-Git-Tag: release-2.6.0~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=01d592622ec74bc6cd921cb5b2b6f7f35d6939db;p=pf4j.git ServiceProviderExtensionFinder should scan the whole classpath (#273) --- diff --git a/pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java b/pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java index 5e682f3..99e1313 100644 --- a/pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java +++ b/pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java @@ -53,7 +53,11 @@ public class LegacyExtensionFinder extends AbstractExtensionFinder { Set bucket = new HashSet<>(); try { Enumeration urls = getClass().getClassLoader().getResources(getExtensionsResource()); - collectExtensions(urls, bucket); + if (urls.hasMoreElements()) { + collectExtensions(urls, bucket); + } else { + log.debug("Cannot find '{}'", getExtensionsResource()); + } debugExtensions(bucket); diff --git a/pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java b/pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java index 66efb8d..21f683c 100644 --- a/pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java +++ b/pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java @@ -61,9 +61,11 @@ public class ServiceProviderExtensionFinder extends AbstractExtensionFinder { final Set bucket = new HashSet<>(); try { - URL url = getClass().getClassLoader().getResource(getExtensionsResource()); - if (url != null) { - collectExtensions(url, bucket); + Enumeration urls = getClass().getClassLoader().getResources(getExtensionsResource()); + if (urls.hasMoreElements()) { + collectExtensions(urls, bucket); + } else { + log.debug("Cannot find '{}'", getExtensionsResource()); } debugExtensions(bucket); @@ -90,10 +92,7 @@ public class ServiceProviderExtensionFinder extends AbstractExtensionFinder { try { Enumeration urls = ((PluginClassLoader) plugin.getPluginClassLoader()).findResources(getExtensionsResource()); if (urls.hasMoreElements()) { - while (urls.hasMoreElements()) { - URL url = urls.nextElement(); - collectExtensions(url, bucket); - } + collectExtensions(urls, bucket); } else { log.debug("Cannot find '{}'", getExtensionsResource()); } @@ -109,6 +108,14 @@ public class ServiceProviderExtensionFinder extends AbstractExtensionFinder { return result; } + private void collectExtensions(Enumeration urls, Set bucket) throws URISyntaxException, IOException { + while (urls.hasMoreElements()) { + URL url = urls.nextElement(); + log.debug("Read '{}'", url.getFile()); + collectExtensions(url, bucket); + } + } + private void collectExtensions(URL url, Set bucket) throws URISyntaxException, IOException { Path extensionPath; if (url.toURI().getScheme().equals("jar")) {