From 7dc4007c27d9898a04ceeca2aa9ceb1da3637d6e Mon Sep 17 00:00:00 2001 From: Decebal Suiu Date: Thu, 6 Aug 2015 16:46:08 +0300 Subject: [PATCH] fix #63 --- .../fortsoft/pf4j/DefaultPluginManager.java | 14 +++++++-- .../java/ro/fortsoft/pf4j/PluginLoader.java | 29 +++++-------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java index a6437e5..6976d3d 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java +++ b/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; diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginLoader.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginLoader.java index e1ec26c..e361c6a 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginLoader.java +++ b/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(); } -- 2.39.5