From 58d3c8e183c44fda43adb61ff4b0dba0ca0b3cc0 Mon Sep 17 00:00:00 2001 From: Valeriy Kucherenko Date: Fri, 17 Jul 2020 19:51:43 +0300 Subject: [PATCH] Fix for problem with file lock on Windows platform. Introduce unloadPlugins method. (#387) Thanks for your contribution! --- .../src/main/java/org/pf4j/AbstractPluginManager.java | 11 +++++++++++ pf4j/src/main/java/org/pf4j/PluginManager.java | 5 +++++ pf4j/src/test/java/org/pf4j/JarPluginManagerTest.java | 2 ++ 3 files changed, 18 insertions(+) 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; }