From c4bf168259f7492df57af69a8c2ff7a3a7662ba3 Mon Sep 17 00:00:00 2001 From: Decebal Suiu Date: Thu, 7 Sep 2017 23:05:24 +0300 Subject: [PATCH] Fix #161 --- .../fortsoft/pf4j/AbstractPluginManager.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/AbstractPluginManager.java b/pf4j/src/main/java/ro/fortsoft/pf4j/AbstractPluginManager.java index 4d0cca6..94fee2f 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/AbstractPluginManager.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/AbstractPluginManager.java @@ -241,22 +241,32 @@ public abstract class AbstractPluginManager implements PluginManager { } } + /** + * Unload the specified plugin and it's dependents. + */ @Override public boolean unloadPlugin(String pluginId) { + return unloadPlugin(pluginId, true); + } + + private boolean unloadPlugin(String pluginId, boolean unloadDependents) { try { - PluginState pluginState = stopPlugin(pluginId); + if (unloadDependents) { + List dependents = dependencyResolver.getDependents(pluginId); + while (!dependents.isEmpty()) { + String dependent = dependents.remove(0); + unloadPlugin(dependent, false); + dependents.addAll(0, dependencyResolver.getDependents(dependent)); + } + } + + PluginState pluginState = stopPlugin(pluginId, false); if (PluginState.STARTED == pluginState) { return false; } PluginWrapper pluginWrapper = getPlugin(pluginId); - PluginDescriptor descriptor = pluginWrapper.getDescriptor(); - List dependencies = descriptor.getDependencies(); - for (PluginDependency dependency : dependencies) { - if (!unloadPlugin(dependency.getPluginId())) { - return false; - } - } + log.info("Unload plugin '{}'", getPluginLabel(pluginWrapper.getDescriptor())); // remove the plugin plugins.remove(pluginId); @@ -409,7 +419,7 @@ public abstract class AbstractPluginManager implements PluginManager { PluginDescriptor pluginDescriptor = pluginWrapper.getDescriptor(); PluginState pluginState = pluginWrapper.getPluginState(); if (PluginState.STOPPED == pluginState) { - log.debug("Already stopped plugin '{}:{}'", pluginDescriptor.getPluginId(), pluginDescriptor.getVersion()); + log.debug("Already stopped plugin '{}'", getPluginLabel(pluginDescriptor)); return PluginState.STOPPED; } @@ -429,7 +439,7 @@ public abstract class AbstractPluginManager implements PluginManager { } try { - log.info("Stop plugin '{}:{}'", pluginDescriptor.getPluginId(), pluginDescriptor.getVersion()); + log.info("Stop plugin '{}'", getPluginLabel(pluginDescriptor)); pluginWrapper.getPlugin().stop(); pluginWrapper.setPluginState(PluginState.STOPPED); startedPlugins.remove(pluginWrapper);