aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDecebal Suiu <decebal.suiu@gmail.com>2016-01-18 21:55:39 +0200
committerDecebal Suiu <decebal.suiu@gmail.com>2016-01-18 21:55:39 +0200
commitc3afe7ede0b4cdfe70d7a63b3612cef46fed0f67 (patch)
treecfcd4b493b57310b6a609b61a2f5df3d3ec75d12
parentabc4bfa220216f986f2f336bd17672e4dea6bc21 (diff)
parent51adfb7c744d4f2722f786123de219cc8311b059 (diff)
downloadpf4j-c3afe7ede0b4cdfe70d7a63b3612cef46fed0f67.tar.gz
pf4j-c3afe7ede0b4cdfe70d7a63b3612cef46fed0f67.zip
Merge pull request #87 from horuzhiy/master
Fix issue "URI is not hierarchical" when working with extensions jar's
-rw-r--r--pf4j/src/main/java/ro/fortsoft/pf4j/ServiceProviderExtensionFinder.java29
1 files 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..95bf879 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.charset.StandardCharsets;
+import java.nio.file.*;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.*;
/**
* The ServiceLoader base implementation for ExtensionFinder.
@@ -50,18 +49,26 @@ public class ServiceProviderExtensionFinder extends AbstractExtensionFinder {
log.debug("Reading extensions storages from classpath");
Map<String, Set<String>> result = new LinkedHashMap<>();
- Set<String> bucket = new HashSet<>();
+ final Set<String> 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.<String, Object>emptyMap());
+ extensionPath = fileSystem.getPath(getExtensionsResource());
+ } else {
+ extensionPath = Paths.get(url.toURI());
+ }
+ Files.walkFileTree(extensionPath, Collections.<FileVisitOption>emptySet(), 1, new SimpleFileVisitor<Path>() {
+ @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;
}
- }
+ });
}
if (bucket.isEmpty()) {