diff options
author | Janos Gyerik <janos.gyerik@sonarsource.com> | 2018-08-22 14:24:02 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2018-09-19 10:51:42 +0200 |
commit | 8af697d69441500c42dfc5d8954d44314d65a00b (patch) | |
tree | 8ed43112f23b00c1cb09926106387c484052cdc4 /sonar-scanner-engine/src/main/java/org | |
parent | 8b06fb069fa33596461c4e21cdde4f59b632a20c (diff) | |
download | sonarqube-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.java | 23 |
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; + } } |