]> source.dussan.org Git - pf4j.git/commitdiff
load extensions from plugin libraries (#262)
authorAndreas Rudolph <andy@openindex.de>
Fri, 28 Dec 2018 20:50:01 +0000 (21:50 +0100)
committerDecebal Suiu <decebal.suiu@gmail.com>
Fri, 28 Dec 2018 20:50:01 +0000 (22:50 +0200)
pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java
pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java

index 5c7c9b207df057c2d533c0ad8ea50a9542cb8bac..9995d89b353f15835c19c91384878a7a37959e6e 100644 (file)
@@ -83,14 +83,17 @@ public class LegacyExtensionFinder extends AbstractExtensionFinder {
             Set<String> bucket = new HashSet<>();
 
             try {
-                URL url = ((PluginClassLoader) plugin.getPluginClassLoader()).findResource(getExtensionsResource());
-                if (url != null) {
-                    log.debug("Read '{}'", url.getFile());
-                    try (Reader reader = new InputStreamReader(url.openStream(), StandardCharsets.UTF_8)) {
-                        LegacyExtensionStorage.read(reader, bucket);
-                    }
-                } else {
+                Enumeration<URL> urls = ((PluginClassLoader) plugin.getPluginClassLoader()).findResources(getExtensionsResource());
+                if (urls == null || !urls.hasMoreElements()) {
                     log.debug("Cannot find '{}'", getExtensionsResource());
+                } else {
+                    while (urls.hasMoreElements()) {
+                        URL url = urls.nextElement();
+                        log.debug("Read '{}'", url.getFile());
+                        try (Reader reader = new InputStreamReader(url.openStream(), StandardCharsets.UTF_8)) {
+                            LegacyExtensionStorage.read(reader, bucket);
+                        }
+                    }
                 }
 
                 debugExtensions(bucket);
index a1c48b6a840859bac16603171749bfadcf0b719f..bfa8f5a79965ec40ec67a441bdbd911cf93661e7 100644 (file)
@@ -33,6 +33,7 @@ import java.nio.file.Paths;
 import java.nio.file.SimpleFileVisitor;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.Collections;
+import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -94,18 +95,21 @@ public class ServiceProviderExtensionFinder extends AbstractExtensionFinder {
             final Set<String> bucket = new HashSet<>();
 
             try {
-                URL url = ((PluginClassLoader) plugin.getPluginClassLoader()).findResource(getExtensionsResource());
-                if (url != null) {
-                    Path extensionPath;
-                    if (url.toURI().getScheme().equals("jar")) {
-                        extensionPath = FileUtils.getPath(url.toURI(), getExtensionsResource());
-                    } else {
-                        extensionPath = Paths.get(url.toURI());
-                    }
-
-                    bucket.addAll(readExtensions(extensionPath));
-                } else {
+                Enumeration<URL> urls = ((PluginClassLoader) plugin.getPluginClassLoader()).findResources(getExtensionsResource());
+                if (urls == null || !urls.hasMoreElements()) {
                     log.debug("Cannot find '{}'", getExtensionsResource());
+                } else {
+                    while (urls.hasMoreElements()) {
+                        URL url = urls.nextElement();
+                        Path extensionPath;
+                        if (url.toURI().getScheme().equals("jar")) {
+                            extensionPath = FileUtils.getPath(url.toURI(), getExtensionsResource());
+                        } else {
+                            extensionPath = Paths.get(url.toURI());
+                        }
+
+                        bucket.addAll(readExtensions(extensionPath));
+                    }
                 }
 
                 debugExtensions(bucket);