Browse Source

Merge pull request #10 from gitblit/resource_loading

Allow inspection of disabled plugins by not stopping resource loading
pull/11/head
Decebal Suiu 11 years ago
parent
commit
66caaa34f4
  1. 14
      pf4j/src/main/java/ro/fortsoft/pf4j/DefaultExtensionFinder.java
  2. 26
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java

14
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,9 +98,11 @@ public class DefaultExtensionFinder implements ExtensionFinder, PluginStateListe
@Override
public Set<String> findClassNames(String pluginId) {
readIndexFiles();
return entries.get(pluginId);
}
@Override
public void pluginStateChanged(PluginStateEvent event) {
// TODO optimize (do only for some transitions)
// clear cache
@ -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