From ecf2d73fd5908534c7e0fe1c494e62a3fabdb138 Mon Sep 17 00:00:00 2001 From: Bruno Harbulot Date: Fri, 12 Feb 2016 10:48:58 +0000 Subject: [PATCH 1/2] Fix issue with listing files from the jar file in readPluginsStorages(). --- .../pf4j/ServiceProviderExtensionFinder.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java b/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java index 80bb412..2a32c55 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java @@ -19,8 +19,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ro.fortsoft.pf4j.processor.ServiceProviderExtensionStorage; -import java.io.File; -import java.io.FileReader; import java.io.IOException; import java.io.Reader; import java.net.URISyntaxException; @@ -111,19 +109,29 @@ public class ServiceProviderExtensionFinder extends AbstractExtensionFinder { for (PluginWrapper plugin : plugins) { String pluginId = plugin.getDescriptor().getPluginId(); log.debug("Reading extensions storages for plugin '{}'", pluginId); - Set bucket = new HashSet<>(); + final Set bucket = new HashSet<>(); try { URL url = ((PluginClassLoader) plugin.getPluginClassLoader()).findResource(getExtensionsResource()); if (url != null) { - File[] files = new File(url.toURI()).listFiles(); - if (files != null) { - for (File file : files) { + Path extensionPath; + if (url.toURI().getScheme().equals("jar")) { + FileSystem fileSystem = FileSystems.newFileSystem(url.toURI(), Collections.emptyMap()); + extensionPath = fileSystem.getPath(getExtensionsResource()); + } else { + extensionPath = Paths.get(url.toURI()); + } + Files.walkFileTree(extensionPath, Collections.emptySet(), 1, new SimpleFileVisitor() { + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { log.debug("Read '{}'", file); - Reader reader = new FileReader(file); + Reader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8); ServiceProviderExtensionStorage.read(reader, bucket); + return FileVisitResult.CONTINUE; } - } + + }); } else { log.debug("Cannot find '{}'", getExtensionsResource()); } From a029a100a54af6f8a800fb795cd9dc8322a1d806 Mon Sep 17 00:00:00 2001 From: Bruno Harbulot Date: Fri, 12 Feb 2016 10:53:08 +0000 Subject: [PATCH 2/2] Fixing debugging statement. --- pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java index b231ffd..f7eb95a 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java @@ -101,7 +101,7 @@ public class PluginClassLoader extends URLClassLoader { } } - log.debug("Couldn't find class '{}' in plugin classpath. Delegating to parent"); + log.debug("Couldn't find class '{}' in plugin classpath. Delegating to parent", className); // use the standard URLClassLoader (which follows normal parent delegation) return super.loadClass(className);