Skip to content

Commit

Permalink
Fix bug in load-jars which would not detect jars from lib/ if Path is…
Browse files Browse the repository at this point in the history
… not absolute

Add slf4j-simple logger in test scope for some logging from tests
Convert some File usage to Path
  • Loading branch information
janhoy committed Mar 30, 2017
1 parent e9126c4 commit 5b2b800
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
6 changes: 6 additions & 0 deletions pf4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
<artifactId>slf4j-api</artifactId>
<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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected void loadClasses(Path pluginPath, PluginClassLoader pluginClassLoader)
*/
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);
Expand Down
22 changes: 9 additions & 13 deletions pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -96,27 +92,27 @@ public static boolean delete(File fileOrFolder) {
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());
}
}
}
Expand Down

0 comments on commit 5b2b800

Please sign in to comment.