From 77c4e004691ae74cf5398bb9908d92bcbf853f1c Mon Sep 17 00:00:00 2001 From: Decebal Suiu Date: Wed, 23 Apr 2014 17:49:17 +0300 Subject: [PATCH] add dispose method in PluginClassLoader --- .../fortsoft/pf4j/DefaultPluginManager.java | 7 ++----- .../ro/fortsoft/pf4j/PluginClassLoader.java | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java index 22f899d..62a7a6d 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/DefaultPluginManager.java @@ -411,11 +411,7 @@ public class DefaultPluginManager implements PluginManager { // remove the classloader if (pluginClassLoaders.containsKey(pluginId)) { PluginClassLoader classLoader = pluginClassLoaders.remove(pluginId); - try { - classLoader.close(); - } catch (IOException e) { - log.error(e.getMessage(), e); - } + classLoader.dispose(); } return true; @@ -803,6 +799,7 @@ public class DefaultPluginManager implements PluginManager { unzip.setDestination(pluginDirectory); unzip.extract(); } + return pluginDirectory; } diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java index 4b3f137..5573703 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginClassLoader.java @@ -12,6 +12,10 @@ */ package ro.fortsoft.pf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; import java.util.List; @@ -23,6 +27,8 @@ import java.util.List; */ 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 JAVAX_PACKAGE_PREFIX = "javax."; 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) 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); + } + } + }