diff options
author | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-08-25 16:26:56 +0200 |
---|---|---|
committer | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-09-12 11:34:52 +0200 |
commit | 9361eca51202cb9923055f1b822203bc8d6cedc9 (patch) | |
tree | dbc5f02724011c31c2b8ef35ff477d3c72cb950f /sonar-scanner-engine | |
parent | 798fe14660d8be551cbec08066f47969263d8517 (diff) | |
download | sonarqube-9361eca51202cb9923055f1b822203bc8d6cedc9.tar.gz sonarqube-9361eca51202cb9923055f1b822203bc8d6cedc9.zip |
SONAR-9616 Use base branch to get project repository (#2426)
Diffstat (limited to 'sonar-scanner-engine')
9 files changed, 42 insertions, 25 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java index 0ee523775fa..ca0ba4da7e0 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java @@ -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(); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesLoader.java index aea1869e4d4..4aa4bcd44cf 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesLoader.java @@ -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); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesProvider.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesProvider.java index 7821e7fb305..d4675ff1c07 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesProvider.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesProvider.java @@ -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(); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfiguration.java index 415b6840342..f6a2626d8d3 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfiguration.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfiguration.java @@ -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/BranchParamsValidator.java index 8855553bb0e..441ca02a03b 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchConfigurationValidator.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/BranchParamsValidator.java @@ -26,6 +26,6 @@ import org.sonar.api.batch.ScannerSide; @ScannerSide @InstantiationStrategy(InstantiationStrategy.PER_BATCH) -public interface BranchConfigurationValidator { +public interface BranchParamsValidator { void validate(List<String> validationMessages, @Nullable String deprecatedBranchName, boolean incrementalMode); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchConfiguration.java index f81bc572063..97a9ddf5cc1 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchConfiguration.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchConfiguration.java @@ -31,13 +31,19 @@ public class DefaultBranchConfiguration implements BranchConfiguration { @CheckForNull @Override + public String branchName() { + return null; + } + + @CheckForNull + @Override public String branchTarget() { return null; } @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/DefaultBranchParamsValidator.java index 68c52726341..4d39cda6dfc 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchConfigurationValidator.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/DefaultBranchParamsValidator.java @@ -22,7 +22,7 @@ package org.sonar.scanner.scan; import java.util.List; import javax.annotation.Nullable; -public class DefaultBranchConfigurationValidator implements BranchConfigurationValidator { +public class DefaultBranchParamsValidator implements BranchParamsValidator { @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/ProjectReactorValidator.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java index eb08678d0c0..81f2ba4ffd9 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java @@ -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()) { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java index 641b75de6af..df04b69b62e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java @@ -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,8 +392,9 @@ 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() { @@ -402,14 +403,20 @@ public class ScannerMediumTester extends ExternalResource { @CheckForNull @Override + public String branchName() { + return branchName; + } + + @CheckForNull + @Override public String branchTarget() { return branchTarget; } @CheckForNull @Override - public String branchName() { - return branchName; + public String branchBase() { + return branchBase; } } |