]> source.dussan.org Git - pf4j.git/commitdiff
Failed plugin state added. When plugin failed to start previous state was kept (...
authorradeklos <radeklos@users.noreply.github.com>
Tue, 4 Feb 2020 18:04:02 +0000 (19:04 +0100)
committerGitHub <noreply@github.com>
Tue, 4 Feb 2020 18:04:02 +0000 (20:04 +0200)
pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
pf4j/src/main/java/org/pf4j/PluginState.java
pf4j/src/main/java/org/pf4j/PluginWrapper.java

index e69acd3be29213b1074d00a1ec8cb0cf1d434f56..d94b0c294f3c586173000f8d564ae192980b3668 100644 (file)
@@ -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));
                 }
             }
         }
index 7b5037a2eacd479aad6bcff0d106b6b15bb6bb90..e28fc308862df7680c6a791c76ba0c5b8f04ee5b 100644 (file)
@@ -24,12 +24,12 @@ public enum PluginState {
      * The runtime knows the plugin is there. It knows about the plugin path, the plugin descriptor.
      */
     CREATED("CREATED"),
-    
+
     /**
      * The plugin cannot be used.
      */
     DISABLED("DISABLED"),
-    
+
     /**
      * The plugin is created. All the dependencies are created and resolved.
      * The plugin is ready to be started.
@@ -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;
 
index 0af0d93f56ff856dd0fb27aa7177edc0397c1e7c..8e472f82678adb49abd96994e71a647d281f684f 100644 (file)
@@ -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;
+    }
+
 }