Browse Source

ServiceProviderExtensionFinder should scan the whole classpath (#273)

pull/276/head
Andreas Rudolph 6 years ago committed by Decebal Suiu
parent
commit
01d592622e
  1. 6
      pf4j/src/main/java/org/pf4j/LegacyExtensionFinder.java
  2. 21
      pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java

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

@ -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);

21
pf4j/src/main/java/org/pf4j/ServiceProviderExtensionFinder.java

@ -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")) {

Loading…
Cancel
Save