Browse Source

Fix #590

pull/592/head
Decebal Suiu 2 months ago
parent
commit
de2a2ecfba
  1. 2
      pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
  2. 14
      pf4j/src/main/java/org/pf4j/PluginStateEvent.java
  3. 19
      pf4j/src/test/java/org/pf4j/AbstractPluginManagerTest.java

2
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;
}

14
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);
}
}

19
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)

Loading…
Cancel
Save