aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-core
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-03-27 17:42:31 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2014-03-27 17:43:33 +0100
commit5bdefeb0c7ec0227473e259219c4682d052e9998 (patch)
treee399534a5cb4e80d255238dbb3a16828ad28d482 /sonar-core
parent90792a4f54d37f00a4625f946777c3c66f9b8aeb (diff)
downloadsonarqube-5bdefeb0c7ec0227473e259219c4682d052e9998.tar.gz
sonarqube-5bdefeb0c7ec0227473e259219c4682d052e9998.zip
SONAR-4692 Prevent analysis of projects that both embed the same module
Diffstat (limited to 'sonar-core')
-rw-r--r--sonar-core/src/main/java/org/sonar/core/component/ComponentKeys.java18
1 files changed, 18 insertions, 0 deletions
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 e034a3e3afa..57dd45eff49 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
@@ -25,6 +25,8 @@ import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.api.resources.Scopes;
+import javax.annotation.Nullable;
+
public final class ComponentKeys {
/*
@@ -32,6 +34,8 @@ public final class ComponentKeys {
*/
private static final String VALID_MODULE_KEY_REGEXP = "[\\p{Alnum}\\-_.:]*[\\p{Alpha}\\-_.:]+[\\p{Alnum}\\-_.:]*";
+ private static final String KEY_WITH_BRANCH_FORMAT = "%s:%s";
+
private ComponentKeys() {
// only static stuff
}
@@ -74,4 +78,18 @@ public final class ComponentKeys {
public static boolean isValidModuleKey(String keyCandidate) {
return keyCandidate.matches(VALID_MODULE_KEY_REGEXP);
}
+
+ /**
+ * Return the project/module key with potential branch
+ * @param keyWithoutBranch
+ * @param branch
+ * @return
+ */
+ public static String createKey(String keyWithoutBranch, @Nullable String branch) {
+ if (StringUtils.isNotBlank(branch)) {
+ return String.format(KEY_WITH_BRANCH_FORMAT, keyWithoutBranch, branch);
+ } else {
+ return keyWithoutBranch;
+ }
+ }
}