提交 b5733d63 编写于 作者: K kohsuke

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
上级 7ef53f94
...@@ -80,6 +80,16 @@ public final class PluginManager { ...@@ -80,6 +80,16 @@ public final class PluginManager {
LOGGER.log(Level.SEVERE, "Failed to load a plug-in " + arc, e); 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<PluginWrapper> getPlugins() { public List<PluginWrapper> getPlugins() {
......
...@@ -56,7 +56,7 @@ public final class PluginWrapper { ...@@ -56,7 +56,7 @@ public final class PluginWrapper {
* Loaded plugin instance. * Loaded plugin instance.
* Null if disabled. * Null if disabled.
*/ */
public final Plugin plugin; private Plugin plugin;
/** /**
* {@link ClassLoader} for loading classes from this plugin. * {@link ClassLoader} for loading classes from this plugin.
...@@ -82,6 +82,27 @@ public final class PluginWrapper { ...@@ -82,6 +82,27 @@ public final class PluginWrapper {
*/ */
private final String shortName; private final String shortName;
/**
* True if this plugin is activated for this session.
* The snapshot of <tt>disableFile.exists()</tt> as of the start up.
*/
private final boolean active;
private final File archive;
private final List<Dependency> dependencies = new ArrayList<Dependency>();
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 * @param archive
* A .hpi archive file jar file, or a .hpl linked plugin. * A .hpi archive file jar file, or a .hpl linked plugin.
...@@ -92,6 +113,7 @@ public final class PluginWrapper { ...@@ -92,6 +113,7 @@ public final class PluginWrapper {
*/ */
public PluginWrapper(PluginManager owner, File archive) throws IOException { public PluginWrapper(PluginManager owner, File archive) throws IOException {
LOGGER.info("Loading plugin: "+archive); LOGGER.info("Loading plugin: "+archive);
this.archive = archive;
this.shortName = getShortName(archive); this.shortName = getShortName(archive);
...@@ -161,15 +183,33 @@ public final class PluginWrapper { ...@@ -161,15 +183,33 @@ public final class PluginWrapper {
disableFile = new File(archive.getPath()+".disabled"); disableFile = new File(archive.getPath()+".disabled");
if(disableFile.exists()) { if(disableFile.exists()) {
LOGGER.info("Plugin is disabled"); LOGGER.info("Plugin is disabled");
this.plugin = null; this.active = false;
return; } 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.
*
* <p>
* 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"); String className = manifest.getMainAttributes().getValue("Plugin-Class");
if(className ==null) { if(className ==null) {
throw new IOException("Plugin installation failed. No 'Plugin-Class' entry in the manifest of "+archive); 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() // override the context classloader so that XStream activity in plugin.start()
// will be able to resolve classes in this plugin // will be able to resolve classes in this plugin
ClassLoader old = Thread.currentThread().getContextClassLoader(); ClassLoader old = Thread.currentThread().getContextClassLoader();
...@@ -248,6 +288,13 @@ public final class PluginWrapper { ...@@ -248,6 +288,13 @@ public final class PluginWrapper {
return shortName; return shortName;
} }
/**
* Gets the instance of {@link Plugin} contributed by this plugin.
*/
public Plugin getPlugin() {
return plugin;
}
@Override @Override
public String toString() { public String toString() {
return "Plugin:" + getShortName(); return "Plugin:" + getShortName();
...@@ -321,7 +368,7 @@ public final class PluginWrapper { ...@@ -321,7 +368,7 @@ public final class PluginWrapper {
* Returns true if this plugin is enabled for this session. * Returns true if this plugin is enabled for this session.
*/ */
public boolean isActive() { public boolean isActive() {
return plugin!=null; return active;
} }
/** /**
......
...@@ -309,7 +309,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node ...@@ -309,7 +309,7 @@ public final class Hudson extends View implements ItemGroup<TopLevelItem>, Node
public Plugin getPlugin(String shortName) { public Plugin getPlugin(String shortName) {
PluginWrapper p = pluginManager.getPlugin(shortName); PluginWrapper p = pluginManager.getPlugin(shortName);
if(p==null) return null; if(p==null) return null;
return p.plugin; return p.getPlugin();
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册