]> source.dussan.org Git - pf4j.git/commitdiff
Fix the problem of not being able to disable plugins correctly (#577)
authorJohn Niang <johnniang@foxmail.com>
Sat, 6 Apr 2024 14:25:21 +0000 (22:25 +0800)
committerGitHub <noreply@github.com>
Sat, 6 Apr 2024 14:25:21 +0000 (17:25 +0300)
pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java

index 78c261c118ecbfd871fcc94198a8ba583f016ea9..559fc811c331f506b79397c80451807bb7290866 100644 (file)
@@ -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;
             }
index d95a2d08e1f439857a2f4c414480b082a646b520..bc2363077a95b7afef83e61e5400816af7e1c795 100644 (file)
@@ -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")