diff options
author | Jan Høydahl <janhoy@users.noreply.github.com> | 2017-04-01 07:43:53 +0200 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2017-04-01 08:43:53 +0300 |
commit | aef9d3a48699a978650fefa902ad3520aa1b7592 (patch) | |
tree | 83c2b535f33059d11e7fbe1aed2dc7ebf1126adf | |
parent | 9f284467b3660298de7786be448f27577769b0b2 (diff) | |
download | pf4j-aef9d3a48699a978650fefa902ad3520aa1b7592.tar.gz pf4j-aef9d3a48699a978650fefa902ad3520aa1b7592.zip |
Fix bug in loadJars() (#131)
Fix bug in load-jars which would not detect jars from lib/ if Path is not absolute
Add slf4j-simple logger in test scope for some logging from tests
Convert some File usage to Path
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | pf4j/pom.xml | 6 | ||||
-rw-r--r-- | pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginDescriptorFinder.java | 3 | ||||
-rw-r--r-- | pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginLoader.java | 2 | ||||
-rw-r--r-- | pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java | 22 |
5 files changed, 20 insertions, 14 deletions
@@ -4,3 +4,4 @@ target/ .settings .idea/ *.iml +demo-dist/ diff --git a/pf4j/pom.xml b/pf4j/pom.xml index fe448a5..aeefe49 100644 --- a/pf4j/pom.xml +++ b/pf4j/pom.xml @@ -33,6 +33,12 @@ <version>1.7.5</version> </dependency> <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>1.7.5</version> + <scope>test</scope> + </dependency> + <dependency> <groupId>com.github.zafarkhaja</groupId> <artifactId>java-semver</artifactId> <version>0.9.0</version> diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginDescriptorFinder.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginDescriptorFinder.java index e58aa05..8b7eb37 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginDescriptorFinder.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginDescriptorFinder.java @@ -44,6 +44,9 @@ public class DefaultPluginDescriptorFinder extends ManifestPluginDescriptorFinde @Override public Manifest readManifest(Path pluginPath) throws PluginException { // TODO it's ok with first classes root? Another idea is to specify in PluginClasspath the folder. + if (pluginClasspath.getClassesDirectories().size() == 0) { + throw new PluginException("Failed to read manifest, no classes folder in classpath"); + } String classes = pluginClasspath.getClassesDirectories().get(0); Path manifestPath = pluginPath.resolve(Paths.get(classes,"/META-INF/MANIFEST.MF")); log.debug("Lookup plugin descriptor in '{}'", manifestPath); diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginLoader.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginLoader.java index 88bbbef..e4c6b9f 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginLoader.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginLoader.java @@ -69,7 +69,7 @@ public class DefaultPluginLoader implements PluginLoader { */ protected void loadJars(Path pluginPath, PluginClassLoader pluginClassLoader) { for (String libDirectory : pluginClasspath.getLibDirectories()) { - File file = pluginPath.resolve(libDirectory).toFile(); + Path file = pluginPath.resolve(libDirectory); List<File> jars = FileUtils.getJars(file); for (File jar : jars) { pluginClassLoader.addFile(jar); diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java b/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java index 9e2ca10..8cf29e4 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java @@ -15,13 +15,9 @@ */ package ro.fortsoft.pf4j.util; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileFilter; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -96,27 +92,27 @@ public class FileUtils { return success; } - public static List<File> getJars(File folder) { + public static List<File> getJars(Path folder) { List<File> bucket = new ArrayList<>(); getJars(bucket, folder); return bucket; } - private static void getJars(List<File> bucket, File folder) { + private static void getJars(final List<File> bucket, Path folder) { FileFilter jarFilter = new JarFileFilter(); FileFilter directoryFilter = new DirectoryFileFilter(); - if (folder.exists() && folder.isDirectory() && folder.isAbsolute()) { - File[] jars = folder.listFiles(jarFilter); + if (Files.exists(folder) && Files.isDirectory(folder)) { + File[] jars = folder.toFile().listFiles(jarFilter); for (int i = 0; (jars != null) && (i < jars.length); ++i) { bucket.add(jars[i]); } - File[] directories = folder.listFiles(directoryFilter); + File[] directories = folder.toFile().listFiles(directoryFilter); for (int i = 0; (directories != null) && (i < directories.length); ++i) { File directory = directories[i]; - getJars(bucket, directory); + getJars(bucket, directory.toPath()); } } } |