提交 99875244 编写于 作者: S Stuart McCulloch 提交者: Kohsuke Kawaguchi

JENKINS-8897

上级 d4db356c
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
package hudson; package hudson;
import hudson.PluginWrapper.Dependency; import hudson.PluginWrapper.Dependency;
import hudson.model.Hudson;
import hudson.util.IOException2; import hudson.util.IOException2;
import hudson.util.MaskingClassLoader; import hudson.util.MaskingClassLoader;
import hudson.util.VersionNumber; import hudson.util.VersionNumber;
...@@ -47,6 +48,7 @@ import java.util.HashSet; ...@@ -47,6 +48,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.jar.Manifest; import java.util.jar.Manifest;
import java.util.jar.Attributes; import java.util.jar.Attributes;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
...@@ -256,6 +258,38 @@ public class ClassicPluginStrategy implements PluginStrategy { ...@@ -256,6 +258,38 @@ public class ClassicPluginStrategy implements PluginStrategy {
public void initializeComponents(PluginWrapper plugin) { public void initializeComponents(PluginWrapper plugin) {
} }
public <T> List<ExtensionComponent<T>> findComponents(Class<T> type, Hudson hudson) {
List<ExtensionFinder> finders;
if (type==ExtensionFinder.class) {
// Avoid infinite recursion of using ExtensionFinders to find ExtensionFinders
finders = Collections.<ExtensionFinder>singletonList(new ExtensionFinder.Sezpoz());
} else {
finders = hudson.getExtensionList(ExtensionFinder.class);
}
/**
* See {@link ExtensionFinder#scout(Class, Hudson)} for the dead lock issue and what this does.
*/
if (LOGGER.isLoggable(Level.FINER))
LOGGER.log(Level.FINER,"Scout-loading ExtensionList: "+type, new Throwable());
for (ExtensionFinder finder : finders) {
finder.scout(type, hudson);
}
List<ExtensionComponent<T>> r = new ArrayList<ExtensionComponent<T>>();
for (ExtensionFinder finder : finders) {
try {
r.addAll(finder._find(type, hudson));
} catch (AbstractMethodError e) {
// backward compatibility
for (T t : finder.findExtensions(type, hudson))
r.add(new ExtensionComponent<T>(t));
}
}
return r;
}
public void load(PluginWrapper wrapper) throws IOException { public void load(PluginWrapper wrapper) throws IOException {
// 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
......
...@@ -141,11 +141,6 @@ public class DescriptorExtensionList<T extends Describable<T>, D extends Descrip ...@@ -141,11 +141,6 @@ public class DescriptorExtensionList<T extends Describable<T>, D extends Descrip
return this; return this;
} }
@Override
protected void scoutLoad() {
// no-op, since our load() doesn't by itself do any classloading
}
/** /**
* Loading the descriptors in this case means filtering the descriptor from the master {@link ExtensionList}. * Loading the descriptors in this case means filtering the descriptor from the master {@link ExtensionList}.
*/ */
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
*/ */
package hudson; package hudson;
import hudson.ExtensionFinder.Sezpoz;
import hudson.init.InitMilestone; import hudson.init.InitMilestone;
import hudson.model.Hudson; import hudson.model.Hudson;
import hudson.util.AdaptedIterator; import hudson.util.AdaptedIterator;
...@@ -31,6 +30,7 @@ import hudson.util.DescriptorList; ...@@ -31,6 +30,7 @@ import hudson.util.DescriptorList;
import hudson.util.Memoizer; import hudson.util.Memoizer;
import hudson.util.Iterators; import hudson.util.Iterators;
import hudson.ExtensionPoint.LegacyInstancesAreScopedToHudson; import hudson.ExtensionPoint.LegacyInstancesAreScopedToHudson;
import hudson.PluginStrategy;
import java.util.AbstractList; import java.util.AbstractList;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -197,22 +197,12 @@ public class ExtensionList<T> extends AbstractList<T> { ...@@ -197,22 +197,12 @@ public class ExtensionList<T> extends AbstractList<T> {
return null; return null;
} }
/**
* Returns {@link ExtensionFinder}s used to search for the extension instances.
*/
protected Iterable<? extends ExtensionFinder> finders() {
return hudson.getExtensionList(ExtensionFinder.class);
}
private List<ExtensionComponent<T>> ensureLoaded() { private List<ExtensionComponent<T>> ensureLoaded() {
if(extensions!=null) if(extensions!=null)
return extensions; // already loaded return extensions; // already loaded
if(Hudson.getInstance().getInitLevel().compareTo(InitMilestone.PLUGINS_PREPARED)<0) if(Hudson.getInstance().getInitLevel().compareTo(InitMilestone.PLUGINS_PREPARED)<0)
return legacyInstances; // can't perform the auto discovery until all plugins are loaded, so just make the legacy instances visible return legacyInstances; // can't perform the auto discovery until all plugins are loaded, so just make the legacy instances visible
scoutLoad();
synchronized (getLoadLock()) { synchronized (getLoadLock()) {
if(extensions==null) { if(extensions==null) {
List<ExtensionComponent<T>> r = load(); List<ExtensionComponent<T>> r = load();
...@@ -237,17 +227,6 @@ public class ExtensionList<T> extends AbstractList<T> { ...@@ -237,17 +227,6 @@ public class ExtensionList<T> extends AbstractList<T> {
*/ */
private static final class Lock {} private static final class Lock {}
/**
* See {@link ExtensionFinder#scout(Class, Hudson)} for the dead lock issue and what this does.
*/
protected void scoutLoad() {
if (LOGGER.isLoggable(Level.FINER))
LOGGER.log(Level.FINER,"Scout-loading ExtensionList: "+extensionType, new Throwable());
for (ExtensionFinder finder : finders()) {
finder.scout(extensionType, hudson);
}
}
/** /**
* Loads all the extensions. * Loads all the extensions.
*/ */
...@@ -255,17 +234,7 @@ public class ExtensionList<T> extends AbstractList<T> { ...@@ -255,17 +234,7 @@ public class ExtensionList<T> extends AbstractList<T> {
if (LOGGER.isLoggable(Level.FINE)) if (LOGGER.isLoggable(Level.FINE))
LOGGER.log(Level.FINE,"Loading ExtensionList: "+extensionType, new Throwable()); LOGGER.log(Level.FINE,"Loading ExtensionList: "+extensionType, new Throwable());
List<ExtensionComponent<T>> r = new ArrayList<ExtensionComponent<T>>(); return hudson.getPluginManager().getPluginStrategy().findComponents(extensionType, hudson);
for (ExtensionFinder finder : finders()) {
try {
r.addAll(finder._find(extensionType, hudson));
} catch (AbstractMethodError e) {
// backward compatibility
for (T t : finder.findExtensions(extensionType, hudson))
r.add(new ExtensionComponent<T>(t));
}
}
return r;
} }
/** /**
...@@ -282,19 +251,6 @@ public class ExtensionList<T> extends AbstractList<T> { ...@@ -282,19 +251,6 @@ public class ExtensionList<T> extends AbstractList<T> {
} }
public static <T> ExtensionList<T> create(Hudson hudson, Class<T> type) { public static <T> ExtensionList<T> create(Hudson hudson, Class<T> type) {
if(type==ExtensionFinder.class)
return new ExtensionList<T>(hudson,type) {
Set<Sezpoz> finders = Collections.singleton(new Sezpoz());
/**
* If this ExtensionList is searching for ExtensionFinders, calling hudson.getExtensionList
* results in infinite recursion.
*/
@Override
protected Iterable<? extends ExtensionFinder> finders() {
return finders;
}
};
if(type.getAnnotation(LegacyInstancesAreScopedToHudson.class)!=null) if(type.getAnnotation(LegacyInstancesAreScopedToHudson.class)!=null)
return new ExtensionList<T>(hudson,type); return new ExtensionList<T>(hudson,type);
else { else {
......
...@@ -23,8 +23,11 @@ ...@@ -23,8 +23,11 @@
*/ */
package hudson; package hudson;
import hudson.model.Hudson;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List;
/** /**
* Pluggability point for how to create {@link PluginWrapper}. * Pluggability point for how to create {@link PluginWrapper}.
...@@ -63,4 +66,13 @@ public interface PluginStrategy extends ExtensionPoint { ...@@ -63,4 +66,13 @@ public interface PluginStrategy extends ExtensionPoint {
*/ */
public abstract void initializeComponents(PluginWrapper plugin); public abstract void initializeComponents(PluginWrapper plugin);
} /**
\ No newline at end of file * Find components of the given type using the assigned strategy.
*
* @param type The component type
* @param hudson The Hudson scope
* @return Sequence of components
* @since 1.400
*/
public abstract <T> List<ExtensionComponent<T>> findComponents(Class<T> type, Hudson hudson);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册