From b5733d63be72bf2659b5a70deb5e7862fb12fe0d Mon Sep 17 00:00:00 2001 From: kohsuke Date: Sat, 3 Mar 2007 15:31:32 +0000 Subject: [PATCH] modified to parse "Plugin-Dependencies" manifest entry. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@2312 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/PluginManager.java | 10 ++++ core/src/main/java/hudson/PluginWrapper.java | 55 ++++++++++++++++++-- core/src/main/java/hudson/model/Hudson.java | 2 +- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/hudson/PluginManager.java b/core/src/main/java/hudson/PluginManager.java index fb427cbe1a..319c825a74 100644 --- a/core/src/main/java/hudson/PluginManager.java +++ b/core/src/main/java/hudson/PluginManager.java @@ -80,6 +80,16 @@ public final class PluginManager { LOGGER.log(Level.SEVERE, "Failed to load a plug-in " + arc, e); } } + + for (PluginWrapper p : activePlugins.toArray(new PluginWrapper[0])) + try { + p.load(this); + } catch (IOException e) { + failedPlugins.add(new FailedPlugin(p.getShortName(),e)); + LOGGER.log(Level.SEVERE, "Failed to load a plug-in " + p.getShortName(), e); + activePlugins.remove(p); + plugins.remove(p); + } } public List getPlugins() { diff --git a/core/src/main/java/hudson/PluginWrapper.java b/core/src/main/java/hudson/PluginWrapper.java index 83d136b63d..70c720fb80 100644 --- a/core/src/main/java/hudson/PluginWrapper.java +++ b/core/src/main/java/hudson/PluginWrapper.java @@ -56,7 +56,7 @@ public final class PluginWrapper { * Loaded plugin instance. * Null if disabled. */ - public final Plugin plugin; + private Plugin plugin; /** * {@link ClassLoader} for loading classes from this plugin. @@ -82,6 +82,27 @@ public final class PluginWrapper { */ private final String shortName; + /** + * True if this plugin is activated for this session. + * The snapshot of disableFile.exists() as of the start up. + */ + private final boolean active; + + private final File archive; + + private final List dependencies = new ArrayList(); + + private static final class Dependency { + public final String shortName; + public final String version; + + public Dependency(String s) { + int idx = s.indexOf(':'); + this.shortName = s.substring(0,idx); + this.version = s.substring(idx+1); + } + } + /** * @param archive * A .hpi archive file jar file, or a .hpl linked plugin. @@ -92,6 +113,7 @@ public final class PluginWrapper { */ public PluginWrapper(PluginManager owner, File archive) throws IOException { LOGGER.info("Loading plugin: "+archive); + this.archive = archive; this.shortName = getShortName(archive); @@ -161,15 +183,33 @@ public final class PluginWrapper { disableFile = new File(archive.getPath()+".disabled"); if(disableFile.exists()) { LOGGER.info("Plugin is disabled"); - this.plugin = null; - return; + this.active = false; + } else { + this.active = true; } + // compute dependencies + String v = Util.fixNull(manifest.getMainAttributes().getValue("Plugin-Dependencies")); + for(String s : v.split(",")) + dependencies.add(new Dependency(s)); + } + + /** + * Loads the plugin and starts it. + * + *

+ * This should be done after all the classloaders are constructed for + * all the plugins, so that dependencies can be properly loaded by plugins. + */ + /*package*/ void load(PluginManager owner) throws IOException { String className = manifest.getMainAttributes().getValue("Plugin-Class"); if(className ==null) { throw new IOException("Plugin installation failed. No 'Plugin-Class' entry in the manifest of "+archive); } + if(!active) + return; + // override the context classloader so that XStream activity in plugin.start() // will be able to resolve classes in this plugin ClassLoader old = Thread.currentThread().getContextClassLoader(); @@ -248,6 +288,13 @@ public final class PluginWrapper { return shortName; } + /** + * Gets the instance of {@link Plugin} contributed by this plugin. + */ + public Plugin getPlugin() { + return plugin; + } + @Override public String toString() { return "Plugin:" + getShortName(); @@ -321,7 +368,7 @@ public final class PluginWrapper { * Returns true if this plugin is enabled for this session. */ public boolean isActive() { - return plugin!=null; + return active; } /** diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index f19afd8060..2382dc0bff 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -309,7 +309,7 @@ public final class Hudson extends View implements ItemGroup, Node public Plugin getPlugin(String shortName) { PluginWrapper p = pluginManager.getPlugin(shortName); if(p==null) return null; - return p.plugin; + return p.getPlugin(); } /** -- GitLab