Browse Source

add dispose method in PluginClassLoader

pull/22/head
Decebal Suiu 11 years ago
parent
commit
77c4e00469
  1. 7
      pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java
  2. 21
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java

7
pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java

@ -411,11 +411,7 @@ public class DefaultPluginManager implements PluginManager {
// remove the classloader // remove the classloader
if (pluginClassLoaders.containsKey(pluginId)) { if (pluginClassLoaders.containsKey(pluginId)) {
PluginClassLoader classLoader = pluginClassLoaders.remove(pluginId); PluginClassLoader classLoader = pluginClassLoaders.remove(pluginId);
try { classLoader.dispose();
classLoader.close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
} }
return true; return true;
@ -803,6 +799,7 @@ public class DefaultPluginManager implements PluginManager {
unzip.setDestination(pluginDirectory); unzip.setDestination(pluginDirectory);
unzip.extract(); unzip.extract();
} }
return pluginDirectory; return pluginDirectory;
} }

21
pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java

@ -12,6 +12,10 @@
*/ */
package ro.fortsoft.pf4j; package ro.fortsoft.pf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.List; import java.util.List;
@ -23,6 +27,8 @@ import java.util.List;
*/ */
public class PluginClassLoader extends URLClassLoader { public class PluginClassLoader extends URLClassLoader {
private static final Logger log = LoggerFactory.getLogger(PluginClassLoader.class);
// private static final String JAVA_PACKAGE_PREFIX = "java."; // private static final String JAVA_PACKAGE_PREFIX = "java.";
// private static final String JAVAX_PACKAGE_PREFIX = "javax."; // private static final String JAVAX_PACKAGE_PREFIX = "javax.";
private static final String PLUGIN_PACKAGE_PREFIX = "ro.fortsoft.pf4j."; private static final String PLUGIN_PACKAGE_PREFIX = "ro.fortsoft.pf4j.";
@ -90,4 +96,19 @@ public class PluginClassLoader extends URLClassLoader {
// use the standard URLClassLoader (which follows normal parent delegation) // use the standard URLClassLoader (which follows normal parent delegation)
return super.loadClass(className); return super.loadClass(className);
} }
/**
* Release all resources acquired by this class loader.
* The current implementation is incomplete.
* For now, this instance can no longer be used to load
* new classes or resources that are defined by this loader.
*/
public void dispose() {
try {
close();
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
} }

Loading…
Cancel
Save