From e73f1a46f2130eec79ca6de64ac5408a0aeac9a0 Mon Sep 17 00:00:00 2001 From: Alexander Horuzhiy <123456> Date: Mon, 18 Jan 2016 16:25:39 +0100 Subject: [PATCH 1/3] Fix issue with listing files from the Jar file. Work with Jar's like with external file system using NIO. --- .../pf4j/ServiceProviderExtensionFinder.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java b/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java index 05c9cb4..64af946 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java @@ -25,11 +25,10 @@ import java.io.IOException; import java.io.Reader; import java.net.URISyntaxException; import java.net.URL; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.nio.file.*; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.*; +import java.util.stream.Stream; /** * The ServiceLoader base implementation for ExtensionFinder. @@ -50,18 +49,26 @@ public class ServiceProviderExtensionFinder extends AbstractExtensionFinder { log.debug("Reading extensions storages from classpath"); Map> result = new LinkedHashMap<>(); - Set bucket = new HashSet<>(); + final Set bucket = new HashSet<>(); try { URL url = getClass().getClassLoader().getResource(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); ServiceProviderExtensionStorage.read(reader, bucket); + return FileVisitResult.CONTINUE; } - } + }); } if (bucket.isEmpty()) { From a6b782623da7e65a3f8caf094d3e6b0b0ed34458 Mon Sep 17 00:00:00 2001 From: Alexander Horuzhiy <123456> Date: Mon, 18 Jan 2016 16:31:54 +0100 Subject: [PATCH 2/3] Remove Java 8 dependency --- .../java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java | 1 - 1 file changed, 1 deletion(-) diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java b/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java index 64af946..da82fe9 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java @@ -28,7 +28,6 @@ import java.net.URL; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.*; -import java.util.stream.Stream; /** * The ServiceLoader base implementation for ExtensionFinder. From 51adfb7c744d4f2722f786123de219cc8311b059 Mon Sep 17 00:00:00 2001 From: Alexander Horuzhiy <123456> Date: Mon, 18 Jan 2016 16:34:39 +0100 Subject: [PATCH 3/3] Change Java 8 newBufferedReader method to be compiled on Java 7 --- .../java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java b/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java index da82fe9..95bf879 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.io.Reader; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.*; @@ -63,7 +64,7 @@ public class ServiceProviderExtensionFinder extends AbstractExtensionFinder { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { log.debug("Read '{}'", file); - Reader reader = Files.newBufferedReader(file); + Reader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8); ServiceProviderExtensionStorage.read(reader, bucket); return FileVisitResult.CONTINUE; }