]> source.dussan.org Git - pf4j.git/commitdiff
Fix #576
authorDecebal Suiu <decebal.suiu@gmail.com>
Sat, 6 Apr 2024 21:11:21 +0000 (00:11 +0300)
committerDecebal Suiu <decebal.suiu@gmail.com>
Sat, 6 Apr 2024 21:11:21 +0000 (00:11 +0300)
pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java

index 559fc811c331f506b79397c80451807bb7290866..d602abf5537e6b1d8c9d37d70942b51f9394e6a2 100644 (file)
@@ -331,6 +331,9 @@ public abstract class AbstractPluginManager implements PluginManager {
             }
         }
 
+        // resolve the plugins again (update plugins graph)
+        resolveDependencies();
+
         return true;
     }
 
index d10689f1f755b079c2d3eb9c2df8b08caf583f58..33f9db051d39171db340b1b6f2d0502fbdc86942 100644 (file)
@@ -396,4 +396,40 @@ public class DefaultPluginManagerTest {
         assertThrows(PluginNotFoundException.class, () -> pluginManager.stopPlugin(pluginZip2.pluginId()));
     }
 
+    @Test
+    void deletePluginWithDependency() throws IOException {
+        PluginZip pluginZip1 = new PluginZip.Builder(pluginsPath.resolve("my-first-plugin-1.1.1.zip"), "myPlugin1")
+            .pluginVersion("1.1.1")
+            .build();
+
+        PluginZip pluginZip2 = new PluginZip.Builder(pluginsPath.resolve("my-second-plugin-2.2.2.zip"), "myPlugin2")
+            .pluginVersion("2.2.2")
+            .pluginDependencies("myPlugin1")
+            .build();
+
+        PluginZip pluginZip3 = new PluginZip.Builder(pluginsPath.resolve("my-third-plugin-3.3.3.zip"), "myPlugin3")
+            .pluginVersion("3.3.3")
+            .pluginDependencies("myPlugin2")
+            .build();
+
+        pluginManager.loadPlugins();
+        pluginManager.startPlugins();
+
+        assertEquals(PluginState.STARTED, pluginManager.getPlugin(pluginZip1.pluginId()).getPluginState());
+        assertEquals(PluginState.STARTED, pluginManager.getPlugin(pluginZip2.pluginId()).getPluginState());
+        assertEquals(PluginState.STARTED, pluginManager.getPlugin(pluginZip3.pluginId()).getPluginState());
+
+        System.out.println("Stopping " + pluginZip2.pluginId());
+        pluginManager.stopPlugin(pluginZip2.pluginId());
+        assertEquals(PluginState.STOPPED, pluginManager.getPlugin(pluginZip2.pluginId()).getPluginState());
+
+        boolean deleted = pluginManager.deletePlugin(pluginZip2.pluginId());
+        assertTrue(deleted);
+
+        assertEquals(1, pluginManager.getPlugins().size()); // myPlugin1 should still be there, myPlugin2 and myPlugin3 should be gone
+
+        pluginManager.stopPlugin(pluginZip1.pluginId());
+        assertEquals(PluginState.STOPPED, pluginManager.getPlugin(pluginZip1.pluginId()).getPluginState());
+    }
+
 }