protected boolean validate(
      MirrorSettings ms, Settings settings, SettingsValidationErrors errors) {

    boolean result = true;
    boolean isHttp = false;

    if (ms.mirrorRepoUrl.isEmpty()) {
      result = false;
      errors.addFieldError(SETTING_MIRROR_REPO_URL + ms.suffix, "The mirror repo url is required.");
    } else {
      try {
        URI uri = URI.create(ms.mirrorRepoUrl);
        String scheme = uri.getScheme().toLowerCase();

        if (scheme.startsWith("http")) {
          isHttp = true;
          if (ms.mirrorRepoUrl.contains("@")) {
            result = false;
            errors.addFieldError(
                SETTING_MIRROR_REPO_URL + ms.suffix,
                "The username and password should not be included.");
          }
        }
      } catch (Exception ex) {
        // Not a valid url, assume it is something git can read

      }
    }

    // HTTP must have username and password
    if (isHttp) {
      if (ms.username.isEmpty()) {
        result = false;
        errors.addFieldError(
            SETTING_USERNAME + ms.suffix, "The username is required when using http(s).");
      }

      if (ms.password.isEmpty()) {
        result = false;
        errors.addFieldError(
            SETTING_PASSWORD + ms.suffix, "The password is required when using http(s).");
      }
    } else {
      // Only http should have username or password
      ms.password = ms.username = "";
    }

    return result;
  }
  @Override
  public void validate(
      @Nonnull Settings settings,
      @Nonnull SettingsValidationErrors errors,
      @Nonnull Repository repository) {

    final String jenkinsUrl = settings.getString(Notifier.JENKINS_BASE);
    if (Strings.isNullOrEmpty(jenkinsUrl)) {
      errors.addFieldError(Notifier.JENKINS_BASE, "The url for your Jenkins instance is required.");
    }

    final String cloneType = settings.getString(Notifier.CLONE_URL);
    if (Strings.isNullOrEmpty(cloneType)) {
      errors.addFieldError(Notifier.CLONE_URL, "The repository clone url is required");
    }
  }
  /**
   * Validate the given {@code settings} before they are persisted.
   *
   * @param settings to be validated
   * @param errors callback for reporting validation errors.
   * @param repository the context {@code Repository} the settings will be associated with
   */
  @Override
  public void validate(
      @Nonnull Settings settings,
      @Nonnull SettingsValidationErrors errors,
      @Nonnull Repository repository) {

    try {
      boolean ok = true;
      logger.debug("MirrorRepositoryHook: validate started.");

      List<MirrorSettings> mirrorSettings = getMirrorSettings(settings);

      for (MirrorSettings ms : mirrorSettings) {
        if (!validate(ms, settings, errors)) {
          ok = false;
        }
      }

      // If no errors, run the mirror command
      if (ok) {
        updateSettings(mirrorSettings, settings);
        for (MirrorSettings ms : mirrorSettings) {
          runMirrorCommand(ms, repository);
        }
      }

    } catch (Exception e) {
      logger.error("Error running MirrorRepositoryHook validate.", e);
      errors.addFormError(e.getMessage());
    }
  }
 @Override
 public void validate(Settings settings, SettingsValidationErrors errors, Repository repository) {
   try {
     Pattern.compile(settings.getString(SETTINGS_PATTERN, ""));
   } catch (PatternSyntaxException e) {
     errors.addFieldError(SETTINGS_PATTERN, "Pattern is not a valid regular expression");
   }
 }