summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-04-09 21:34:02 -0400
committerJames Moger <james.moger@gitblit.com>2014-04-09 22:02:33 -0400
commite80ae328688cac8876cea441e6f36fc053373979 (patch)
treef7979dd9a289a40bb095aebb8adb838a6bdcd05a
parent7e00f212b15a07584bf0130272761675302c1116 (diff)
downloadpf4j-e80ae328688cac8876cea441e6f36fc053373979.tar.gz
pf4j-e80ae328688cac8876cea441e6f36fc053373979.zip
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.
-rw-r--r--pf4j/src/main/java/ro/fortsoft/pf4j/DefaultExtensionFinder.java16
-rw-r--r--pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java26
2 files changed, 12 insertions, 30 deletions
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<ExtensionWrapper<T>> result = new ArrayList<ExtensionWrapper<T>>();
for (Map.Entry<String, Set<String>> entry : entries.entrySet()) {
String pluginId = entry.getKey();
+
+ PluginWrapper pluginWrapper = pluginManager.getPlugin(pluginId);
+ if (PluginState.STARTED != pluginWrapper.getPluginState()) {
+ continue;
+ }
+
Set<String> extensionClassNames = entry.getValue();
for (String className : extensionClassNames) {
@@ -92,10 +98,12 @@ public class DefaultExtensionFinder implements ExtensionFinder, PluginStateListe
@Override
public Set<String> 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<String, Set<String>>();
- List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins();
- for (PluginWrapper plugin : startedPlugins) {
+ List<PluginWrapper> plugins = pluginManager.getPlugins();
+ for (PluginWrapper plugin : plugins) {
String pluginId = plugin.getDescriptor().getPluginId();
log.debug("Reading extensions index file for plugin '{}'", pluginId);
Set<String> entriesPerPlugin = new HashSet<String>();
@@ -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<URL> 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());
- }
-
}