|
|
|
@ -15,6 +15,10 @@
|
|
|
|
|
*/ |
|
|
|
|
package org.pf4j; |
|
|
|
|
|
|
|
|
|
import org.pf4j.util.StringUtils; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
import java.io.Closeable; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.nio.file.Files; |
|
|
|
@ -28,10 +32,6 @@ import java.util.List;
|
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
|
|
import org.pf4j.util.StringUtils; |
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This class implements the boilerplate plugin code that any {@link PluginManager} |
|
|
|
|
* implementation would have to support. |
|
|
|
@ -243,7 +243,7 @@ public abstract class AbstractPluginManager implements PluginManager {
|
|
|
|
|
return unloadPlugin(pluginId, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private boolean unloadPlugin(String pluginId, boolean unloadDependents) { |
|
|
|
|
protected boolean unloadPlugin(String pluginId, boolean unloadDependents) { |
|
|
|
|
try { |
|
|
|
|
if (unloadDependents) { |
|
|
|
|
List<String> dependents = dependencyResolver.getDependents(pluginId); |
|
|
|
@ -332,10 +332,10 @@ public abstract class AbstractPluginManager implements PluginManager {
|
|
|
|
|
pluginWrapper.setPluginState(PluginState.STARTED); |
|
|
|
|
pluginWrapper.setFailedException(null); |
|
|
|
|
startedPlugins.add(pluginWrapper); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
} catch (Exception | LinkageError e) { |
|
|
|
|
pluginWrapper.setPluginState(PluginState.FAILED); |
|
|
|
|
pluginWrapper.setFailedException(e); |
|
|
|
|
log.error(e.getMessage(), e); |
|
|
|
|
log.error("Unable to start plugin '{}'", getPluginLabel(pluginWrapper.getDescriptor()), e); |
|
|
|
|
} finally { |
|
|
|
|
firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, pluginState)); |
|
|
|
|
} |
|
|
|
@ -371,7 +371,10 @@ public abstract class AbstractPluginManager implements PluginManager {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (PluginDependency dependency : pluginDescriptor.getDependencies()) { |
|
|
|
|
startPlugin(dependency.getPluginId()); |
|
|
|
|
// start dependency only if it marked as required (non optional) or if it optional and loaded
|
|
|
|
|
if (!dependency.isOptional() || plugins.containsKey(dependency.getPluginId())) { |
|
|
|
|
startPlugin(dependency.getPluginId()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log.info("Start plugin '{}'", getPluginLabel(pluginDescriptor)); |
|
|
|
@ -418,7 +421,7 @@ public abstract class AbstractPluginManager implements PluginManager {
|
|
|
|
|
return stopPlugin(pluginId, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private PluginState stopPlugin(String pluginId, boolean stopDependents) { |
|
|
|
|
protected PluginState stopPlugin(String pluginId, boolean stopDependents) { |
|
|
|
|
checkPluginId(pluginId); |
|
|
|
|
|
|
|
|
|
PluginWrapper pluginWrapper = getPlugin(pluginId); |
|
|
|
@ -454,7 +457,7 @@ public abstract class AbstractPluginManager implements PluginManager {
|
|
|
|
|
return pluginWrapper.getPluginState(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void checkPluginId(String pluginId) { |
|
|
|
|
protected void checkPluginId(String pluginId) { |
|
|
|
|
if (!plugins.containsKey(pluginId)) { |
|
|
|
|
throw new IllegalArgumentException(String.format("Unknown pluginId %s", pluginId)); |
|
|
|
|
} |
|
|
|
@ -913,7 +916,7 @@ public abstract class AbstractPluginManager implements PluginManager {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
private <T> List<Class<? extends T>> getExtensionClasses(List<ExtensionWrapper<T>> extensionsWrapper) { |
|
|
|
|
protected <T> List<Class<? extends T>> getExtensionClasses(List<ExtensionWrapper<T>> extensionsWrapper) { |
|
|
|
|
List<Class<? extends T>> extensionClasses = new ArrayList<>(extensionsWrapper.size()); |
|
|
|
|
for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) { |
|
|
|
|
Class<T> c = (Class<T>) extensionWrapper.getDescriptor().extensionClass; |
|
|
|
@ -923,7 +926,7 @@ public abstract class AbstractPluginManager implements PluginManager {
|
|
|
|
|
return extensionClasses; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private <T> List<T> getExtensions(List<ExtensionWrapper<T>> extensionsWrapper) { |
|
|
|
|
protected <T> List<T> getExtensions(List<ExtensionWrapper<T>> extensionsWrapper) { |
|
|
|
|
List<T> extensions = new ArrayList<>(extensionsWrapper.size()); |
|
|
|
|
for (ExtensionWrapper<T> extensionWrapper : extensionsWrapper) { |
|
|
|
|
try { |
|
|
|
|