提交 e78b8a26 编写于 作者: K Kohsuke Kawaguchi

ExtensionList and its subtypes need to be able to pick up delta components...

ExtensionList and its subtypes need to be able to pick up delta components that are discovered and mix them with what it already knows
上级 82ef72c0
......@@ -26,6 +26,7 @@ package hudson;
import hudson.model.Descriptor;
import hudson.model.Describable;
import hudson.model.Hudson;
import jenkins.ExtensionComponentSet;
import jenkins.model.Jenkins;
import hudson.model.ViewDescriptor;
import hudson.model.Descriptor.FormException;
......@@ -36,6 +37,7 @@ import hudson.slaves.NodeDescriptor;
import hudson.tasks.Publisher;
import hudson.tasks.Publisher.DescriptorExtensionListImpl;
import java.util.Collection;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
......@@ -177,8 +179,17 @@ public class DescriptorExtensionList<T extends Describable<T>, D extends Descrip
*/
@Override
protected List<ExtensionComponent<D>> load() {
return _load(jenkins.getExtensionList(Descriptor.class).getComponents());
}
@Override
protected Collection<ExtensionComponent<D>> load(ExtensionComponentSet delta) {
return _load(delta.find(Descriptor.class));
}
private List<ExtensionComponent<D>> _load(Iterable<ExtensionComponent<Descriptor>> set) {
List<ExtensionComponent<D>> r = new ArrayList<ExtensionComponent<D>>();
for( ExtensionComponent<Descriptor> c : hudson.getExtensionList(Descriptor.class).getComponents() ) {
for( ExtensionComponent<Descriptor> c : set ) {
Descriptor d = c.getInstance();
try {
if(d.getT()==describableType)
......
......@@ -23,8 +23,10 @@
*/
package hudson;
import com.google.common.collect.Lists;
import hudson.init.InitMilestone;
import hudson.model.Hudson;
import jenkins.ExtensionComponentSet;
import jenkins.model.Jenkins;
import hudson.util.AdaptedIterator;
import hudson.util.DescriptorList;
......@@ -241,6 +243,21 @@ public class ExtensionList<T> extends AbstractList<T> {
return jenkins.lookup.setIfNull(Lock.class,new Lock());
}
/**
* Used during {@link Jenkins#refreshExtensions()} to add new components into existing {@link ExtensionList}s.
* Do not call from anywhere else.
*/
public void refresh(ExtensionComponentSet delta) {
synchronized (getLoadLock()) {
if (extensions==null)
return; // not yet loaded. when we load it, we'll load everything visible by then, so no work needed
List<ExtensionComponent<T>> l = Lists.newArrayList(extensions);
l.addAll(load(delta));
extensions = sort(l);
}
}
/**
* Loading an {@link ExtensionList} can result in a nested loading of another {@link ExtensionList}.
* What that means is that we need a single lock that spans across all the {@link ExtensionList}s,
......@@ -258,6 +275,14 @@ public class ExtensionList<T> extends AbstractList<T> {
return jenkins.getPluginManager().getPluginStrategy().findComponents(extensionType, hudson);
}
/**
* Picks up extensions that we care from the given list.
*/
protected Collection<ExtensionComponent<T>> load(ExtensionComponentSet delta) {
return delta.find(extensionType);
}
/**
* If the {@link ExtensionList} implementation requires sorting extensions,
* override this method to do so.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册