]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11166 Fall back to default branch when target is not specified
authorJanos Gyerik <janos.gyerik@sonarsource.com>
Wed, 22 Aug 2018 12:24:02 +0000 (14:24 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 19 Sep 2018 08:51:42 +0000 (10:51 +0200)
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java

index ce5d73822e3e12a9a6bbded30a44e25ec446f237..afc5182d1d6055549b9429824ad74ef310cf0b41 100644 (file)
  */
 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;
+  }
 }