Browse Source

fix #63

pull/66/head
Decebal Suiu 10 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();
}
/**
* Add the possibility to override the PluginClassLoader.
*/
protected PluginClassLoader createPluginClassLoader(PluginDescriptor pluginDescriptor) {
return new PluginClassLoader(this, pluginDescriptor, getClass().getClassLoader());
}
private void initialize() {
plugins = new HashMap<>();
pluginClassLoaders = new HashMap<>();
@ -765,13 +772,15 @@ public class DefaultPluginManager implements PluginManager {
// load plugin
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();
log.debug("Loaded plugin '{}'", pluginPath);
// create the plugin wrapper
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.setRuntimeMode(getRuntimeMode());
@ -796,7 +805,6 @@ public class DefaultPluginManager implements PluginManager {
unresolvedPlugins.add(pluginWrapper);
// add plugin class loader to the list with class loaders
PluginClassLoader pluginClassLoader = pluginLoader.getPluginClassLoader();
pluginClassLoaders.put(pluginId, pluginClassLoader);
return pluginWrapper;

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

@ -12,22 +12,20 @@
*/
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.FileFilter;
import java.net.MalformedURLException;
import java.util.List;
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.
* This means add all jar files from 'lib' directory, 'classes'
* to classpath.
* This means add all jar files from 'lib' directory, 'classes' to classpath.
* It's a class for only the internal use.
*
* @author Decebal Suiu
@ -44,27 +42,16 @@ class PluginLoader {
private PluginClasspath pluginClasspath;
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.pluginClassLoader = pluginClassLoader;
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() {
return loadClassesAndJars();
}
public PluginClassLoader getPluginClassLoader() {
return pluginClassLoader;
}
private boolean loadClassesAndJars() {
return loadClasses() && loadJars();
}

Loading…
Cancel
Save