From 1dec420e91bd45970fe6ab2f23fafa0010cd10d7 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Tue, 24 Feb 2009 19:17:29 +0000 Subject: [PATCH] updated Node to support auto-discovery git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15665 71c3de6d-444a-0410-be80-ed276b4c234a --- .../java/hudson/DescriptorExtensionList.java | 17 ++++++++++------- .../main/java/hudson/model/ComputerSet.java | 4 ++-- core/src/main/java/hudson/model/Slave.java | 5 +++-- .../src/main/java/hudson/slaves/DumbSlave.java | 13 ++----------- .../java/hudson/slaves/NodeDescriptor.java | 18 +++++++++++++----- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/hudson/DescriptorExtensionList.java b/core/src/main/java/hudson/DescriptorExtensionList.java index 508481c1a8..1e2c3eb8c1 100644 --- a/core/src/main/java/hudson/DescriptorExtensionList.java +++ b/core/src/main/java/hudson/DescriptorExtensionList.java @@ -56,6 +56,16 @@ public final class DescriptorExtensionList> extends Ext this.describableType = describableType; } + /** + * Finds the descriptor that has the matching fully-qualified class name. + * + * @param fqcn + * Fully qualified name of the descriptor, not the describable. + */ + public Descriptor find(String fqcn) { + return Descriptor.find(this,fqcn); + } + /** * Loading the descriptors in this case means filtering the descriptor from the master {@link ExtensionList}. */ @@ -74,13 +84,6 @@ public final class DescriptorExtensionList> extends Ext return r; } - /** - * Obtain the statically-scoped storage to store manulaly registered {@link Descriptor}s. - */ - private static List allocateLegacyInstanceStore(Class describableType) { - return legacyDescriptors.get(describableType); - } - /** * Stores manually registered Descriptor instances. */ diff --git a/core/src/main/java/hudson/model/ComputerSet.java b/core/src/main/java/hudson/model/ComputerSet.java index bfd7f35ab2..91c8482c16 100644 --- a/core/src/main/java/hudson/model/ComputerSet.java +++ b/core/src/main/java/hudson/model/ComputerSet.java @@ -194,7 +194,7 @@ public final class ComputerSet extends AbstractModelObject { return; } - req.setAttribute("descriptor", NodeDescriptor.ALL.find(mode)); + req.setAttribute("descriptor", NodeDescriptor.all().find(mode)); req.getView(this,"_new.jelly").forward(req,rsp); } } @@ -211,7 +211,7 @@ public final class ComputerSet extends AbstractModelObject { if (checkName(req, rsp, name)) return; - Node result = NodeDescriptor.ALL.find(type).newInstance(req, req.getSubmittedForm()); + Node result = NodeDescriptor.all().find(type).newInstance(req, req.getSubmittedForm()); app.addNode(result); // take the user back to the slave list top page diff --git a/core/src/main/java/hudson/model/Slave.java b/core/src/main/java/hudson/model/Slave.java index ee904fa870..a3795649fa 100644 --- a/core/src/main/java/hudson/model/Slave.java +++ b/core/src/main/java/hudson/model/Slave.java @@ -35,7 +35,6 @@ import hudson.slaves.ComputerLauncher; import hudson.slaves.DumbSlave; import hudson.slaves.JNLPLauncher; import hudson.slaves.NodeDescriptor; -import hudson.slaves.NodeProperties; import hudson.slaves.NodeProperty; import hudson.slaves.NodePropertyDescriptor; import hudson.slaves.RetentionStrategy; @@ -424,7 +423,9 @@ public abstract class Slave extends Node implements Serializable { return this; } - public abstract SlaveDescriptor getDescriptor(); + public SlaveDescriptor getDescriptor() { + return (SlaveDescriptor)Hudson.getInstance().getDescriptor(getClass()); + } public static abstract class SlaveDescriptor extends NodeDescriptor { public void doCheckNumExecutors() throws IOException, ServletException { diff --git a/core/src/main/java/hudson/slaves/DumbSlave.java b/core/src/main/java/hudson/slaves/DumbSlave.java index 53bbdd3bc2..5a2f875e36 100644 --- a/core/src/main/java/hudson/slaves/DumbSlave.java +++ b/core/src/main/java/hudson/slaves/DumbSlave.java @@ -25,6 +25,7 @@ package hudson.slaves; import hudson.model.Slave; import hudson.model.Descriptor.FormException; +import hudson.Extension; import java.io.IOException; import java.util.ArrayList; @@ -39,7 +40,6 @@ import org.kohsuke.stapler.DataBoundConstructor; * @author Kohsuke Kawaguchi */ public final class DumbSlave extends Slave { - @Deprecated public DumbSlave(String name, String nodeDescription, String remoteFS, String numExecutors, Mode mode, String label, ComputerLauncher launcher, RetentionStrategy retentionStrategy) throws FormException, IOException { this(name, nodeDescription, remoteFS, numExecutors, mode, label, launcher, retentionStrategy, new ArrayList()); @@ -50,19 +50,10 @@ public final class DumbSlave extends Slave { super(name, nodeDescription, remoteFS, numExecutors, mode, label, launcher, retentionStrategy, nodeProperties); } - public DescriptorImpl getDescriptor() { - return DescriptorImpl.INSTANCE; - } - + @Extension public static final class DescriptorImpl extends SlaveDescriptor { - public static final DescriptorImpl INSTANCE = new DescriptorImpl(); - public String getDisplayName() { return Messages.DumbSlave_displayName(); } } - - static { - NodeDescriptor.ALL.add(DescriptorImpl.INSTANCE); - } } diff --git a/core/src/main/java/hudson/slaves/NodeDescriptor.java b/core/src/main/java/hudson/slaves/NodeDescriptor.java index f397ed163e..0d73e427ad 100644 --- a/core/src/main/java/hudson/slaves/NodeDescriptor.java +++ b/core/src/main/java/hudson/slaves/NodeDescriptor.java @@ -26,7 +26,10 @@ package hudson.slaves; import hudson.model.Descriptor; import hudson.model.Slave; import hudson.model.Node; +import hudson.model.Hudson; import hudson.util.DescriptorList; +import hudson.Extension; +import hudson.DescriptorExtensionList; /** * {@link Descriptor} for {@link Slave}. @@ -58,11 +61,16 @@ public abstract class NodeDescriptor extends Descriptor { } /** - * All the registered instances. + * Returns all the registered {@link NodeDescriptor} descriptors. */ - public static final DescriptorList ALL = new DescriptorList(); - - static { - ALL.load(DumbSlave.class); + public static DescriptorExtensionList all() { + return Hudson.getInstance().getDescriptorList(Node.class); } + + /** + * All the registered instances. + * @deprecated as of 1.286 + * Use {@link #all()} for read access, and {@link Extension} for registration. + */ + public static final DescriptorList ALL = new DescriptorList(Node.class); } -- GitLab