diff options
author | Andreas Rudolph <andy@openindex.de> | 2018-12-28 21:50:01 +0100 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2018-12-28 22:50:01 +0200 |
commit | 8408667a49ca185dfa8b1ab7939928acae339d02 (patch) | |
tree | a7e9148d81d25ea288539451f18122ac9e05264a /pf4j | |
parent | ab12f7fa5a95dd570f2e62812a243d48411c1dce (diff) | |
download | pf4j-8408667a49ca185dfa8b1ab7939928acae339d02.tar.gz pf4j-8408667a49ca185dfa8b1ab7939928acae339d02.zip |
load extensions from plugin libraries (#262)
Diffstat (limited to 'pf4j')
-rw-r--r-- | pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java | 17 | ||||
-rw-r--r-- | pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java | 26 |
2 files changed, 25 insertions, 18 deletions
diff --git a/pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java b/pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java index 5c7c9b2..9995d89 100644 --- a/pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java +++ b/pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java @@ -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); diff --git a/pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java b/pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java index a1c48b6..bfa8f5a 100644 --- a/pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java +++ b/pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java @@ -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); |