Browse Source

load extensions from plugin libraries (#262)

pull/276/head
Andreas Rudolph 6 years ago committed by Decebal Suiu
parent
commit
8408667a49
  1. 17
      pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java
  2. 26
      pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java

17
pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java

@ -83,14 +83,17 @@ public class LegacyExtensionFinder extends AbstractExtensionFinder {
Set<String> bucket = new HashSet<>(); Set<String> bucket = new HashSet<>();
try { try {
URL url = ((PluginClassLoader) plugin.getPluginClassLoader()).findResource(getExtensionsResource()); Enumeration<URL> urls = ((PluginClassLoader) plugin.getPluginClassLoader()).findResources(getExtensionsResource());
if (url != null) { if (urls == null || !urls.hasMoreElements()) {
log.debug("Read '{}'", url.getFile());
try (Reader reader = new InputStreamReader(url.openStream(), StandardCharsets.UTF_8)) {
LegacyExtensionStorage.read(reader, bucket);
}
} else {
log.debug("Cannot find '{}'", getExtensionsResource()); 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); debugExtensions(bucket);

26
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.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
@ -94,18 +95,21 @@ public class ServiceProviderExtensionFinder extends AbstractExtensionFinder {
final Set<String> bucket = new HashSet<>(); final Set<String> bucket = new HashSet<>();
try { try {
URL url = ((PluginClassLoader) plugin.getPluginClassLoader()).findResource(getExtensionsResource()); Enumeration<URL> urls = ((PluginClassLoader) plugin.getPluginClassLoader()).findResources(getExtensionsResource());
if (url != null) { if (urls == null || !urls.hasMoreElements()) {
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 {
log.debug("Cannot find '{}'", getExtensionsResource()); 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); debugExtensions(bucket);

Loading…
Cancel
Save