public DefaultBranchImpl(@Nullable String name) {
this.isLegacyBranch = (name != null);
this.branchName = (name == null) ? BranchDto.DEFAULT_MAIN_BRANCH_NAME : name;
- if (!ComponentKeys.isValidBranch(branchName)) {
+ if (!ComponentKeys.isValidLegacyBranch(branchName)) {
throw MessageException.of(format("\"%s\" is not a valid branch name. "
+ "Allowed characters are alphanumeric, '-', '_', '.' and '/'.", branchName));
}
}
private ComponentDto createRootComponent(DbSession session, NewComponent newComponent) {
- checkBranchFormat(newComponent.qualifier(), newComponent.deprecatedBranch());
+ checkLegacyBranchFormat(newComponent.qualifier(), newComponent.deprecatedBranch());
String keyWithBranch = ComponentKeys.createKey(newComponent.key(), newComponent.deprecatedBranch());
checkRequest(!dbClient.componentDao().selectByKey(session, keyWithBranch).isPresent(),
"Could not create %s, key already exists: %s", getQualifierToDisplay(newComponent.qualifier()), keyWithBranch);
"Malformed key for %s: %s. Allowed characters are alphanumeric, '-', '_', '.' and ':', with at least one non-digit.", getQualifierToDisplay(qualifier), key);
}
- private void checkBranchFormat(String qualifier, @Nullable String branch) {
- checkRequest(branch == null || ComponentKeys.isValidBranch(branch),
+ private void checkLegacyBranchFormat(String qualifier, @Nullable String branch) {
+ checkRequest(branch == null || ComponentKeys.isValidLegacyBranch(branch),
"Malformed branch for %s: %s. Allowed characters are alphanumeric, '-', '_', '.' and '/', with at least one non-digit.", getQualifierToDisplay(qualifier), branch);
}
*
* @return <code>true</code> if <code>branchCandidate</code> can be used for a project
*/
- public static boolean isValidBranch(String branchCandidate) {
+ public static boolean isValidLegacyBranch(String branchCandidate) {
return branchCandidate.matches(VALID_BRANCH_REGEXP);
}
@Test
public void isValidBranchKey() {
- assertThat(ComponentKeys.isValidBranch("")).isTrue();
- assertThat(ComponentKeys.isValidBranch("abc")).isTrue();
- assertThat(ComponentKeys.isValidBranch("0123")).isTrue();
- assertThat(ComponentKeys.isValidBranch("ab 12")).isFalse();
- assertThat(ComponentKeys.isValidBranch("ab_12")).isTrue();
- assertThat(ComponentKeys.isValidBranch("ab/12")).isTrue();
- assertThat(ComponentKeys.isValidBranch("ab\\12")).isFalse();
- assertThat(ComponentKeys.isValidBranch("ab\n")).isFalse();
+ assertThat(ComponentKeys.isValidLegacyBranch("")).isTrue();
+ assertThat(ComponentKeys.isValidLegacyBranch("abc")).isTrue();
+ assertThat(ComponentKeys.isValidLegacyBranch("0123")).isTrue();
+ assertThat(ComponentKeys.isValidLegacyBranch("ab 12")).isFalse();
+ assertThat(ComponentKeys.isValidLegacyBranch("ab_12")).isTrue();
+ assertThat(ComponentKeys.isValidLegacyBranch("ab/12")).isTrue();
+ assertThat(ComponentKeys.isValidLegacyBranch("ab\\12")).isFalse();
+ assertThat(ComponentKeys.isValidLegacyBranch("ab\n")).isFalse();
}
@Test
validatePullRequestParamsWhenPluginAbsent(validationMessages);
}
- validateBranch(validationMessages, deprecatedBranchName);
+ validateLegacyBranch(validationMessages, deprecatedBranchName);
if (!validationMessages.isEmpty()) {
throw MessageException.of("Validation of project reactor failed:\n o " + Joiner.on("\n o ").join(validationMessages));
}
}
- private static void validateBranch(List<String> validationMessages, @Nullable String branch) {
- if (isNotEmpty(branch) && !ComponentKeys.isValidBranch(branch)) {
+ private static void validateLegacyBranch(List<String> validationMessages, @Nullable String branch) {
+ if (isNotEmpty(branch) && !ComponentKeys.isValidLegacyBranch(branch)) {
validationMessages.add(format("\"%s\" is not a valid branch name. "
+ "Allowed characters are alphanumeric, '-', '_', '.' and '/'.", branch));
}