提交 3e842b69 编写于 作者: K Kohsuke Kawaguchi

More symbol assignments and constructor diet

to move more properties off to setters.
上级 16c4b50f
...@@ -67,6 +67,7 @@ import jenkins.slaves.WorkspaceLocator; ...@@ -67,6 +67,7 @@ import jenkins.slaves.WorkspaceLocator;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.HttpResponse; import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerRequest;
...@@ -98,7 +99,7 @@ public abstract class Slave extends Node implements Serializable { ...@@ -98,7 +99,7 @@ public abstract class Slave extends Node implements Serializable {
/** /**
* Description of this node. * Description of this node.
*/ */
private final String description; private String description;
/** /**
* Path to the root of the workspace from the view point of this node, such as "/hudson", this need not * Path to the root of the workspace from the view point of this node, such as "/hudson", this need not
...@@ -118,7 +119,7 @@ public abstract class Slave extends Node implements Serializable { ...@@ -118,7 +119,7 @@ public abstract class Slave extends Node implements Serializable {
/** /**
* Job allocation strategy. * Job allocation strategy.
*/ */
private Mode mode; private Mode mode = Mode.NORMAL;
/** /**
* Agent availablility strategy. * Agent availablility strategy.
...@@ -162,6 +163,16 @@ public abstract class Slave extends Node implements Serializable { ...@@ -162,6 +163,16 @@ public abstract class Slave extends Node implements Serializable {
this(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, new ArrayList()); this(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, new ArrayList());
} }
public Slave(@Nonnull String name, String remoteFS, ComputerLauncher launcher) throws FormException, IOException {
this.name = name;
this.remoteFS = remoteFS;
this.launcher = launcher;
}
/**
* @deprecated as of 1.XXX
* Use {@link #Slave(String, String, ComputerLauncher)} and set the rest through setters.
*/
public Slave(@Nonnull String name, String nodeDescription, String remoteFS, int numExecutors, public Slave(@Nonnull String name, String nodeDescription, String remoteFS, int numExecutors,
Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties) throws FormException, IOException { Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties) throws FormException, IOException {
this.name = name; this.name = name;
...@@ -231,6 +242,11 @@ public abstract class Slave extends Node implements Serializable { ...@@ -231,6 +242,11 @@ public abstract class Slave extends Node implements Serializable {
this.name = name; this.name = name;
} }
@DataBoundSetter
public void setNodeDescription(String value) {
this.description = value;
}
public String getNodeDescription() { public String getNodeDescription() {
return description; return description;
} }
...@@ -239,10 +255,16 @@ public abstract class Slave extends Node implements Serializable { ...@@ -239,10 +255,16 @@ public abstract class Slave extends Node implements Serializable {
return numExecutors; return numExecutors;
} }
@DataBoundSetter
public void setNumExecutors(int n) {
this.numExecutors = n;
}
public Mode getMode() { public Mode getMode() {
return mode; return mode;
} }
@DataBoundSetter
public void setMode(Mode mode) { public void setMode(Mode mode) {
this.mode = mode; this.mode = mode;
} }
...@@ -252,10 +274,16 @@ public abstract class Slave extends Node implements Serializable { ...@@ -252,10 +274,16 @@ public abstract class Slave extends Node implements Serializable {
return nodeProperties; return nodeProperties;
} }
@DataBoundSetter
public void setNodeProperties(List<? extends NodeProperty<?>> properties) throws IOException {
nodeProperties.replaceBy(properties);
}
public RetentionStrategy getRetentionStrategy() { public RetentionStrategy getRetentionStrategy() {
return retentionStrategy == null ? RetentionStrategy.Always.INSTANCE : retentionStrategy; return retentionStrategy == null ? RetentionStrategy.Always.INSTANCE : retentionStrategy;
} }
@DataBoundSetter
public void setRetentionStrategy(RetentionStrategy availabilityStrategy) { public void setRetentionStrategy(RetentionStrategy availabilityStrategy) {
this.retentionStrategy = availabilityStrategy; this.retentionStrategy = availabilityStrategy;
} }
...@@ -265,6 +293,7 @@ public abstract class Slave extends Node implements Serializable { ...@@ -265,6 +293,7 @@ public abstract class Slave extends Node implements Serializable {
} }
@Override @Override
@DataBoundSetter
public void setLabelString(String labelString) throws IOException { public void setLabelString(String labelString) throws IOException {
this.label = Util.fixNull(labelString).trim(); this.label = Util.fixNull(labelString).trim();
// Compute labels now. // Compute labels now.
......
...@@ -42,6 +42,7 @@ import java.util.logging.Level; ...@@ -42,6 +42,7 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter; import org.kohsuke.stapler.QueryParameter;
...@@ -182,7 +183,7 @@ public class CommandLauncher extends ComputerLauncher { ...@@ -182,7 +183,7 @@ public class CommandLauncher extends ComputerLauncher {
private static final Logger LOGGER = Logger.getLogger(CommandLauncher.class.getName()); private static final Logger LOGGER = Logger.getLogger(CommandLauncher.class.getName());
@Extension @Extension @Symbol("command")
public static class DescriptorImpl extends Descriptor<ComputerLauncher> { public static class DescriptorImpl extends Descriptor<ComputerLauncher> {
public String getDisplayName() { public String getDisplayName() {
return Messages.CommandLauncher_displayName(); return Messages.CommandLauncher_displayName();
......
...@@ -31,8 +31,11 @@ import java.io.IOException; ...@@ -31,8 +31,11 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundConstructor;
import javax.annotation.Nonnull;
/** /**
* Default {@link Slave} implementation for computers that do not belong to a higher level structure, * Default {@link Slave} implementation for computers that do not belong to a higher level structure,
* like grid or cloud. * like grid or cloud.
...@@ -49,12 +52,21 @@ public final class DumbSlave extends Slave { ...@@ -49,12 +52,21 @@ public final class DumbSlave extends Slave {
this(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, new ArrayList()); this(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, new ArrayList());
} }
@DataBoundConstructor /**
* @deprecated as of 1.XXX.
* Use {@link #DumbSlave(String, String, ComputerLauncher)} and configure the rest through setters.
*/
public DumbSlave(String name, String nodeDescription, String remoteFS, String numExecutors, Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties) throws IOException, FormException { public DumbSlave(String name, String nodeDescription, String remoteFS, String numExecutors, Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy retentionStrategy, List<? extends NodeProperty<?>> nodeProperties) throws IOException, FormException {
super(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, nodeProperties); super(name, nodeDescription, remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, nodeProperties);
} }
@Extension @DataBoundConstructor
public DumbSlave(@Nonnull String name, String remoteFS, ComputerLauncher launcher) throws FormException, IOException {
super(name, remoteFS, launcher);
}
@Extension @Symbol({"dumb",
"slave"/*because this is in effect the canonical slave type*/})
public static final class DescriptorImpl extends SlaveDescriptor { public static final class DescriptorImpl extends SlaveDescriptor {
public String getDisplayName() { public String getDisplayName() {
return Messages.DumbSlave_displayName(); return Messages.DumbSlave_displayName();
......
...@@ -27,6 +27,8 @@ import hudson.model.Descriptor; ...@@ -27,6 +27,8 @@ import hudson.model.Descriptor;
import hudson.model.TaskListener; import hudson.model.TaskListener;
import hudson.Util; import hudson.Util;
import hudson.Extension; import hudson.Extension;
import jenkins.model.Jenkins;
import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundConstructor;
/** /**
...@@ -75,8 +77,18 @@ public class JNLPLauncher extends ComputerLauncher { ...@@ -75,8 +77,18 @@ public class JNLPLauncher extends ComputerLauncher {
// do nothing as we cannot self start // do nothing as we cannot self start
} }
@Extension /**
public static final Descriptor<ComputerLauncher> DESCRIPTOR = new Descriptor<ComputerLauncher>() { * @deprecated as of 1.XXX
* Use {@link Jenkins#getDescriptor(Class)}
*/
public static /*almost final*/ Descriptor<ComputerLauncher> DESCRIPTOR;
@Extension @Symbol("jnlp")
public static class DescriptorImpl extends Descriptor<ComputerLauncher> {
public DescriptorImpl() {
DESCRIPTOR = this;
}
public String getDisplayName() { public String getDisplayName() {
return Messages.JNLPLauncher_displayName(); return Messages.JNLPLauncher_displayName();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册