diff options
-rw-r--r-- | pf4j/src/main/java/org/pf4j/AbstractPluginManager.java | 7 | ||||
-rw-r--r-- | pf4j/src/main/java/org/pf4j/PluginClassLoader.java | 21 |
2 files changed, 28 insertions, 0 deletions
diff --git a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java index 17116ae..0e750ad 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java +++ b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java @@ -619,6 +619,13 @@ public abstract class AbstractPluginManager implements PluginManager { if (plugin.getPluginClassLoader() == classLoader) { return plugin; } + + if (plugin.getPluginClassLoader() instanceof PluginClassLoader) { + PluginClassLoader pluginClassLoader = (PluginClassLoader) plugin.getPluginClassLoader(); + if (pluginClassLoader.isClassLoaded(clazz.getName())) { + return plugin; + } + } } return null; diff --git a/pf4j/src/main/java/org/pf4j/PluginClassLoader.java b/pf4j/src/main/java/org/pf4j/PluginClassLoader.java index 2043929..1fc79da 100644 --- a/pf4j/src/main/java/org/pf4j/PluginClassLoader.java +++ b/pf4j/src/main/java/org/pf4j/PluginClassLoader.java @@ -22,7 +22,10 @@ import java.io.File; import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; +import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; /** * One instance of this class should be created by plugin manager for every available plug-in. @@ -43,6 +46,8 @@ public class PluginClassLoader extends URLClassLoader { private PluginDescriptor pluginDescriptor; private boolean parentFirst; + private Set<String> loadedClasses; + public PluginClassLoader(PluginManager pluginManager, PluginDescriptor pluginDescriptor, ClassLoader parent) { this(pluginManager, pluginDescriptor, parent, false); } @@ -57,6 +62,8 @@ public class PluginClassLoader extends URLClassLoader { this.pluginManager = pluginManager; this.pluginDescriptor = pluginDescriptor; this.parentFirst = parentFirst; + + loadedClasses = new HashSet<>(); } @Override @@ -108,6 +115,7 @@ public class PluginClassLoader extends URLClassLoader { try { loadedClass = findClass(className); log.trace("Found class '{}' in plugin classpath", className); + loadedClasses.add(className); return loadedClass; } catch (ClassNotFoundException e) { // try next step @@ -138,6 +146,7 @@ public class PluginClassLoader extends URLClassLoader { try { loadedClass = findClass(className); log.trace("Found class '{}' in plugin classpath", className); + loadedClasses.add(className); return loadedClass; } catch (ClassNotFoundException e) { // try next step @@ -189,6 +198,18 @@ public class PluginClassLoader extends URLClassLoader { } } + /** + * Returns all classes loaded by this class loader. + */ + public Set<String> getLoadedClasses() { + return Collections.unmodifiableSet(loadedClasses); + } + + public boolean isClassLoaded(String className) { +// return findLoadedClass(className) != null; + return loadedClasses.contains(className); + } + private Class<?> loadClassFromDependencies(String className) { log.trace("Search in dependencies for class '{}'", className); List<PluginDependency> dependencies = pluginDescriptor.getDependencies(); |