From: John Niang Date: Sat, 6 Apr 2024 14:25:21 +0000 (+0800) Subject: Fix the problem of not being able to disable plugins correctly (#577) X-Git-Tag: release-3.11.1~6 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f563b9168b4beaca95b28541c1031b0dd7bed913;p=pf4j.git Fix the problem of not being able to disable plugins correctly (#577) --- diff --git a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java index 78c261c..559fc81 100644 --- a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java +++ b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java @@ -537,7 +537,7 @@ public abstract class AbstractPluginManager implements PluginManager { log.debug("Already disabled plugin '{}'", getPluginLabel(pluginDescriptor)); return true; } else if (PluginState.STARTED == pluginState) { - if (PluginState.STOPPED == stopPlugin(pluginId)) { + if (PluginState.STOPPED != stopPlugin(pluginId)) { log.error("Failed to stop plugin '{}' on disable", getPluginLabel(pluginDescriptor)); return false; } diff --git a/pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java b/pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java index d95a2d0..bc23630 100644 --- a/pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java +++ b/pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java @@ -166,6 +166,19 @@ public class DefaultPluginManagerTest { assertSame(PluginState.DISABLED, plugin.getPluginState()); } + @Test + void shouldDisablePluginAfterStarting() throws IOException { + new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin") + .pluginVersion("1.2.3") + .build(); + + pluginManager.loadPlugins(); + pluginManager.startPlugins(); + assertEquals(PluginState.STARTED, pluginManager.getPlugin("myPlugin").getPluginState()); + pluginManager.disablePlugin("myPlugin"); + assertEquals(PluginState.DISABLED, pluginManager.getPlugin("myPlugin").getPluginState()); + } + @Test public void deleteZipPlugin() throws Exception { PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")