提交 216073a5 编写于 作者: K Kohsuke Kawaguchi

Various bug fixes.

- init task needs to be filtered down to only include those that are newly added.
- newly added plugin needs to be a part of the 'plugins' field
上级 94faaf3f
......@@ -62,6 +62,7 @@ import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
......@@ -330,12 +331,13 @@ public abstract class PluginManager extends AbstractModelObject {
* TODO: revisit where/how to expose this. This is an experiment.
*/
public void dynamicLoad(File arc) throws Exception {
PluginWrapper p = strategy.createPluginWrapper(arc);
final PluginWrapper p = strategy.createPluginWrapper(arc);
if (getPlugin(p.getShortName())!=null)
throw new IllegalArgumentException("Dynamic reloading isn't possible");
// TODO: check cyclic dependency
plugins.add(p);
activePlugins.add(p);
try {
......@@ -350,11 +352,16 @@ public abstract class PluginManager extends AbstractModelObject {
throw e;
}
// run initializers
// TODO: need to ignore base types
// run initializers in the added plugin
Reactor r = new Reactor(InitMilestone.ordering());
r.addAll(new InitializerFinder(p.classLoader).discoverTasks(r));
r.addAll(new InitializerFinder(p.classLoader) {
@Override
protected boolean filter(Method e) {
return e.getDeclaringClass().getClassLoader()!=p.classLoader || super.filter(e);
}
}.discoverTasks(r));
new InitReactorRunner().run(r);
Jenkins.getInstance().refreshExtensions();
}
/**
......
......@@ -68,8 +68,7 @@ public class InitializerFinder extends TaskBuilder {
public Collection<Task> discoverTasks(Reactor session) throws IOException {
List<Task> result = new ArrayList<Task>();
for (Method e : Index.list(Initializer.class,cl,Method.class)) {
if (!discovered.add(e))
continue; // already reported once
if (filter(e)) continue; // already reported once
if (!Modifier.isStatic(e.getModifiers()))
throw new IOException(e+" is not a static method");
......@@ -82,6 +81,13 @@ public class InitializerFinder extends TaskBuilder {
return result;
}
/**
* Return true to ignore this method.
*/
protected boolean filter(Method e) {
return !discovered.add(e);
}
/**
* Obtains the display name of the given initialization task
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册