Browse Source

Only call `stopPlugin` during unload if the plugin is started

Related to #459.
pull/460/head
Sebastian Lövdahl 3 years ago
parent
commit
2385c8d083

+ 7
- 2
pf4j/src/main/java/org/pf4j/AbstractPluginManager.java View File

dependents.addAll(0, dependencyResolver.getDependents(dependent)); dependents.addAll(0, dependencyResolver.getDependents(dependent));
} }
} }

checkPluginId(pluginId);

PluginWrapper pluginWrapper = getPlugin(pluginId); PluginWrapper pluginWrapper = getPlugin(pluginId);
PluginState pluginState; PluginState pluginState;
try { try {
return PluginState.STOPPED; return PluginState.STOPPED;
} }


// test for disabled plugin
if (PluginState.DISABLED == pluginState) {
if (PluginState.DISABLED == pluginState ||
PluginState.CREATED == pluginState ||
PluginState.RESOLVED == pluginState) {

// do nothing // do nothing
return pluginState; return pluginState;
} }

+ 18
- 0
pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java View File



import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
assertFalse(pluginJar.file().exists()); assertFalse(pluginJar.file().exists());
} }


@Test
public void loadedPluginWithMissingDependencyCanBeUnloaded() throws IOException {
PluginZip pluginZip = new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.1.1.zip"), "myPlugin")
.pluginVersion("1.1.1")
.pluginDependencies("myBasePlugin")
.build();

pluginManager.loadPlugins();
pluginManager.startPlugins();

PluginWrapper myPlugin = pluginManager.getPlugin(pluginZip.pluginId());
assertNotNull(myPlugin);
assertNotEquals(PluginState.STARTED, myPlugin.getPluginState());

assertTrue(pluginManager.unloadPlugin(pluginZip.pluginId()));
}
} }

Loading…
Cancel
Save