提交 4de81f1e 编写于 作者: K kohsuke

fixed a bug where XStream activity in plugins wasn't able to resolve classes.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@1131 71c3de6d-444a-0410-be80-ed276b4c234a
上级 54db1b53
......@@ -119,6 +119,16 @@ public final class PluginManager {
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
// first, use the context classloader so that plugins that are loading
// can use its own classloader first.
ClassLoader cl = Thread.currentThread().getContextClassLoader();
if(cl!=null)
try {
return cl.loadClass(name);
} catch(ClassNotFoundException e) {
// not found. try next
}
for (PluginWrapper p : activePlugins) {
try {
return p.classLoader.loadClass(name);
......
......@@ -171,37 +171,45 @@ public final class PluginWrapper {
throw new IOException("Plugin installation failed. No 'Plugin-Class' entry in the manifest of "+archive);
}
// 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();
Thread.currentThread().setContextClassLoader(classLoader);
try {
Class clazz = classLoader.loadClass(className);
Object plugin = clazz.newInstance();
if(!(plugin instanceof Plugin)) {
throw new IOException(className+" doesn't extend from hudson.Plugin");
try {
Class clazz = classLoader.loadClass(className);
Object plugin = clazz.newInstance();
if(!(plugin instanceof Plugin)) {
throw new IOException(className+" doesn't extend from hudson.Plugin");
}
this.plugin = (Plugin)plugin;
this.plugin.wrapper = this;
} catch (ClassNotFoundException e) {
IOException ioe = new IOException("Unable to load " + className + " from " + archive);
ioe.initCause(e);
throw ioe;
} catch (IllegalAccessException e) {
IOException ioe = new IOException("Unable to create instance of " + className + " from " + archive);
ioe.initCause(e);
throw ioe;
} catch (InstantiationException e) {
IOException ioe = new IOException("Unable to create instance of " + className + " from " + archive);
ioe.initCause(e);
throw ioe;
}
this.plugin = (Plugin)plugin;
this.plugin.wrapper = this;
} catch (ClassNotFoundException e) {
IOException ioe = new IOException("Unable to load " + className + " from " + archive);
ioe.initCause(e);
throw ioe;
} catch (IllegalAccessException e) {
IOException ioe = new IOException("Unable to create instance of " + className + " from " + archive);
ioe.initCause(e);
throw ioe;
} catch (InstantiationException e) {
IOException ioe = new IOException("Unable to create instance of " + className + " from " + archive);
ioe.initCause(e);
throw ioe;
}
// initialize plugin
try {
plugin.setServletContext(owner.context);
plugin.start();
} catch(Throwable t) {
// gracefully handle any error in plugin.
IOException ioe = new IOException("Failed to initialize");
ioe.initCause(t);
throw ioe;
// initialize plugin
try {
plugin.setServletContext(owner.context);
plugin.start();
} catch(Throwable t) {
// gracefully handle any error in plugin.
IOException ioe = new IOException("Failed to initialize");
ioe.initCause(t);
throw ioe;
}
} finally {
Thread.currentThread().setContextClassLoader(old);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册