Refine search
/** * Validates the retry count Regex */ public FormValidation doCheckRetryCount(@QueryParameter String value)throws IOException,ServletException{ // retry count is optional so this is ok if(value == null || value.trim().equals("")) return FormValidation.ok(); if (!value.matches("[0-9]*")) { return FormValidation.error("Invalid retry count"); } return FormValidation.ok(); }
/** * Makes sure that the given string is a non-negative integer. */ 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()); } }
/** * Performs syntax check. */ public FormValidation doCheckSpec(@QueryParameter String value, @AncestorInPath Item item) { try { CronTabList ctl = CronTabList.create(fixNull(value), item != null ? Hash.from(item.getFullName()) : null); Collection<FormValidation> validations = new ArrayList<>(); updateValidationsForSanity(validations, ctl); updateValidationsForNextRun(validations, ctl); return FormValidation.aggregate(validations); } catch (ANTLRException e) { if (value.trim().indexOf('\n')==-1 && value.contains("**")) return FormValidation.error(Messages.TimerTrigger_MissingWhitespace()); return FormValidation.error(e.getMessage()); } }
public FormValidation doCheckNewSource(@QueryParameter String newSource){ Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); String normalized = Util.fixEmptyAndTrim(newSource); File f = new File(newSource); if (normalized == null) { return FormValidation.ok(); // empty, do nothing } else if (!f.exists() && !ConfigurationAsCode.isSupportedURI(normalized)) { return FormValidation.error("Configuration cannot be applied. File or URL cannot be parsed or do not exist."); } try { final Map<Source, String> issues = collectIssues(newSource); final JSONArray errors = collectProblems(issues, "error"); if (!errors.isEmpty()) { return FormValidation.error(errors.toString()); } final JSONArray warnings = collectProblems(issues, "warning"); if (!warnings.isEmpty()) { return FormValidation.warning(warnings.toString()); } return FormValidation.okWithMarkup("The configuration can be applied"); } catch (ConfiguratorException e) { return FormValidation.error(e, e.getCause().getMessage()); } catch (IllegalArgumentException e) { return FormValidation.error(e, e.getCause().getMessage()); } }
public FormValidation doCheckAcceptLicense(@QueryParameter boolean value) { if (username==null || password==null) return FormValidation.errorWithMarkup(Messages.JDKInstaller_RequireOracleAccount(Stapler.getCurrentRequest().getContextPath()+'/'+getDescriptorUrl()+"/enterCredential")); if (value) { return FormValidation.ok(); } else { return FormValidation.error(Messages.JDKInstaller_DescriptorImpl_doCheckAcceptLicense()); } }
public FormValidation doCheckAdminAddress(@QueryParameter String value) { try { new InternetAddress(value); return FormValidation.ok(); } catch (AddressException e) { return FormValidation.error(e.getMessage()); } }
/** * 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) { return error(hudson.model.Messages.Hudson_NotANumber()); } }
public FormValidation doCheckToolHome(@QueryParameter String value) { if (value.length() > 0) { return FormValidation.ok(); } else { return FormValidation.error(Messages.CommandInstaller_no_command()); } } }
/** * Checks if the MAVEN_HOME is valid. */ @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); if(!maven1File.exists() && !maven2File.exists()) return FormValidation.error(Messages.Maven_NotMavenDirectory(value)); return FormValidation.ok(); }
public FormValidation doCheckCommand(@QueryParameter String value) { if (value.length() > 0) { return FormValidation.ok(); } else { return FormValidation.error(Messages.CommandInstaller_no_command()); } }
/** * Checks if the JAVA_HOME is a valid JAVA_HOME path. */ @Override protected FormValidation checkHomeDirectory(File value) { File toolsJar = new File(value,"lib/tools.jar"); File mac = new File(value,"lib/dt.jar"); // JENKINS-25601: JDK 9+ no longer has tools.jar. Keep the existing dt.jar/tools.jar checks to be safe. File javac = new File(value, "bin/javac"); File javacExe = new File(value, "bin/javac.exe"); if(!toolsJar.exists() && !mac.exists() && !javac.exists() && !javacExe.exists()) return FormValidation.error(Messages.Hudson_NotJDKDir(value)); return FormValidation.ok(); }
/** * Checks if the include regular expression is valid. */ public FormValidation doCheckIncludeRegex( @QueryParameter String value ) throws IOException, ServletException, InterruptedException { String v = Util.fixEmpty(value); if (v != null) { try { Pattern.compile(v); } catch (PatternSyntaxException pse) { return FormValidation.error(pse.getMessage()); } } return FormValidation.ok(); } }
/** * Makes sure that the given string is a base64 encoded text. * * @param allowWhitespace * if you allow whitespace (CR,LF,etc) in base64 encoding * @param allowEmpty * Is empty string allowed? * @param errorMessage * Error message. * @since 1.305 */ public static FormValidation validateBase64(String value, boolean allowWhitespace, boolean allowEmpty, String errorMessage) { try { String v = value; if(!allowWhitespace) { if(v.indexOf(' ')>=0 || v.indexOf('\n')>=0) return error(errorMessage); } v=v.trim(); if(!allowEmpty && v.length()==0) return error(errorMessage); com.trilead.ssh2.crypto.Base64.decode(v.toCharArray()); return ok(); } catch (IOException e) { return error(errorMessage); } }
public FormValidation doCheckNamePattern(@QueryParameter String value) throws IOException, ServletException { String pattern = Util.fixEmptyAndTrim(value); if (pattern == null) { return FormValidation.error(Messages.PatternProjectNamingStrategy_NamePatternRequired()); } try { Pattern.compile(pattern); } catch (PatternSyntaxException e) { return FormValidation.error(Messages.PatternProjectNamingStrategy_NamePatternInvalidSyntax()); } return FormValidation.ok(); } }
/** * Make sure that the given string is an integer in the range specified by the lower and upper bounds (both inclusive) * * @param value the value to check * @param lower the lower bound (inclusive) * @param upper the upper bound (inclusive) * * @since 2.104 */ public static FormValidation validateIntegerInRange(String value, int lower, int upper) { try { int intValue = Integer.parseInt(value); if (intValue < lower) { return error(hudson.model.Messages.Hudson_MustBeAtLeast(lower)); } if (intValue > upper) { return error(hudson.model.Messages.Hudson_MustBeAtMost(upper)); } return ok(); } catch (NumberFormatException e) { return error(hudson.model.Messages.Hudson_NotANumber()); } }
/** * Checks if parameterized build choices are valid. */ public FormValidation doCheckChoices(@QueryParameter String value) { if (ChoiceParameterDefinition.areValidChoices(value)) { return FormValidation.ok(); } else { return FormValidation.error(Messages.ChoiceParameterDefinition_MissingChoices()); } } }
public FormValidation doCheckCustomWorkspace(@QueryParameter String customWorkspace){ if(Util.fixEmptyAndTrim(customWorkspace)==null) return FormValidation.error(Messages.AbstractProject_CustomWorkspaceEmpty()); else return FormValidation.ok(); }