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"); } }
@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"); } }