diff --git a/core/src/main/java/hudson/Plugin.java b/core/src/main/java/hudson/Plugin.java index e80cb9644f..9e90602c29 100644 --- a/core/src/main/java/hudson/Plugin.java +++ b/core/src/main/java/hudson/Plugin.java @@ -105,17 +105,28 @@ public abstract class Plugin implements Saveable { * *

* If a plugin wants to run an initialization step after all plugins and extension points - * are registered, a good place to do that is {@link ItemListener#onLoaded()} + * are registered, a good place to do that is {@link #postInitialize()}. + * If a plugin wants to run an initialization step after all the jobs are loaded, + * {@link ItemListener#onLoaded()} is a good place. * * @throws Exception * any exception thrown by the plugin during the initialization will disable plugin. * * @since 1.42 * @see ExtensionPoint + * @see #postInitialize() */ public void start() throws Exception { } + /** + * Called after {@link #start()} is called for all the plugins. + * + * @throws Exception + * any exception thrown by the plugin during the initialization will disable plugin. + */ + public void postInitialize() throws Exception {} + /** * Called to orderly shut down Hudson. * diff --git a/core/src/main/java/hudson/PluginManager.java b/core/src/main/java/hudson/PluginManager.java index 2a1e272569..5340b1d4a1 100644 --- a/core/src/main/java/hudson/PluginManager.java +++ b/core/src/main/java/hudson/PluginManager.java @@ -161,6 +161,14 @@ public final class PluginManager extends AbstractModelObject { for (PluginWrapper p : activePlugins.toArray(new PluginWrapper[activePlugins.size()])) { strategy.initializeComponents(p); + try { + p.getPlugin().postInitialize(); + } catch (Exception e) { + failedPlugins.add(new FailedPlugin(p.getShortName(),e)); + LOGGER.log(Level.SEVERE, "Failed to post-initialize a plug-in " + p.getShortName(), e); + activePlugins.remove(p); + plugins.remove(p); + } } } @@ -440,9 +448,9 @@ public final class PluginManager extends AbstractModelObject { */ public static final class FailedPlugin { public final String name; - public final IOException cause; + public final Exception cause; - public FailedPlugin(String name, IOException cause) { + public FailedPlugin(String name, Exception cause) { this.name = name; this.cause = cause; }