Browse Source

unload broken plugins fix

pull/545/head
Finn Reißmann 8 months ago
parent
commit
e3ebefd23b
No account linked to committer's email address

+ 13
- 6
pf4j/src/main/java/org/pf4j/AbstractPluginManager.java View File

dependents.addAll(0, dependencyResolver.getDependents(dependent)); dependents.addAll(0, dependencyResolver.getDependents(dependent));
} }
} }
PluginWrapper pluginWrapper = getPlugin(pluginId);
PluginState pluginState;
try {
pluginState = stopPlugin(pluginId, false);
if (PluginState.STARTED == pluginState) {
return false;
}


PluginState pluginState = stopPlugin(pluginId, false);
if (PluginState.STARTED == pluginState) {
return false;
log.info("Unload plugin '{}'", getPluginLabel(pluginWrapper.getDescriptor()));
} catch (final Exception e) {
if (pluginWrapper == null) {
return false;
}
pluginState = PluginState.FAILED;
} }


PluginWrapper pluginWrapper = getPlugin(pluginId);
log.info("Unload plugin '{}'", getPluginLabel(pluginWrapper.getDescriptor()));

// remove the plugin // remove the plugin
plugins.remove(pluginId); plugins.remove(pluginId);
getResolvedPlugins().remove(pluginWrapper); getResolvedPlugins().remove(pluginWrapper);

+ 27
- 0
pf4j/src/test/java/org/pf4j/JarPluginManagerTest.java View File

package org.pf4j; package org.pf4j;


import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.api.io.TempDir;
import org.pf4j.test.TestPlugin; import org.pf4j.test.TestPlugin;


import java.io.IOException; import java.io.IOException;
import java.nio.file.FileSystemException;
import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;


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;
assertFalse(pluginJar.file().exists()); assertFalse(pluginJar.file().exists());
} }


@Test
public void releaseBrokenJar() throws IOException {
PluginJar pluginZip = new PluginJar.Builder(pluginsPath.resolve("test.jar"), "test")
.pluginVersion("1.2.3")
.pluginClass("invalidClass")
.build();

pluginManager.loadPlugins();
final Path pluginPath = pluginManager.getPlugin(pluginZip.pluginId()).getPluginPath();

try {
pluginManager.startPlugin(pluginZip.pluginId());
} catch (final Exception exceptionStartPlugin) {
Assertions.assertThrows(FileSystemException.class, () -> Files.delete(pluginPath));

// Try to remove the plugin if it cannot be started
try {
pluginManager.unloadPlugin(pluginZip.pluginId());
} catch (final Exception ignored2) {
}
Assertions.assertDoesNotThrow(() -> Files.delete(pluginPath));
}
}
} }

Loading…
Cancel
Save