Browse Source

fix #63

pull/66/head
Decebal Suiu 9 years ago
parent
commit
7dc4007c27
  1. 14
      pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java
  2. 29
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginLoader.java

14
pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java

@ -718,6 +718,13 @@ public class DefaultPluginManager implements PluginManager {
return new DefaultExtensionFactory(); return new DefaultExtensionFactory();
} }
/**
* Add the possibility to override the PluginClassLoader.
*/
protected PluginClassLoader createPluginClassLoader(PluginDescriptor pluginDescriptor) {
return new PluginClassLoader(this, pluginDescriptor, getClass().getClassLoader());
}
private void initialize() { private void initialize() {
plugins = new HashMap<>(); plugins = new HashMap<>();
pluginClassLoaders = new HashMap<>(); pluginClassLoaders = new HashMap<>();
@ -765,13 +772,15 @@ public class DefaultPluginManager implements PluginManager {
// load plugin // load plugin
log.debug("Loading plugin '{}'", pluginPath); log.debug("Loading plugin '{}'", pluginPath);
PluginLoader pluginLoader = new PluginLoader(this, pluginDescriptor, pluginDirectory, pluginClasspath); PluginClassLoader pluginClassLoader = createPluginClassLoader(pluginDescriptor);
log.debug("Created class loader '{}'", pluginClassLoader);
PluginLoader pluginLoader = new PluginLoader(pluginDirectory, pluginClassLoader, pluginClasspath);
pluginLoader.load(); pluginLoader.load();
log.debug("Loaded plugin '{}'", pluginPath); log.debug("Loaded plugin '{}'", pluginPath);
// create the plugin wrapper // create the plugin wrapper
log.debug("Creating wrapper for plugin '{}'", pluginPath); log.debug("Creating wrapper for plugin '{}'", pluginPath);
PluginWrapper pluginWrapper = new PluginWrapper(pluginDescriptor, pluginPath, pluginLoader.getPluginClassLoader()); PluginWrapper pluginWrapper = new PluginWrapper(pluginDescriptor, pluginPath, pluginClassLoader);
pluginWrapper.setPluginFactory(pluginFactory); pluginWrapper.setPluginFactory(pluginFactory);
pluginWrapper.setRuntimeMode(getRuntimeMode()); pluginWrapper.setRuntimeMode(getRuntimeMode());
@ -796,7 +805,6 @@ public class DefaultPluginManager implements PluginManager {
unresolvedPlugins.add(pluginWrapper); unresolvedPlugins.add(pluginWrapper);
// add plugin class loader to the list with class loaders // add plugin class loader to the list with class loaders
PluginClassLoader pluginClassLoader = pluginLoader.getPluginClassLoader();
pluginClassLoaders.put(pluginId, pluginClassLoader); pluginClassLoaders.put(pluginId, pluginClassLoader);
return pluginWrapper; return pluginWrapper;

29
pf4j/src/main/java/ro/fortsoft/pf4j/PluginLoader.java

@ -12,22 +12,20 @@
*/ */
package ro.fortsoft.pf4j; package ro.fortsoft.pf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ro.fortsoft.pf4j.util.DirectoryFileFilter;
import ro.fortsoft.pf4j.util.JarFileFilter;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.util.List; import java.util.List;
import java.util.Vector; import java.util.Vector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ro.fortsoft.pf4j.util.DirectoryFileFilter;
import ro.fortsoft.pf4j.util.JarFileFilter;
/** /**
* Load all information needed by a plugin. * Load all information needed by a plugin.
* This means add all jar files from 'lib' directory, 'classes' * This means add all jar files from 'lib' directory, 'classes' to classpath.
* to classpath.
* It's a class for only the internal use. * It's a class for only the internal use.
* *
* @author Decebal Suiu * @author Decebal Suiu
@ -44,27 +42,16 @@ class PluginLoader {
private PluginClasspath pluginClasspath; private PluginClasspath pluginClasspath;
private PluginClassLoader pluginClassLoader; private PluginClassLoader pluginClassLoader;
public PluginLoader(PluginManager pluginManager, PluginDescriptor pluginDescriptor, File pluginRepository, PluginClasspath pluginClasspath) { public PluginLoader(File pluginRepository, PluginClassLoader pluginClassLoader, PluginClasspath pluginClasspath) {
this.pluginRepository = pluginRepository; this.pluginRepository = pluginRepository;
this.pluginClassLoader = pluginClassLoader;
this.pluginClasspath = pluginClasspath; this.pluginClasspath = pluginClasspath;
ClassLoader parent = getClass().getClassLoader();
pluginClassLoader = new PluginClassLoader(pluginManager, pluginDescriptor, parent);
log.debug("Created class loader '{}'", pluginClassLoader);
}
public File getPluginRepository() {
return pluginRepository;
} }
public boolean load() { public boolean load() {
return loadClassesAndJars(); return loadClassesAndJars();
} }
public PluginClassLoader getPluginClassLoader() {
return pluginClassLoader;
}
private boolean loadClassesAndJars() { private boolean loadClassesAndJars() {
return loadClasses() && loadJars(); return loadClasses() && loadJars();
} }

Loading…
Cancel
Save