From 8408667a49ca185dfa8b1ab7939928acae339d02 Mon Sep 17 00:00:00 2001 From: Andreas Rudolph Date: Fri, 28 Dec 2018 21:50:01 +0100 Subject: [PATCH] load extensions from plugin libraries (#262) --- .../java/org/pf4j/LegacyExtensionFinder.java | 17 +++++++----- .../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 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 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 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 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); -- 2.39.5