aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/main/java/org
diff options
context:
space:
mode:
authorJanos Gyerik <janos.gyerik@sonarsource.com>2018-08-22 14:24:02 +0200
committersonartech <sonartech@sonarsource.com>2018-09-19 10:51:42 +0200
commit8af697d69441500c42dfc5d8954d44314d65a00b (patch)
tree8ed43112f23b00c1cb09926106387c484052cdc4 /sonar-scanner-engine/src/main/java/org
parent8b06fb069fa33596461c4e21cdde4f59b632a20c (diff)
downloadsonarqube-8af697d69441500c42dfc5d8954d44314d65a00b.tar.gz
sonarqube-8af697d69441500c42dfc5d8954d44314d65a00b.zip
SONAR-11166 Fall back to default branch when target is not specified
Diffstat (limited to 'sonar-scanner-engine/src/main/java/org')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java23
1 files changed, 20 insertions, 3 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java
index ce5d73822e3..afc5182d1d6 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java
@@ -19,11 +19,11 @@
*/
package org.sonar.scanner.scan.branch;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.function.Function;
-import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
+import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
/**
@@ -34,8 +34,20 @@ public class ProjectBranches {
private final Map<String, BranchInfo> branches;
+ @Nullable
+ private final String defaultBranchName;
+
public ProjectBranches(List<BranchInfo> branchInfos) {
- branches = branchInfos.stream().collect(Collectors.toMap(BranchInfo::name, Function.identity()));
+ this.branches = new HashMap<>();
+ String mainBranchName = null;
+ for (BranchInfo branch : branchInfos) {
+ String branchName = branch.name();
+ this.branches.put(branchName, branch);
+ if (branch.isMain()) {
+ mainBranchName = branchName;
+ }
+ }
+ this.defaultBranchName = mainBranchName;
}
@CheckForNull
@@ -46,4 +58,9 @@ public class ProjectBranches {
public boolean isEmpty() {
return branches.isEmpty();
}
+
+ @CheckForNull
+ public String defaultBranchName() {
+ return defaultBranchName;
+ }
}