Browse Source

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.
pull/10/head
James Moger 11 years ago
parent
commit
e80ae32868
  1. 16
      pf4j/src/main/java/ro/fortsoft/pf4j/DefaultExtensionFinder.java
  2. 26
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java

16
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);
}

26
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());
}
}

Loading…
Cancel
Save