提交 83c040c4 编写于 作者: S sogabe

[FIXED HUDSON-8088] check the name of Ant, Maven and JDK installations.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@36901 71c3de6d-444a-0410-be80-ed276b4c234a
上级 7d8cc5c0
......@@ -29,6 +29,7 @@ import hudson.util.FormValidation;
import hudson.Launcher;
import hudson.Extension;
import hudson.EnvVars;
import hudson.Util;
import hudson.slaves.NodeSpecific;
import hudson.tools.ToolInstallation;
import hudson.tools.ToolDescriptor;
......@@ -177,6 +178,10 @@ public final class JDK extends ToolInstallation implements NodeSpecific<JDK>, En
return FormValidation.ok();
}
public FormValidation doCheckName(@QueryParameter String value) {
return FormValidation.validateRequired(value);
}
}
public static class ConverterImpl extends ToolConverter {
......
......@@ -30,7 +30,14 @@ import hudson.FilePath;
import hudson.Functions;
import hudson.Launcher;
import hudson.Util;
import hudson.model.*;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Computer;
import hudson.model.EnvironmentSpecific;
import hudson.model.Hudson;
import hudson.model.Node;
import hudson.model.TaskListener;
import hudson.remoting.Callable;
import hudson.slaves.NodeSpecific;
import hudson.tasks._ant.AntConsoleAnnotator;
......@@ -246,7 +253,7 @@ public class Ant extends Builder {
return (DescriptorImpl)super.getDescriptor();
}
@Extension
@Extension
public static class DescriptorImpl extends BuildStepDescriptor<Builder> {
@CopyOnWrite
private volatile AntInstallation[] installations = new AntInstallation[0];
......@@ -417,6 +424,10 @@ public class Ant extends Builder {
return FormValidation.ok();
}
public FormValidation doCheckName(@QueryParameter String value) {
return FormValidation.validateRequired(value);
}
}
public static class ConverterImpl extends ToolConverter {
......
......@@ -547,6 +547,10 @@ public class Maven extends Builder {
return FormValidation.ok();
}
public FormValidation doCheckName(@QueryParameter String value) {
return FormValidation.validateRequired(value);
}
}
public static class ConverterImpl extends ToolConverter {
......
......@@ -354,6 +354,15 @@ public abstract class FormValidation extends IOException implements HttpResponse
}
}
/**
* Makes sure that the given string is not null or empty.
*/
public static FormValidation validateRequired(String value) {
if (Util.fixEmptyAndTrim(value) == null)
return error(Messages.FormValidation_ValidateRequired());
return ok();
}
/**
* Makes sure that the given string is a base64 encoded text.
*
......
# The MIT License
#
# Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe
# Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
......@@ -23,4 +23,5 @@
ClockDifference.InSync=In sync
ClockDifference.Ahead=\ ahead
ClockDifference.Behind=\ behind
ClockDifference.Failed=Failed to check
\ No newline at end of file
ClockDifference.Failed=Failed to check
FormValidation.ValidateRequired=Required
\ No newline at end of file
# The MIT License
#
# Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe
# Copyright (c) 2004-2010, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
......@@ -20,7 +20,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
ClockDifference.InSync=\u540C\u671F\u4E2D
ClockDifference.Ahead=\ \u9032\u3093\u3067\u3044\u307E\u3059
ClockDifference.Behind=\ \u9045\u308C\u3066\u3044\u307E\u3059
ClockDifference.Failed=\u30C1\u30A7\u30C3\u30AF\u306B\u5931\u6557\u3057\u307E\u3057\u305F
\ No newline at end of file
ClockDifference.InSync=\u540c\u671f\u4e2d
ClockDifference.Ahead=\ \u9032\u3093\u3067\u3044\u307e\u3059
ClockDifference.Behind=\ \u9045\u308c\u3066\u3044\u307e\u3059
ClockDifference.Failed=\u30c1\u30a7\u30c3\u30af\u306b\u5931\u6557\u3057\u307e\u3057\u305f
FormValidation.ValidateRequired=\u5fc5\u9808\u9805\u76ee\u3067\u3059\u3002
\ No newline at end of file
/*
* The MIT License
*
* Copyright (c) 2010, Seiji Sogabe
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package hudson.util;
import junit.framework.TestCase;
/**
* @author sogabe
*/
public class FormValidationTest extends TestCase {
public void testValidateRequired_OK() {
FormValidation actual = FormValidation.validateRequired("Name");
assertEquals(FormValidation.ok(), actual);
}
public void testValidateRequired_Null() {
FormValidation actual = FormValidation.validateRequired(null);
assertNotNull(actual);
assertEquals(FormValidation.Kind.ERROR, actual.kind);
}
public void testValidateRequired_Empty() {
FormValidation actual = FormValidation.validateRequired(" ");
assertNotNull(actual);
assertEquals(FormValidation.Kind.ERROR, actual.kind);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册