From: Valeriy Kucherenko Date: Fri, 17 Jul 2020 16:51:43 +0000 (+0300) Subject: Fix for problem with file lock on Windows platform. Introduce unloadPlugins method... X-Git-Tag: release-3.4.0~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=58d3c8e183c44fda43adb61ff4b0dba0ca0b3cc0;p=pf4j.git Fix for problem with file lock on Windows platform. Introduce unloadPlugins method. (#387) Thanks for your contribution! --- diff --git a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java index 5b8b82c..ea8d297 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java +++ b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java @@ -235,6 +235,17 @@ public abstract class AbstractPluginManager implements PluginManager { } } + /** + * Unload all plugins + */ + @Override + public void unloadPlugins() { + // wrap resolvedPlugins in new list because of concurrent modification + for (PluginWrapper pluginWrapper : new ArrayList<>(resolvedPlugins)) { + unloadPlugin(pluginWrapper.getPluginId()); + } + } + /** * Unload the specified plugin and it's dependents. */ diff --git a/pf4j/src/main/java/org/pf4j/PluginManager.java b/pf4j/src/main/java/org/pf4j/PluginManager.java index a937f22..248b1ac 100644 --- a/pf4j/src/main/java/org/pf4j/PluginManager.java +++ b/pf4j/src/main/java/org/pf4j/PluginManager.java @@ -100,6 +100,11 @@ public interface PluginManager { */ PluginState stopPlugin(String pluginId); + /** + * Unload all plugins + */ + void unloadPlugins(); + /** * Unload a plugin. * diff --git a/pf4j/src/test/java/org/pf4j/JarPluginManagerTest.java b/pf4j/src/test/java/org/pf4j/JarPluginManagerTest.java index d9ca90a..4eb2872 100644 --- a/pf4j/src/test/java/org/pf4j/JarPluginManagerTest.java +++ b/pf4j/src/test/java/org/pf4j/JarPluginManagerTest.java @@ -53,6 +53,8 @@ public class JarPluginManagerTest { @AfterEach public void tearDown() { + pluginManager.unloadPlugins(); + pluginJar = null; pluginManager = null; }