Browse Source

Failed plugin state added. When plugin failed to start previous state was kept (#364)

pull/366/head
radeklos 5 years ago committed by GitHub
parent
commit
ed1f7fde6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
  2. 7
      pf4j/src/main/java/org/pf4j/PluginState.java
  3. 14
      pf4j/src/main/java/org/pf4j/PluginWrapper.java

7
pf4j/src/main/java/org/pf4j/AbstractPluginManager.java

@ -330,11 +330,14 @@ public abstract class AbstractPluginManager implements PluginManager {
log.info("Start plugin '{}'", getPluginLabel(pluginWrapper.getDescriptor()));
pluginWrapper.getPlugin().start();
pluginWrapper.setPluginState(PluginState.STARTED);
pluginWrapper.setFailedException(null);
startedPlugins.add(pluginWrapper);
firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, pluginState));
} catch (Exception e) {
pluginWrapper.setPluginState(PluginState.FAILED);
pluginWrapper.setFailedException(e);
log.error(e.getMessage(), e);
} finally {
firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, pluginState));
}
}
}

7
pf4j/src/main/java/org/pf4j/PluginState.java

@ -44,7 +44,12 @@ public enum PluginState {
/**
* The {@link Plugin#stop()} has executed.
*/
STOPPED("STOPPED");
STOPPED("STOPPED"),
/**
* Plugin failed to start.
*/
FAILED("FAILED");
private String status;

14
pf4j/src/main/java/org/pf4j/PluginWrapper.java

@ -32,6 +32,8 @@ public class PluginWrapper {
private PluginState pluginState;
private RuntimeMode runtimeMode;
private Exception failedException;
Plugin plugin; // cache
public PluginWrapper(PluginManager pluginManager, PluginDescriptor descriptor, Path pluginPath, ClassLoader pluginClassLoader) {
@ -139,4 +141,16 @@ public class PluginWrapper {
this.pluginFactory = pluginFactory;
}
/**
* Returns the exception with which the plugin fails to start.
* See @{link PluginStatus#FAILED}.
*/
public Exception getFailedException() {
return failedException;
}
public void setFailedException(Exception failedException) {
this.failedException = failedException;
}
}

Loading…
Cancel
Save