diff --git a/core/src/main/java/hudson/ExtensionList.java b/core/src/main/java/hudson/ExtensionList.java index 8c0a3ed8705cf35e63b52db3e8413e7f3db4215b..e781750d0c0060d3e7ccb5c5029f470144d2c58d 100644 --- a/core/src/main/java/hudson/ExtensionList.java +++ b/core/src/main/java/hudson/ExtensionList.java @@ -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 extends AbstractCollection { +public class ExtensionList extends AbstractList { public final Hudson hudson; public final Class extensionType; @@ -70,44 +69,6 @@ public class ExtensionList extends AbstractCollection { */ private final List legacyInstances; - /** - * View of the {@link ExtensionList} as a mutable list. - * - *

- * 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 listView = new AbstractList() { - @Override - public T get(int index) { - return ensureLoaded().get(index); - } - - @Override - public int size() { - return ExtensionList.this.size(); - } - - @Override - public Iterator 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 extensionType) { this(hudson,extensionType,new Vector()); } @@ -140,10 +101,34 @@ public class ExtensionList extends AbstractCollection { 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 extends AbstractCollection { 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. - * - *

- * 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 asList() { - return listView; - } - public static ExtensionList create(Hudson hudson, Class type) { if(type==ExtensionFinder.class) return new ExtensionList(hudson,type) { diff --git a/core/src/main/java/hudson/Functions.java b/core/src/main/java/hudson/Functions.java index 27b153a32300597af39de79b1ba95400cd3f54fd..f2ca211861dd41b51ee9e6f5f74db6ec69fd2e54 100644 --- a/core/src/main/java/hudson/Functions.java +++ b/core/src/main/java/hudson/Functions.java @@ -609,7 +609,7 @@ public class Functions { } public static List> getComputerLauncherDescriptors() { - return ComputerLauncher.LIST; + return Hudson.getInstance().getDescriptorList(ComputerLauncher.class); } public static List>> getRetentionStrategyDescriptors() { diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index 429933b09f08eda45d9e07cb834a47275828213f..e3668e09edc3b5949f4168f3a563827247377578 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -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, Stapl * * @see AdministrativeMonitor */ - public transient final List administrativeMonitors = getExtensionList(AdministrativeMonitor.class).asList(); + public transient final List administrativeMonitors = getExtensionList(AdministrativeMonitor.class); /*package*/ final CopyOnWriteArraySet disabledAdministrativeMonitors = new CopyOnWriteArraySet(); diff --git a/core/src/main/java/hudson/os/windows/ManagedWindowsServiceLauncher.java b/core/src/main/java/hudson/os/windows/ManagedWindowsServiceLauncher.java index 1f42856a31732f16d0222e2e895b1f3fad5c056d..e5ffc9e707664bf66a21b582566904053ee5ff75 100644 --- a/core/src/main/java/hudson/os/windows/ManagedWindowsServiceLauncher.java +++ b/core/src/main/java/hudson/os/windows/ManagedWindowsServiceLauncher.java @@ -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 getDescriptor() { - return DescriptorImpl.INSTANCE; - } - + @Extension public static class DescriptorImpl extends Descriptor { - 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); } } diff --git a/core/src/main/java/hudson/slaves/CommandLauncher.java b/core/src/main/java/hudson/slaves/CommandLauncher.java index f917c50ce6b5d6a8e43b34abab8e2845caf6d4e2..af445c3eb31e20936304cb6746d1abab1a3c2d8b 100644 --- a/core/src/main/java/hudson/slaves/CommandLauncher.java +++ b/core/src/main/java/hudson/slaves/CommandLauncher.java @@ -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 getDescriptor() { - return DESCRIPTOR; - } - - public static final Descriptor 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 { public String getDisplayName() { return Messages.CommandLauncher_displayName(); diff --git a/core/src/main/java/hudson/slaves/ComputerLauncher.java b/core/src/main/java/hudson/slaves/ComputerLauncher.java index 4a07a4b489be0ef860b8675b86d0dff720bd2c3f..406fe96a6ba4c06df1f977f4d1a1fb4482d4d63d 100644 --- a/core/src/main/java/hudson/slaves/ComputerLauncher.java +++ b/core/src/main/java/hudson/slaves/ComputerLauncher.java @@ -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, public void beforeDisconnect(SlaveComputer computer, StreamTaskListener listener) { } + public Descriptor getDescriptor() { + return (Descriptor)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 LIST = new DescriptorList(); - - static { - LIST.load(JNLPLauncher.class); - LIST.load(CommandLauncher.class); - LIST.load(ManagedWindowsServiceLauncher.class); - } + public static final DescriptorList LIST = new DescriptorList(ComputerLauncher.class); } diff --git a/core/src/main/java/hudson/slaves/JNLPLauncher.java b/core/src/main/java/hudson/slaves/JNLPLauncher.java index a7ab01fa4318c58f658f5d735540152db818bfe2..5926971d0d7afc1ec3649fdc679b23e31a24d21f 100644 --- a/core/src/main/java/hudson/slaves/JNLPLauncher.java +++ b/core/src/main/java/hudson/slaves/JNLPLauncher.java @@ -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 getDescriptor() { - return DESCRIPTOR; - } - + @Extension public static final Descriptor DESCRIPTOR = new Descriptor() { public String getDisplayName() { return Messages.JNLPLauncher_displayName(); } }; - static { - LIST.add(DESCRIPTOR); - } } diff --git a/core/src/main/java/hudson/util/DescriptorList.java b/core/src/main/java/hudson/util/DescriptorList.java index 3f7d84201f52ece38ad28c1219e221022e28f138..a04ba4dcccf7756139dcc569f0582d594c88793a 100644 --- a/core/src/main/java/hudson/util/DescriptorList.java +++ b/core/src/main/java/hudson/util/DescriptorList.java @@ -137,7 +137,7 @@ public final class DescriptorList> extends AbstractList if(type==null) return legacy; else - return Hudson.getInstance().getDescriptorList(type).asList(); + return Hudson.getInstance().getDescriptorList(type); } /**