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<>(); Set<String> bucket = new HashSet<>();
try { try {
Enumeration<URL> urls = getClass().getClassLoader().getResources(getExtensionsResource()); Enumeration<URL> urls = getClass().getClassLoader().getResources(getExtensionsResource());
collectExtensions(urls, bucket); if (urls.hasMoreElements()) {
collectExtensions(urls, bucket);
} else {
log.debug("Cannot find '{}'", getExtensionsResource());
}
debugExtensions(bucket); 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<>(); final Set<String> bucket = new HashSet<>();
try { try {
URL url = getClass().getClassLoader().getResource(getExtensionsResource()); Enumeration<URL> urls = getClass().getClassLoader().getResources(getExtensionsResource());
if (url != null) { if (urls.hasMoreElements()) {
collectExtensions(url, bucket); collectExtensions(urls, bucket);
} else {
log.debug("Cannot find '{}'", getExtensionsResource());
} }
debugExtensions(bucket); debugExtensions(bucket);
@ -90,10 +92,7 @@ public class ServiceProviderExtensionFinder extends AbstractExtensionFinder {
try { try {
Enumeration<URL> urls = ((PluginClassLoader) plugin.getPluginClassLoader()).findResources(getExtensionsResource()); Enumeration<URL> urls = ((PluginClassLoader) plugin.getPluginClassLoader()).findResources(getExtensionsResource());
if (urls.hasMoreElements()) { if (urls.hasMoreElements()) {
while (urls.hasMoreElements()) { collectExtensions(urls, bucket);
URL url = urls.nextElement();
collectExtensions(url, bucket);
}
} else { } else {
log.debug("Cannot find '{}'", getExtensionsResource()); log.debug("Cannot find '{}'", getExtensionsResource());
} }
@ -109,6 +108,14 @@ public class ServiceProviderExtensionFinder extends AbstractExtensionFinder {
return result; 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 { private void collectExtensions(URL url, Set<String> bucket) throws URISyntaxException, IOException {
Path extensionPath; Path extensionPath;
if (url.toURI().getScheme().equals("jar")) { if (url.toURI().getScheme().equals("jar")) {

Loading…
Cancel
Save