]> source.dussan.org Git - pf4j.git/commitdiff
ServiceProviderExtensionFinder should scan the whole classpath (#273)
authorAndreas Rudolph <andy@openindex.de>
Sat, 5 Jan 2019 12:30:56 +0000 (13:30 +0100)
committerDecebal Suiu <decebal.suiu@gmail.com>
Sat, 5 Jan 2019 12:30:56 +0000 (14:30 +0200)
pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java
pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java

index 5e682f3009a54aa825d7481a0de55b6824d4416c..99e13134094547ed5505d91e40e6a75795054661 100644 (file)
@@ -53,7 +53,11 @@ public class LegacyExtensionFinder extends AbstractExtensionFinder {
         Set<String> bucket = new HashSet<>();
         try {
             Enumeration<URL> urls = getClass().getClassLoader().getResources(getExtensionsResource());
-            collectExtensions(urls, bucket);
+            if (urls.hasMoreElements()) {
+                collectExtensions(urls, bucket);
+            } else {
+                log.debug("Cannot find '{}'", getExtensionsResource());
+            }
 
             debugExtensions(bucket);
 
index 66efb8d2203a71cf4fd222e1814c7c99ad1dd391..21f683cb114b53e06d2d68e35ccec5da3883933f 100644 (file)
@@ -61,9 +61,11 @@ public class ServiceProviderExtensionFinder extends AbstractExtensionFinder {
 
         final Set<String> bucket = new HashSet<>();
         try {
-            URL url = getClass().getClassLoader().getResource(getExtensionsResource());
-            if (url != null) {
-                collectExtensions(url, bucket);
+            Enumeration<URL> 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<URL> 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<URL> urls, Set<String> 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<String> bucket) throws URISyntaxException, IOException {
         Path extensionPath;
         if (url.toURI().getScheme().equals("jar")) {