From: James Moger Date: Thu, 10 Apr 2014 01:34:02 +0000 (-0400) Subject: Allow inspection of disabled plugins by not stopping resource loading X-Git-Tag: release-0.7.0~1^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F10%2Fhead;p=pf4j.git Allow inspection of disabled plugins by not stopping resource loading The differences between a DISABLED plugin and a STARTED plugin are: 1. a STARTED plugin has executed Plugin.start(), a DISABLED plugin has not 2. a STARTED plugin may contribute extension instances, a DISABLED plugin may not DISABLED plugins still have valid classloaders and their classes can be manually loaded and explored, but the resource loading - which is important for inspection has been handicapped by the DISABLED check. Instead of preventing loading the extension indexes for DISABLED plugins, the extension finder should only return ExtensionWrappers for STARTED plugins. --- diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultExtensionFinder.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultExtensionFinder.java index 295d5c8..5da04b6 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultExtensionFinder.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultExtensionFinder.java @@ -56,6 +56,12 @@ public class DefaultExtensionFinder implements ExtensionFinder, PluginStateListe List> result = new ArrayList>(); for (Map.Entry> entry : entries.entrySet()) { String pluginId = entry.getKey(); + + PluginWrapper pluginWrapper = pluginManager.getPlugin(pluginId); + if (PluginState.STARTED != pluginWrapper.getPluginState()) { + continue; + } + Set extensionClassNames = entry.getValue(); for (String className : extensionClassNames) { @@ -92,10 +98,12 @@ public class DefaultExtensionFinder implements ExtensionFinder, PluginStateListe @Override public Set findClassNames(String pluginId) { + readIndexFiles(); return entries.get(pluginId); } - public void pluginStateChanged(PluginStateEvent event) { + @Override + public void pluginStateChanged(PluginStateEvent event) { // TODO optimize (do only for some transitions) // clear cache entries = null; @@ -134,8 +142,8 @@ public class DefaultExtensionFinder implements ExtensionFinder, PluginStateListe entries = new HashMap>(); - List startedPlugins = pluginManager.getStartedPlugins(); - for (PluginWrapper plugin : startedPlugins) { + List plugins = pluginManager.getPlugins(); + for (PluginWrapper plugin : plugins) { String pluginId = plugin.getDescriptor().getPluginId(); log.debug("Reading extensions index file for plugin '{}'", pluginId); Set entriesPerPlugin = new HashSet(); @@ -164,7 +172,7 @@ public class DefaultExtensionFinder implements ExtensionFinder, PluginStateListe return entries; } - private boolean isExtensionPoint(Class type) { + private boolean isExtensionPoint(Class type) { return ExtensionPoint.class.isAssignableFrom(type); } diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java index 3fd7572..4b3f137 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java @@ -12,11 +12,8 @@ */ package ro.fortsoft.pf4j; -import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; -import java.util.Collections; -import java.util.Enumeration; import java.util.List; /** @@ -93,27 +90,4 @@ public class PluginClassLoader extends URLClassLoader { // use the standard URLClassLoader (which follows normal parent delegation) return super.loadClass(className); } - - @Override - public URL getResource(String name) { - if (PluginState.DISABLED == getPlugin().getPluginState()) { - return null; - } - - return super.getResource(name); - } - - @Override - public Enumeration getResources(String name) throws IOException { - if (PluginState.DISABLED == getPlugin().getPluginState()) { - return Collections.emptyEnumeration(); - } - - return super.getResources(name); - } - - private PluginWrapper getPlugin() { - return pluginManager.getPlugin(pluginDescriptor.getPluginId()); - } - }