]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9616 Use base branch to get project repository (#2426)
authorJanos Gyerik <janos.gyerik@sonarsource.com>
Fri, 25 Aug 2017 14:26:56 +0000 (16:26 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 09:34:52 +0000 (11:34 +0200)
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesLoader.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesProvider.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfiguration.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfigurationValidator.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchParamsValidator.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchConfiguration.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchConfigurationValidator.java [deleted file]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchParamsValidator.java [new file with mode: 0644]
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java

index 0ee523775faccd589b2d9557010a1c71a977f334..ca0ba4da7e0700ea57ae9899fd3054a549febbba 100644 (file)
@@ -52,8 +52,8 @@ public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoad
   }
 
   @Override
-  public ProjectRepositories load(String projectKey, boolean issuesMode, @Nullable String branchTarget) {
-    GetRequest request = new GetRequest(getUrl(projectKey, issuesMode, branchTarget));
+  public ProjectRepositories load(String projectKey, boolean issuesMode, @Nullable String branchBase) {
+    GetRequest request = new GetRequest(getUrl(projectKey, issuesMode, branchBase));
     try (WsResponse response = wsClient.call(request)) {
       InputStream is = response.contentStream();
       return processStream(is, projectKey);
@@ -67,7 +67,7 @@ public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoad
     }
   }
 
-  private static String getUrl(String projectKey, boolean issuesMode, @Nullable String branchTarget) {
+  private static String getUrl(String projectKey, boolean issuesMode, @Nullable String branchBase) {
     StringBuilder builder = new StringBuilder();
 
     builder.append(BATCH_PROJECT_URL)
@@ -75,8 +75,8 @@ public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoad
     if (issuesMode) {
       builder.append("&issues_mode=true");
     }
-    if (branchTarget != null) {
-      builder.append("&branch=").append(branchTarget);
+    if (branchBase != null) {
+      builder.append("&branch=").append(branchBase);
     }
     return builder.toString();
   }
index aea1869e4d4425b8fd2cc2307f8676febf7eddc1..4aa4bcd44cff1982b576fa20d337bd4f58565844 100644 (file)
@@ -22,5 +22,5 @@ package org.sonar.scanner.repository;
 import javax.annotation.Nullable;
 
 public interface ProjectRepositoriesLoader {
-  ProjectRepositories load(String projectKeyWithBranch, boolean issuesMode, @Nullable String branchTarget);
+  ProjectRepositories load(String projectKeyWithBranch, boolean issuesMode, @Nullable String branchBase);
 }
index 7821e7fb305bb805e952178b626174dc161af0e8..d4675ff1c073f734815df348fe19ce826ddf3a87 100644 (file)
@@ -39,7 +39,7 @@ public class ProjectRepositoriesProvider extends ProviderAdapter {
   protected ProjectRepositories provideInternal(ProjectRepositoriesLoader loader, ProjectKey projectKey, boolean isIssueMode, BranchConfiguration branchConfig) {
     if (project == null) {
       Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
-      project = loader.load(projectKey.get(), isIssueMode, branchConfig.branchTarget());
+      project = loader.load(projectKey.get(), isIssueMode, branchConfig.branchBase());
       checkProject(isIssueMode);
       profiler.stopInfo();
     }
index 415b68403426590572479732ff5203b5024b4b77..f6a2626d8d379dcb732c452c9563cae42dcf6931 100644 (file)
@@ -41,16 +41,20 @@ public interface BranchConfiguration {
   BranchType branchType();
 
   /**
-   * The name of the target branch to merge into, and the base to determine changed files.
-   *
-   * @return name of the target branch
+   * The name of the branch.
+   */
+  @CheckForNull
+  String branchName();
+
+  /**
+   * The name of the target branch to merge into.
    */
   @CheckForNull
   String branchTarget();
 
   /**
-   * The name of the branch.
+   * The name of the base branch to determine project repository and changed files.
    */
   @CheckForNull
-  String branchName();
+  String branchBase();
 }
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfigurationValidator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfigurationValidator.java
deleted file mode 100644 (file)
index 8855553..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.scan;
-
-import java.util.List;
-import javax.annotation.Nullable;
-import org.sonar.api.batch.InstantiationStrategy;
-import org.sonar.api.batch.ScannerSide;
-
-@ScannerSide
-@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
-public interface BranchConfigurationValidator {
-  void validate(List<String> validationMessages, @Nullable String deprecatedBranchName, boolean incrementalMode);
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchParamsValidator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchParamsValidator.java
new file mode 100644 (file)
index 0000000..441ca02
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.scan;
+
+import java.util.List;
+import javax.annotation.Nullable;
+import org.sonar.api.batch.InstantiationStrategy;
+import org.sonar.api.batch.ScannerSide;
+
+@ScannerSide
+@InstantiationStrategy(InstantiationStrategy.PER_BATCH)
+public interface BranchParamsValidator {
+  void validate(List<String> validationMessages, @Nullable String deprecatedBranchName, boolean incrementalMode);
+}
index f81bc572063a627f27e0b6688f9e148622eb1523..97a9ddf5cc14c9bb0061ec548195794b3b0d05c9 100644 (file)
@@ -29,6 +29,12 @@ public class DefaultBranchConfiguration implements BranchConfiguration {
     return BranchType.LONG;
   }
 
+  @CheckForNull
+  @Override
+  public String branchName() {
+    return null;
+  }
+
   @CheckForNull
   @Override
   public String branchTarget() {
@@ -37,7 +43,7 @@ public class DefaultBranchConfiguration implements BranchConfiguration {
 
   @CheckForNull
   @Override
-  public String branchName() {
+  public String branchBase() {
     return null;
   }
 }
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchConfigurationValidator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchConfigurationValidator.java
deleted file mode 100644 (file)
index 68c5272..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2017 SonarSource SA
- * mailto:info AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- */
-package org.sonar.scanner.scan;
-
-import java.util.List;
-import javax.annotation.Nullable;
-
-public class DefaultBranchConfigurationValidator implements BranchConfigurationValidator {
-  @Override
-  public void validate(List<String> validationMessages, @Nullable String deprecatedBranchName, boolean incrementalMode) {
-    // no-op
-  }
-}
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchParamsValidator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchParamsValidator.java
new file mode 100644 (file)
index 0000000..4d39cda
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.scanner.scan;
+
+import java.util.List;
+import javax.annotation.Nullable;
+
+public class DefaultBranchParamsValidator implements BranchParamsValidator {
+  @Override
+  public void validate(List<String> validationMessages, @Nullable String deprecatedBranchName, boolean incrementalMode) {
+    // no-op
+  }
+}
index eb08678d0c0cef9e28e0a88b732f0f11e3b961c2..81f2ba4ffd9b167a69a216f21d8594c77e44d1a8 100644 (file)
@@ -37,15 +37,15 @@ import org.sonar.scanner.analysis.DefaultAnalysisMode;
 public class ProjectReactorValidator {
   private final DefaultAnalysisMode mode;
 
-  private final BranchConfigurationValidator branchConfigurationValidator;
+  private final BranchParamsValidator branchParamsValidator;
 
-  public ProjectReactorValidator(DefaultAnalysisMode mode, BranchConfigurationValidator branchConfigurationValidator) {
+  public ProjectReactorValidator(DefaultAnalysisMode mode, BranchParamsValidator branchParamsValidator) {
     this.mode = mode;
-    this.branchConfigurationValidator = branchConfigurationValidator;
+    this.branchParamsValidator = branchParamsValidator;
   }
 
   public ProjectReactorValidator(DefaultAnalysisMode mode) {
-    this(mode, new DefaultBranchConfigurationValidator());
+    this(mode, new DefaultBranchParamsValidator());
   }
 
   public void validate(ProjectReactor reactor) {
@@ -61,7 +61,7 @@ public class ProjectReactorValidator {
 
     String deprecatedBranchName = reactor.getRoot().getBranch();
 
-    branchConfigurationValidator.validate(validationMessages, deprecatedBranchName, mode.isIncremental());
+    branchParamsValidator.validate(validationMessages, deprecatedBranchName, mode.isIncremental());
     validateBranch(validationMessages, deprecatedBranchName);
 
     if (!validationMessages.isEmpty()) {
index 641b75de6af05b197c4d4624f5a602f536092ce6..df04b69b62e6f95523d9ebe34fbf64baef068d2b 100644 (file)
@@ -372,7 +372,7 @@ public class ScannerMediumTester extends ExternalResource {
     private Date lastAnalysisDate;
 
     @Override
-    public ProjectRepositories load(String projectKey, boolean isIssuesMode, @Nullable String branchTarget) {
+    public ProjectRepositories load(String projectKey, boolean isIssuesMode, @Nullable String branchBase) {
       Table<String, String, String> settings = HashBasedTable.create();
       return new ProjectRepositories(settings, fileDataTable, lastAnalysisDate);
     }
@@ -392,14 +392,21 @@ public class ScannerMediumTester extends ExternalResource {
   private static class FakeBranchConfiguration implements BranchConfiguration {
 
     private BranchType branchType = BranchType.LONG;
-    private String branchName = "";
-    private String branchTarget = "";
+    private String branchName = null;
+    private String branchTarget = null;
+    private String branchBase = null;
 
     @Override
     public BranchType branchType() {
       return branchType;
     }
 
+    @CheckForNull
+    @Override
+    public String branchName() {
+      return branchName;
+    }
+
     @CheckForNull
     @Override
     public String branchTarget() {
@@ -408,8 +415,8 @@ public class ScannerMediumTester extends ExternalResource {
 
     @CheckForNull
     @Override
-    public String branchName() {
-      return branchName;
+    public String branchBase() {
+      return branchBase;
     }
   }