aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2019-03-01 08:17:32 -0600
committersonartech <sonartech@sonarsource.com>2019-03-06 11:30:44 +0100
commitf02eeba4ef9908da5d6e5ea969e91a22c6c443cd (patch)
treec2cee4e353bc2ac5fb909378624d592b988c6162
parentb41f2655daa7d58a272f0f98ac1ec16ff10f6e24 (diff)
downloadsonarqube-f02eeba4ef9908da5d6e5ea969e91a22c6c443cd.tar.gz
sonarqube-f02eeba4ef9908da5d6e5ea969e91a22c6c443cd.zip
SONAR-11561 Allow more special characters in branch names
-rw-r--r--server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java2
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java6
-rw-r--r--sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java2
-rw-r--r--sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java16
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java6
5 files changed, 16 insertions, 16 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java
index 09c83904ac0..ae137aa4743 100644
--- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java
+++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java
@@ -47,7 +47,7 @@ public class DefaultBranchImpl implements Branch {
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));
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java
index 8c784b3ad2b..0eb1efecd36 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/component/ComponentUpdater.java
@@ -100,7 +100,7 @@ public class ComponentUpdater {
}
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);
@@ -169,8 +169,8 @@ public class ComponentUpdater {
"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);
}
diff --git a/sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java b/sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java
index 93cbbe0439f..a3bb4fb1453 100644
--- a/sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java
+++ b/sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java
@@ -111,7 +111,7 @@ public final class ComponentKeys {
*
* @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);
}
diff --git a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
index d4f45a69769..a328a0c586b 100644
--- a/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
+++ b/sonar-core/src/test/java/org/sonar/core/component/ComponentKeysTest.java
@@ -68,14 +68,14 @@ public class ComponentKeysTest {
@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
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java
index fb67d7dc0fa..c49d685c9c3 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java
@@ -85,7 +85,7 @@ public class ProjectReactorValidator {
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));
@@ -122,8 +122,8 @@ public class ProjectReactorValidator {
}
}
- 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));
}