/**
   * @param res
   * @param rsp
   * @param regex
   * @return FormValidation.Kind.OK if the regex is valid, FormValidation.Kind.WARNING if the regex
   *     is valid but consists only of whitespaces or has leading and/or trailing whitespaces, and
   *     FormValidation.Kind.ERROR if the regex syntax is invalid.
   */
  public FormValidation doCheckExcludedFilesRegex(
      final StaplerRequest res,
      final StaplerResponse rsp,
      @QueryParameter("value") final String regex) {

    if ((regex == null) || (regex.isEmpty())) {
      return FormValidation.ok();
    }

    try {
      Pattern.compile(regex);
    } catch (final PatternSyntaxException pse) {
      return FormValidation.error("Regex syntax is invalid.");
    }

    if (regex.trim().isEmpty()) {
      return FormValidation.warning(
          "Regex is valid, but consists entirely of whitespaces - is this intentional?");
    }

    if (!regex.trim().equals(regex)) {
      return FormValidation.warning(
          "Regex is valid, but contains leading and/or trailing whitespaces - is this intentional?");
    }

    return FormValidation.ok();
  }
  public FormValidation doCheckBackupPath(
      final StaplerRequest res,
      final StaplerResponse rsp,
      @QueryParameter("value") final String path) {
    if ((path == null) || path.trim().isEmpty()) {
      return FormValidation.error("Backup path must not be empty.");
    }

    String expandedPathMessage = "";
    String expandedPath = "";
    try {
      expandedPath = Utils.expandEnvironmentVariables(path);
    } catch (final EnvironmentVariableNotDefinedException evnd) {
      return FormValidation.error(evnd.getMessage());
    }
    if (!expandedPath.equals(path)) {
      expandedPathMessage = String.format("The path will be expanded to '%s'.\n\n", expandedPath);
    }

    final File backupdir = new File(expandedPath);
    if (!backupdir.exists()) {
      return FormValidation.warning(
          expandedPathMessage
              + "The directory does not exist, but will be created before the first run.");
    }
    if (!backupdir.isDirectory()) {
      return FormValidation.error(
          expandedPathMessage
              + "A file with this name exists, thus a directory with the same name cannot be created.");
    }
    final File tmp = new File(expandedPath + File.separator + "test.txt");
    try {
      tmp.createNewFile();
    } catch (final Exception e) {
      if (!tmp.canWrite()) {
        return FormValidation.error(
            expandedPathMessage + "The directory exists, but is not writable.");
      }
    } finally {
      if (tmp.exists()) {
        tmp.delete();
      }
    }
    if (!expandedPath.trim().equals(expandedPath)) {
      return FormValidation.warning(
          expandedPathMessage
              + "Path contains leading and/or trailing whitespaces - is this intentional?");
    }

    if (!expandedPathMessage.isEmpty()) {
      return FormValidation.warning(
          expandedPathMessage.substring(0, expandedPathMessage.length() - 2));
    }

    return FormValidation.ok();
  }
 /**
  * Validates the TCF file.
  *
  * @param tcfFile the TCF file
  * @return the form validation
  */
 public FormValidation validateTcfFile(final String tcfFile) {
   FormValidation returnValue = FormValidation.ok();
   if (StringUtils.isBlank(tcfFile)) {
     returnValue = FormValidation.warning(Messages.TestBuilder_NoTcfFile());
   } else if (tcfFile.contains(PARAMETER)) {
     returnValue = FormValidation.warning(Messages.Builder_NoValidatedValue());
   } else if (!tcfFile.endsWith(".tcf")) {
     returnValue = FormValidation.error(Messages.TestBuilder_TcfFileExtension());
   }
   return returnValue;
 }
Example #4
0
    /** Performs syntactical check on the remote FS for slaves. */
    public FormValidation doCheckRemoteFS(@QueryParameter String value)
        throws IOException, ServletException {
      if (Util.fixEmptyAndTrim(value) == null)
        return FormValidation.error(Messages.Slave_Remote_Director_Mandatory());

      if (value.startsWith("\\\\") || value.startsWith("/net/"))
        return FormValidation.warning(Messages.Slave_Network_Mounted_File_System_Warning());

      if (Util.isRelativePath(value)) {
        return FormValidation.warning(Messages.Slave_Remote_Relative_Path_Warning());
      }

      return FormValidation.ok();
    }
Example #5
0
    /**
     * For test Server Address if it available
     *
     * @param value String from Server Address form
     * @return OK if ping, ERROR otherwise
     */
    public FormValidation doCheckServerAddress(@QueryParameter String value) {

      try {

        if (value == null || value.matches("\\s*")) {
          return FormValidation.warning("Set Address");
        }

        if (value.startsWith("$")) {
          return FormValidation.ok();
        }

        new Socket(value, 22).close();

      } catch (UnknownHostException e) {
        return FormValidation.error("Unknown Host\t" + value + "\t" + e.getLocalizedMessage());
      } catch (IOException e) {
        return FormValidation.error(
            "Input Output Exception while connecting to \t"
                + value
                + "\t"
                + e.getLocalizedMessage());
      }
      return FormValidation.ok();
    }
 public static FormValidation validateWarnIfEmpty(
     final String fieldValue, final String displayName) {
   if (StringUtils.trimToNull(fieldValue) == null) {
     return FormValidation.warning("Don't forget to include the " + displayName + ".");
   }
   return FormValidation.ok();
 }
Example #7
0
 public FormValidation doCheckValue(@QueryParameter String value)
     throws IOException, ServletException {
   if (value.isEmpty()) {
     return FormValidation.warning("You must fill this box!");
   }
   return FormValidation.ok();
 }
    public FormValidation doCheckWebHookEndpoint(@QueryParameter String value)
        throws IOException, ServletException {
      if (value.length() == 0) {
        return FormValidation.error("Please set a webHookEndpoint");
      }

      if (value.length() < 20) {
        return FormValidation.warning("Isn't the webHookEndpoint too short?");
      }

      if (!value.startsWith("https://hooks.slack.com/")) {
        return FormValidation.warning("Slack endpoint should start with https://hooks.slack.com/");
      }

      return FormValidation.ok();
    }
    public FormValidation doCheckWorkflowActionName(@QueryParameter String value) {
      if (Util.fixNull(value).trim().length() == 0) {
        return FormValidation.warning(Messages.JiraIssueUpdateBuilder_NoWorkflowAction());
      }

      return FormValidation.ok();
    }
  @Test
  public void noAddressProvided() {

    assertEquals(
        FormValidation.warning("Empty address list provided").toString(),
        descriptor.doCheckWatcherAddresses("").toString());
  }
 public FormValidation doCheckNumExecutors(@QueryParameter int numExecutors) {
   if (numExecutors > 1) {
     return FormValidation.warning("Experimental, see help");
   } else if (numExecutors < 1) {
     return FormValidation.error("Must be > 0");
   }
   return FormValidation.ok();
 }
 /**
  * Validates the test folder.
  *
  * @param testFolder the test folder
  * @return the form validation
  */
 public FormValidation validateTestFolder(final String testFolder) {
   FormValidation returnValue = FormValidation.ok();
   if (StringUtils.isBlank(testFolder)) {
     returnValue = FormValidation.validateRequired(testFolder);
   } else if (testFolder.contains(PARAMETER)) {
     returnValue = FormValidation.warning(Messages.Builder_NoValidatedValue());
   }
   return returnValue;
 }
 /**
  * Validates the global constant value.
  *
  * @param value the global constant value
  * @return FormValidation
  */
 public FormValidation validateGlobalConstantValue(final String value) {
   FormValidation returnValue = FormValidation.ok();
   if (StringUtils.isBlank(value)) {
     returnValue = FormValidation.validateRequired(value);
   } else if (value.contains(PARAMETER)) {
     returnValue = FormValidation.warning(Messages.Builder_NoValidatedValue());
   }
   return returnValue;
 }
 public FormValidation doCheckWaitForIdle(
     final StaplerRequest res,
     final StaplerResponse rsp,
     @QueryParameter("value") final String waitForIdle) {
   if (Boolean.parseBoolean(waitForIdle)) return FormValidation.ok();
   else
     return FormValidation.warning(
         "This may or may not generate corrupt backups! Be aware that no data get changed during the backup process!");
 }
 public FormValidation doCheckHealthScaleFactor(@QueryParameter double value) {
   if (value < 1e-7) return FormValidation.warning("Test health reporting disabled");
   return FormValidation.ok(
       Messages.JUnitResultArchiver_HealthScaleFactorAnalysis(
           1,
           (int) (100.0 - Math.max(0.0, Math.min(100.0, 1 * value))),
           5,
           (int) (100.0 - Math.max(0.0, Math.min(100.0, 5 * value)))));
 }
Example #16
0
    public FormValidation doCheckLabelString(
        @QueryParameter String value, @QueryParameter Node.Mode mode) {
      if (mode == Node.Mode.EXCLUSIVE && (value == null || value.trim().isEmpty())) {
        return FormValidation.warning(
            "You may want to assign labels to this node;"
                + " it's marked to only run jobs that are exclusively tied to itself or a label.");
      }

      return FormValidation.ok();
    }
  public FormValidation doTestThreadFixConnection(
      @QueryParameter("threadFixUrl") String threadFixUrl,
      @QueryParameter("threadFixAPIKey") String threadFixAPIKey) {
    this.threadFixUrl = threadFixUrl;
    this.threadFixAPIKey = threadFixAPIKey;

    ThreadFixClient threadFixClient = new ThreadFixClient(this);

    try {
      threadFixClient.checkConnection();
      this.usingThreadFix = true;
    } catch (Exception ex) {
      return FormValidation.warning("Error talking to ThreadFix: " + ex);
    } catch (ThreadFixClientException e) {
      return FormValidation.warning("Error while talking to ThreadFix: " + e);
    }

    return FormValidation.ok("Connection successful");
  }
Example #18
0
    /**
     * testing if jmx ports given correctly
     *
     * @param value jmx port(s)
     * @return FormValidation
     */
    public FormValidation doCheckJmxPort(@QueryParameter String value) {

      if (value == null || value.matches("\\s*")) {
        return FormValidation.warning("Set JMX Port(s)");
      } else if (!value.matches("\\d+(,\\d+)*")) {
        return FormValidation.error("wrong format: split with comas");
      } else {
        return FormValidation.ok();
      }
    }
 /**
  * Validates the global constant name.
  *
  * @param name the global constant name
  * @return FormValidation
  */
 public FormValidation validateGlobalConstantName(final String name) {
   FormValidation returnValue = FormValidation.ok();
   if (StringUtils.isBlank(name)) {
     returnValue = FormValidation.validateRequired(name);
   } else if (name.contains(PARAMETER)) {
     returnValue = FormValidation.warning(Messages.Builder_NoValidatedValue());
   } else if (!isValidVariableName(name)) {
     returnValue = FormValidation.error(Messages.GlobalConstant_InvalidName());
   }
   return returnValue;
 }
 /**
  * Validates the project file.
  *
  * @param testFile the test file
  * @return the form validation
  */
 public FormValidation validateProjectFile(final String testFile) {
   FormValidation returnValue = FormValidation.ok();
   if (StringUtils.isBlank(testFile)) {
     returnValue = FormValidation.validateRequired(testFile);
   } else if (testFile.contains(PARAMETER)) {
     returnValue = FormValidation.warning(Messages.Builder_NoValidatedValue());
   } else if (!testFile.endsWith(".prj")) {
     returnValue = FormValidation.error(Messages.TestBuilder_PrjFileExtension());
   }
   return returnValue;
 }
    public FormValidation doCheckStashUserPassword(@QueryParameter String value)
        throws IOException, ServletException {

      if (value.trim().equals("")
          && ((stashPassword == null) || stashPassword.getPlainText().trim().equals(""))) {
        return FormValidation.warning(
            "You should use a non-empty password here or in the " + "global configuration!");
      } else {
        return FormValidation.ok();
      }
    }
    /**
     * Check that the releaseVersion field is not empty.
     *
     * @param releaseVersion The release version of the package.
     * @param project The project name
     * @return Ok if not empty, error otherwise.
     */
    public FormValidation doCheckReleaseVersion(
        @QueryParameter String releaseVersion, @QueryParameter String project) {
      setGlobalConfiguration();
      releaseVersion = releaseVersion.trim();
      if (project == null || project.isEmpty()) {
        return FormValidation.warning(PROJECT_RELEASE_VALIDATION_MESSAGE);
      }
      com.octopusdeploy.api.Project p;
      try {
        p = api.getProjectByName(project);
        if (p == null) {
          return FormValidation.warning(PROJECT_RELEASE_VALIDATION_MESSAGE);
        }
      } catch (Exception ex) {
        return FormValidation.warning(PROJECT_RELEASE_VALIDATION_MESSAGE);
      }

      OctopusValidator validator = new OctopusValidator(api);
      return validator.validateRelease(
          releaseVersion, p.getId(), OctopusValidator.ReleaseExistenceRequirement.MustExist);
    }
 public FormValidation doCheckSolrUrl(@QueryParameter final String solrUrl) {
   try {
     URI uri = makeSolrUrl(solrUrl);
     if (solrUrl.equals(uri.toString())) {
       return FormValidation.ok();
     } else {
       return FormValidation.warning("Incomplete url, but solr was found at " + uri.toString());
     }
   } catch (IOException e) {
     return FormValidation.error(e.getMessage());
   }
 }
 /**
  * Validates the filter expression.
  *
  * @param filterExpression the filter expression
  * @return the form validation
  */
 public FormValidation validateFilterExpression(final String filterExpression) {
   FormValidation returnValue = FormValidation.ok();
   if (!StringUtils.isBlank(filterExpression)) {
     if (filterExpression.contains(PARAMETER)) {
       returnValue = FormValidation.warning(Messages.Builder_NoValidatedValue());
     } else {
       final String trimmedExpression =
           StringUtils.trimToEmpty(filterExpression)
               .replaceAll("^\\(\\s*", "(")
               .replaceAll("\\s*\\)", ")");
       final FilterExpressionValidator validator =
           new FilterExpressionValidator(trimmedExpression);
       validator.validate();
       if (!validator.isValid()) {
         returnValue =
             FormValidation.warning(Messages.TestProjectBuilder_InvalidFilterExpression());
       }
     }
   }
   return returnValue;
 }
 /**
  * Checks that the pattern is a valid regexp.
  *
  * @param value the pattern to check.
  * @return {@link hudson.util.FormValidation#ok()} if everything is well.
  */
 public static FormValidation checkPattern(@QueryParameter String value) {
   if (value == null || value.isEmpty()) {
     return FormValidation.error("Please provide a pattern!");
   }
   try {
     Pattern.compile(value);
     return FormValidation.ok();
   } catch (PatternSyntaxException e) {
     return FormValidation.error("Bad syntax! " + e.getMessage());
   } catch (Exception e) {
     return FormValidation.warning("Unpredicted error. " + e.getMessage());
   }
 }
Example #26
0
 public FormValidation doCheckIncludes(
     @AncestorInPath AbstractProject project, @QueryParameter String value)
     throws IOException, InterruptedException {
   if (project.getSomeWorkspace() != null) {
     String msg = project.getSomeWorkspace().validateAntFileMask(value);
     if (msg != null) {
       return FormValidation.error(msg);
     }
     return FormValidation.ok();
   } else {
     return FormValidation.warning(Messages.noworkspace());
   }
 }
  public FormValidation doCheckForceQuietModeTimeout(
      final StaplerRequest res,
      final StaplerResponse rsp,
      @QueryParameter("value") final String timeout) {
    FormValidation validation = FormValidation.validateNonNegativeInteger(timeout);
    if (!FormValidation.ok().equals(validation)) return validation;

    int intTimeout = Integer.parseInt(timeout);
    if (intTimeout > 12 * 60)
      return FormValidation.warning(
          "You choose a very long timeout. The value need to be in minutes.");
    else return FormValidation.ok();
  }
Example #28
0
    public FormValidation doCheckTestingAppNameValue(@QueryParameter String value)
        throws IOException, ServletException {
      testApplicationNameSelected = value;
      if (value.isEmpty()) {
        return FormValidation.warning("You must fill this box!");
      }
      //            else if (!CollectionUtils.isEmpty(deployAppNames) &&
      // !deployAppNames.contains(value.trim())) {
      //                return FormValidation.warning("You have entered a name that does not exist
      // in Hygieia yet. This will create a new application in Hygieia.");
      //            }

      return FormValidation.ok();
    }
Example #29
0
 public static FormValidation validateURL(final String url) {
   if (StringUtils.trimToNull(url) == null) {
     return FormValidation.warning("Don't forget to include the URL.");
   }
   try {
     final URI uri = new URI(url);
     if (uri.getScheme() == null || uri.getHost() == null) {
       return FormValidation.error("Invalid URL: " + url);
     }
     return FormValidation.ok();
   } catch (final Exception e) {
     return FormValidation.error("URL could not be parsed.");
   }
 }
  /** Checks if given repository exists */
  public FormValidation checkDepName(@QueryParameter String value, @QueryParameter String fork)
      throws IOException, ServletException {

    doFillNameItems(fork);

    if (fork.length() == 0) {
      return FormValidation.error(Messages.Dependency_NoFork());
    }

    if (value.length() == 0) {
      return FormValidation.warning(Messages.Repository_NoName());
    }

    // check if given repository is in repo list
    for (String repoName : this.repoNameItems) {
      if (repoName.equals(value)) {
        return FormValidation.ok();
      }
    }
    // if repository was not in list, for example extern repository
    try {
      RepositoryService githubRepoSrv = new RepositoryService(githubClient);
      org.eclipse.egit.github.core.Repository selectedRepo =
          githubRepoSrv.getRepository(fork, value);
      if (selectedRepo != null) {
        if (selectedRepo.isPrivate()) {
          return FormValidation.ok(Messages.Dependency_PrivateFound());
        }
        return FormValidation.ok();
      }
    } catch (IOException ex) {
      // TODO: handle exception
    }

    return FormValidation.warning(
        Messages.Dependency_NotFound(value, fork)); // error(Messages.Repository_NoFound());
  }