aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDecebal Suiu <decebal.suiu@gmail.com>2024-10-12 18:45:35 +0300
committerDecebal Suiu <decebal.suiu@gmail.com>2024-10-12 18:45:35 +0300
commitde2a2ecfbad573151c7bf19f77ab0710362edbb1 (patch)
treead64026cace0149247dfd9774d18163da3d340c0
parent77fe308856119c8e178a547c6306f184d439a219 (diff)
downloadpf4j-de2a2ecfbad573151c7bf19f77ab0710362edbb1.tar.gz
pf4j-de2a2ecfbad573151c7bf19f77ab0710362edbb1.zip
Fix #590
-rw-r--r--pf4j/src/main/java/org/pf4j/AbstractPluginManager.java2
-rw-r--r--pf4j/src/main/java/org/pf4j/PluginStateEvent.java14
-rw-r--r--pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java19
3 files changed, 34 insertions, 1 deletions
diff --git a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
index f576210..626dbcb 100644
--- a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
+++ b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
@@ -516,7 +516,7 @@ public abstract class AbstractPluginManager implements PluginManager {
pluginWrapper.setPluginState(PluginState.STOPPED);
getStartedPlugins().remove(pluginWrapper);
- firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, PluginState.STOPPED));
+ firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, PluginState.STARTED));
return PluginState.STOPPED;
}
diff --git a/pf4j/src/main/java/org/pf4j/PluginStateEvent.java b/pf4j/src/main/java/org/pf4j/PluginStateEvent.java
index 8793abe..efcc66a 100644
--- a/pf4j/src/main/java/org/pf4j/PluginStateEvent.java
+++ b/pf4j/src/main/java/org/pf4j/PluginStateEvent.java
@@ -16,6 +16,7 @@
package org.pf4j;
import java.util.EventObject;
+import java.util.Objects;
/**
* Event object that indicates a change in the state of a plugin.
@@ -83,4 +84,17 @@ public class PluginStateEvent extends EventObject {
']';
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ PluginStateEvent that = (PluginStateEvent) o;
+ return Objects.equals(plugin, that.plugin) && oldState == that.oldState;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(plugin, oldState);
+ }
+
}
diff --git a/pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java b/pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java
index 88be865..e67e081 100644
--- a/pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java
+++ b/pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java
@@ -138,6 +138,25 @@ public class AbstractPluginManagerTest {
verify(pluginManager, times(1)).resolveDependencies();
}
+ @Test
+ void stopPluginFirePluginStateListeners() {
+ PluginStateListener pluginStateListener = mock(PluginStateListener.class);
+ pluginManager.addPluginStateListener(pluginStateListener);
+
+ String pluginId = "plugin1";
+ PluginWrapper pluginWrapper = createPluginWrapper(pluginId);
+ pluginWrapper.setPluginState(PluginState.STARTED);
+
+ doReturn(pluginWrapper).when(pluginManager).getPlugin(pluginId);
+ doNothing().when(pluginManager).checkPluginId(pluginId);
+ doReturn(new ArrayList<>(Arrays.asList(pluginWrapper))).when(pluginManager).getStartedPlugins();
+
+ pluginManager.stopPlugin(pluginId, false);
+
+ PluginStateEvent event = new PluginStateEvent(pluginManager, pluginWrapper, PluginState.STARTED);
+ verify(pluginStateListener).pluginStateChanged(event);
+ }
+
private PluginWrapper createPluginWrapper(String pluginId, String... dependencies) {
PluginDescriptor pluginDescriptor = new DefaultPluginDescriptor()
.setPluginId(pluginId)