diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index 2fcc327bd300f5067e6742a67d97fb2f88087093..e126a00d545f8a88c2ccfce70b53ca4689e73870 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -1423,6 +1423,10 @@ public final class Hudson extends Node implements ItemGroup, Stapl return false; } + public FormValidation doCheckNumExecutors(@QueryParameter String value) { + return FormValidation.validateNonNegativeInteger(value); + } + // to route /descriptor/FQCN/xxx to getDescriptor(FQCN).xxx public Object getDynamic(String token) { return Hudson.getInstance().getDescriptor(token); diff --git a/core/src/main/java/hudson/model/Slave.java b/core/src/main/java/hudson/model/Slave.java index f563dde984d395070b285dd9fc56d024d2ec6b20..b50fa00f950255082ad875f1149009efd10b99ea 100644 --- a/core/src/main/java/hudson/model/Slave.java +++ b/core/src/main/java/hudson/model/Slave.java @@ -427,7 +427,7 @@ public abstract class Slave extends Node implements Serializable { public static abstract class SlaveDescriptor extends NodeDescriptor { public FormValidation doCheckNumExecutors(@QueryParameter String value) { - return FormValidation.validateNonNegativeInteger(value); + return FormValidation.validatePositiveInteger(value); } /** diff --git a/core/src/main/java/hudson/util/FormValidation.java b/core/src/main/java/hudson/util/FormValidation.java index c0bd3c4dc53c7eac4f826813d2aad4c9e81ebeae..1fdbd833c7d050fc62f8ae04eef0b3760122e8cc 100644 --- a/core/src/main/java/hudson/util/FormValidation.java +++ b/core/src/main/java/hudson/util/FormValidation.java @@ -299,6 +299,19 @@ public abstract class FormValidation extends IOException implements HttpResponse public static FormValidation validateNonNegativeInteger(String value) { try { if(Integer.parseInt(value)<0) + return error(hudson.model.Messages.Hudson_NotANonNegativeNumber()); + return ok(); + } catch (NumberFormatException e) { + return error(hudson.model.Messages.Hudson_NotANumber()); + } + } + + /** + * Makes sure that the given string is a positive integer. + */ + public static FormValidation validatePositiveInteger(String value) { + try { + if(Integer.parseInt(value)<=0) return error(hudson.model.Messages.Hudson_NotAPositiveNumber()); return ok(); } catch (NumberFormatException e) { diff --git a/core/src/main/resources/hudson/model/Messages.properties b/core/src/main/resources/hudson/model/Messages.properties index 42f7d61d86425f933143410cc36957d4019cac19..16c531f0c9c85ccfabd8be3fae8f8d62fb95ee1d 100644 --- a/core/src/main/resources/hudson/model/Messages.properties +++ b/core/src/main/resources/hudson/model/Messages.properties @@ -88,6 +88,7 @@ Hudson.ViewAlreadyExists=A view already exists with the name "{0}" Hudson.ViewName=All Hudson.NotANumber=Not a number Hudson.NotAPositiveNumber=Not a positive number +Hudson.NotANonNegativeNumber=Number may not be negative Hudson.NotANegativeNumber=Not a negative number Hudson.NotUsesUTF8ToDecodeURL=\ Your container doesn''t use UTF-8 to decode URLs. If you use non-ASCII characters as a job name etc, \ diff --git a/core/src/main/resources/hudson/model/Node/help-numExecutors.html b/core/src/main/resources/hudson/model/Node/help-numExecutors.html index 4c8fe55c47a3d91fb856999be28cfe64fcf7f46d..7e30307f29c1561084f778e8c6d044c88434f6a1 100644 --- a/core/src/main/resources/hudson/model/Node/help-numExecutors.html +++ b/core/src/main/resources/hudson/model/Node/help-numExecutors.html @@ -10,5 +10,6 @@

When using Hudson in the master/slave mode, setting this value to 0 would prevent the master - to do any build on its own. - \ No newline at end of file + from doing any building on its own. Slaves may not have zero executors, but may be + temporarily disabled using the button on the slave's status page. +