提交 954350b9 编写于 作者: J Jesse Glick

Improved form validation for ToolInstallation.home.

上级 aebb876c
......@@ -23,8 +23,6 @@
*/
package hudson.model;
import com.infradna.tool.bridge_method_injector.BridgeMethodsAdded;
import com.infradna.tool.bridge_method_injector.WithBridgeMethods;
import hudson.util.StreamTaskListener;
import hudson.util.NullStream;
import hudson.util.FormValidation;
......@@ -47,7 +45,6 @@ import java.util.Collections;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
/**
* Information about JDK installation.
......@@ -175,16 +172,7 @@ public final class JDK extends ToolInstallation implements NodeSpecific<JDK>, En
/**
* Checks if the JAVA_HOME is a valid JAVA_HOME path.
*/
public FormValidation doCheckHome(@QueryParameter File value) {
// this can be used to check the existence of a file on the server, so needs to be protected
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
if(value.getPath().equals(""))
return FormValidation.ok();
if(!value.isDirectory())
return FormValidation.error(Messages.Hudson_NotADirectory(value));
@Override protected FormValidation checkHomeDirectory(File value) {
File toolsJar = new File(value,"lib/tools.jar");
File mac = new File(value,"lib/dt.jar");
if(!toolsJar.exists() && !mac.exists())
......@@ -193,9 +181,6 @@ 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 {
......
......@@ -64,7 +64,6 @@ import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.QueryParameter;
import java.io.File;
import java.io.IOException;
......@@ -639,17 +638,7 @@ public class Maven extends Builder {
/**
* Checks if the MAVEN_HOME is valid.
*/
public FormValidation doCheckMavenHome(@QueryParameter File value) {
// this can be used to check the existence of a file on the server, so needs to be protected
if(!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER))
return FormValidation.ok();
if(value.getPath().equals(""))
return FormValidation.ok();
if(!value.isDirectory())
return FormValidation.error(Messages.Maven_NotADirectory(value));
@Override protected FormValidation checkHomeDirectory(File value) {
File maven1File = new File(value,MAVEN_1_INSTALLATION_COMMON_FILE);
File maven2File = new File(value,MAVEN_2_INSTALLATION_COMMON_FILE);
......@@ -659,9 +648,6 @@ public class Maven extends Builder {
return FormValidation.ok();
}
public FormValidation doCheckName(@QueryParameter String value) {
return FormValidation.validateRequired(value);
}
}
public static class ConverterImpl extends ToolConverter {
......
......@@ -26,16 +26,18 @@ package hudson.tools;
import hudson.model.Descriptor;
import hudson.util.DescribableList;
import hudson.util.FormValidation;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Array;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.io.IOException;
import java.lang.reflect.Array;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.jvnet.tiger_types.Types;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
/**
......@@ -119,4 +121,41 @@ public abstract class ToolDescriptor<T extends ToolInstallation> extends Descrip
return true;
}
/**
* Checks if the home directory is valid.
* @since 1.563
*/
public FormValidation doCheckHome(@QueryParameter File value) {
// this can be used to check the existence of a file on the server, so needs to be protected
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
if (value.getPath().isEmpty()) {
return FormValidation.ok();
}
if (!value.isDirectory()) {
return FormValidation.warning(Messages.ToolDescriptor_NotADirectory(value));
}
return checkHomeDirectory(value);
}
/**
* May be overridden to provide tool-specific validation of a tool home directory.
* @param home a possible value for {@link ToolInstallation#getHome}, known to already exist on the master
* @return by default, {@link FormValidation#ok()}
* @since 1.563
*/
protected FormValidation checkHomeDirectory(File home) {
return FormValidation.ok();
}
/**
* Checks if the tool name is valid.
* @since 1.563
*/
public FormValidation doCheckName(@QueryParameter String value) {
return FormValidation.validateRequired(value);
}
}
......@@ -140,7 +140,6 @@ Hudson.NoJavaInPath=java is not in your PATH. Maybe you need to <a href="{0}/con
Hudson.NoName=No name is specified
Hudson.NoSuchDirectory=No such directory: {0}
Hudson.NodeBeingRemoved=Node is being removed
Hudson.NotADirectory={0} is not a directory
Hudson.NotAPlugin={0} is not a Jenkins plugin
Hudson.NotJDKDir={0} doesn\u2019t look like a JDK directory
Hudson.Permissions.Title=Overall
......
......@@ -80,6 +80,5 @@ Maven.DisplayName=Invoke top-level Maven targets
Maven.ExecFailed=command execution failed
Maven.NotMavenDirectory={0} doesn\u2019t look like a Maven directory
Maven.NoExecutable=Couldn\u2019t find any executable in {0}
Maven.NotADirectory={0} is not a directory
Shell.DisplayName=Execute shell
......@@ -35,4 +35,5 @@ ZipExtractionInstaller.could_not_connect=Could not connect to URL.
InstallSourceProperty.DescriptorImpl.displayName=Install automatically
JDKInstaller.DescriptorImpl.displayName=Install from java.sun.com
JDKInstaller.DescriptorImpl.doCheckId=Define JDK ID
JDKInstaller.DescriptorImpl.doCheckAcceptLicense=You must agree to the license to download the JDK.
\ No newline at end of file
JDKInstaller.DescriptorImpl.doCheckAcceptLicense=You must agree to the license to download the JDK.
ToolDescriptor.NotADirectory={0} is not a directory on the Jenkins master (but perhaps it exists on some slaves)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册