提交 bd8c2a1c 编写于 作者: K kohsuke

Converted ComputerLauncher to support auto-registration.

ExtensionList is modified to implement List (with the add() method for legacy support) for simplification.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15620 71c3de6d-444a-0410-be80-ed276b4c234a
上级 66519f5e
......@@ -26,7 +26,6 @@ package hudson;
import hudson.model.Hudson;
import hudson.util.DescriptorList;
import java.util.AbstractCollection;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Collections;
......@@ -56,7 +55,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
* @see Hudson#getExtensionList(Class)
* @see Hudson#getDescriptorList(Class)
*/
public class ExtensionList<T> extends AbstractCollection<T> {
public class ExtensionList<T> extends AbstractList<T> {
public final Hudson hudson;
public final Class<T> extensionType;
......@@ -70,44 +69,6 @@ public class ExtensionList<T> extends AbstractCollection<T> {
*/
private final List<T> legacyInstances;
/**
* View of the {@link ExtensionList} as a mutable list.
*
* <p>
* Read access on this instance will see the full list that {@link ExtensionList} has,
* and the write access will allow the legacy manual registrations.
*/
private final List<T> listView = new AbstractList<T>() {
@Override
public T get(int index) {
return ensureLoaded().get(index);
}
@Override
public int size() {
return ExtensionList.this.size();
}
@Override
public Iterator<T> iterator() {
return ExtensionList.this.iterator(); // performance optimization as this is a common path
}
@Override
public boolean add(T t) {
legacyInstances.add(t);
// if we've already filled extensions, add it
if(extensions!=null)
extensions.add(t);
return true;
}
@Override
public void add(int index, T element) {
add(element);
}
};
protected ExtensionList(Hudson hudson, Class<T> extensionType) {
this(hudson,extensionType,new Vector<T>());
}
......@@ -140,10 +101,34 @@ public class ExtensionList<T> extends AbstractCollection<T> {
return ensureLoaded().iterator();
}
public T get(int index) {
return ensureLoaded().get(index);
}
public int size() {
return ensureLoaded().size();
}
/**
* Write access will put the instance into a legacy store.
*
* @deprecated
* Prefer automatic registration.
*/
@Override
public boolean add(T t) {
legacyInstances.add(t);
// if we've already filled extensions, add it
if(extensions!=null)
extensions.add(t);
return true;
}
@Override
public void add(int index, T element) {
add(element);
}
/**
* Returns {@link ExtensionFinder}s used to search for the extension instances.
*/
......@@ -177,19 +162,6 @@ public class ExtensionList<T> extends AbstractCollection<T> {
return r;
}
/**
* Provides the {@link List} adapter for the extension list, in case
* the compatibility with older Hudson requires that there be a mutable list.
*
* <p>
* Read access to this list will see the same thing as {@link ExtensionList#iterator()},
* and write acecss will keep the objects in a separate list, so that they can be merged
* to the list of auto-disovered instances.
*/
public List<T> asList() {
return listView;
}
public static <T> ExtensionList<T> create(Hudson hudson, Class<T> type) {
if(type==ExtensionFinder.class)
return new ExtensionList<T>(hudson,type) {
......
......@@ -609,7 +609,7 @@ public class Functions {
}
public static List<Descriptor<ComputerLauncher>> getComputerLauncherDescriptors() {
return ComputerLauncher.LIST;
return Hudson.getInstance().getDescriptorList(ComputerLauncher.class);
}
public static List<Descriptor<RetentionStrategy<?>>> getRetentionStrategyDescriptors() {
......
......@@ -84,7 +84,6 @@ import hudson.slaves.NodeDescriptor;
import hudson.slaves.NodeProvisioner;
import hudson.tasks.BuildStep;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrappers;
import hudson.tasks.Builder;
import hudson.tasks.DynamicLabeler;
import hudson.tasks.LabelFinder;
......@@ -411,7 +410,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl
*
* @see AdministrativeMonitor
*/
public transient final List<AdministrativeMonitor> administrativeMonitors = getExtensionList(AdministrativeMonitor.class).asList();
public transient final List<AdministrativeMonitor> administrativeMonitors = getExtensionList(AdministrativeMonitor.class);
/*package*/ final CopyOnWriteArraySet<String> disabledAdministrativeMonitors = new CopyOnWriteArraySet<String>();
......
......@@ -35,6 +35,7 @@ import hudson.remoting.Channel;
import hudson.remoting.SocketInputStream;
import hudson.remoting.SocketOutputStream;
import hudson.remoting.Channel.Listener;
import hudson.Extension;
import jcifs.smb.SmbFile;
import jcifs.smb.SmbException;
import jcifs.smb.NtlmPasswordAuthentication;
......@@ -233,20 +234,14 @@ public class ManagedWindowsServiceLauncher extends ComputerLauncher {
}
}
public Descriptor<ComputerLauncher> getDescriptor() {
return DescriptorImpl.INSTANCE;
}
@Extension
public static class DescriptorImpl extends Descriptor<ComputerLauncher> {
public static final DescriptorImpl INSTANCE = new DescriptorImpl();
public String getDisplayName() {
return "Let Hudson control this Windows slave as a Windows service";
}
}
static {
LIST.add(DescriptorImpl.INSTANCE);
Logger.getLogger("org.jinterop").setLevel(Level.WARNING);
}
}
......@@ -25,6 +25,7 @@ package hudson.slaves;
import hudson.EnvVars;
import hudson.Util;
import hudson.Extension;
import hudson.model.Descriptor;
import hudson.remoting.Channel;
import hudson.util.FormFieldValidator;
......@@ -78,12 +79,6 @@ public class CommandLauncher extends ComputerLauncher {
return agentCommand;
}
public Descriptor<ComputerLauncher> getDescriptor() {
return DESCRIPTOR;
}
public static final Descriptor<ComputerLauncher> DESCRIPTOR = new DescriptorImpl();
/**
* Gets the formatted current time stamp.
*/
......@@ -155,10 +150,7 @@ public class CommandLauncher extends ComputerLauncher {
private static final Logger LOGGER = Logger.getLogger(CommandLauncher.class.getName());
static {
LIST.add(DESCRIPTOR);
}
@Extension
public static class DescriptorImpl extends Descriptor<ComputerLauncher> {
public String getDisplayName() {
return Messages.CommandLauncher_displayName();
......
......@@ -24,9 +24,11 @@
package hudson.slaves;
import hudson.ExtensionPoint;
import hudson.os.windows.ManagedWindowsServiceLauncher;
import hudson.Extension;
import hudson.model.Computer;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.remoting.Channel.Listener;
import hudson.util.DescriptorList;
import hudson.util.StreamTaskListener;
......@@ -97,14 +99,16 @@ public abstract class ComputerLauncher implements Describable<ComputerLauncher>,
public void beforeDisconnect(SlaveComputer computer, StreamTaskListener listener) {
}
public Descriptor<ComputerLauncher> getDescriptor() {
return (Descriptor<ComputerLauncher>)Hudson.getInstance().getDescriptor(getClass());
}
/**
* All registered {@link ComputerLauncher} implementations.
*
* @deprecated as of 1.281
* Use {@link Extension} for registration, and use
* {@link Hudson#getDescriptorList(Class)} for read access.
*/
public static final DescriptorList<ComputerLauncher> LIST = new DescriptorList<ComputerLauncher>();
static {
LIST.load(JNLPLauncher.class);
LIST.load(CommandLauncher.class);
LIST.load(ManagedWindowsServiceLauncher.class);
}
public static final DescriptorList<ComputerLauncher> LIST = new DescriptorList<ComputerLauncher>(ComputerLauncher.class);
}
......@@ -26,6 +26,7 @@ package hudson.slaves;
import hudson.model.Descriptor;
import hudson.util.StreamTaskListener;
import hudson.Util;
import hudson.Extension;
import org.kohsuke.stapler.DataBoundConstructor;
/**
......@@ -66,17 +67,11 @@ public class JNLPLauncher extends ComputerLauncher {
// do nothing as we cannot self start
}
public Descriptor<ComputerLauncher> getDescriptor() {
return DESCRIPTOR;
}
@Extension
public static final Descriptor<ComputerLauncher> DESCRIPTOR = new Descriptor<ComputerLauncher>() {
public String getDisplayName() {
return Messages.JNLPLauncher_displayName();
}
};
static {
LIST.add(DESCRIPTOR);
}
}
......@@ -137,7 +137,7 @@ public final class DescriptorList<T extends Describable<T>> extends AbstractList
if(type==null)
return legacy;
else
return Hudson.getInstance().getDescriptorList(type).asList();
return Hudson.getInstance().getDescriptorList(type);
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册