Browse Source

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
pull/134/head
Jan Høydahl 8 years ago committed by Decebal Suiu
parent
commit
aef9d3a486
  1. 1
      .gitignore
  2. 6
      pf4j/pom.xml
  3. 3
      pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginDescriptorFinder.java
  4. 2
      pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginLoader.java
  5. 22
      pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java

1
.gitignore vendored

@ -4,3 +4,4 @@ target/
.settings
.idea/
*.iml
demo-dist/

6
pf4j/pom.xml

@ -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>

3
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);

2
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);

22
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());
}
}
}

Loading…
Cancel
Save