From 01d592622ec74bc6cd921cb5b2b6f7f35d6939db Mon Sep 17 00:00:00 2001 From: Andreas Rudolph Date: Sat, 5 Jan 2019 13:30:56 +0100 Subject: [PATCH] ServiceProviderExtensionFinder should scan the whole classpath (#273) --- .../java/org/pf4j/LegacyExtensionFinder.java | 6 +++++- .../pf4j/ServiceProviderExtensionFinder.java | 21 ++++++++++++------- 2 files changed, 19 insertions(+), 8 deletions(-) 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")) { -- 2.39.5