From: Duarte Meneses Date: Wed, 6 Nov 2019 16:17:10 +0000 (-0600) Subject: SONAR-12668 Drop 'sonar.branch.target' X-Git-Tag: 8.1.0.31237~49 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0a6525b3f63132a719e96a16233aef04fcf535cd;p=sonarqube.git SONAR-12668 Drop 'sonar.branch.target' --- diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MergeAndTargetBranchComponentUuids.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MergeAndTargetBranchComponentUuids.java index 76268c9984e..22faf3f1d9b 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MergeAndTargetBranchComponentUuids.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MergeAndTargetBranchComponentUuids.java @@ -34,7 +34,7 @@ import static com.google.common.base.Preconditions.checkState; import static org.sonar.db.component.ComponentDto.removeBranchAndPullRequestFromKey; /** - * Cache a map between component keys and uuids in the merge branch and optionally the target branch (for PR and SLB, and only if this target branch is analyzed) + * Cache a map between component keys and uuids in the merge branch and optionally the target branch (for PRs, and only if this target branch is analyzed) */ public class MergeAndTargetBranchComponentUuids { private final AnalysisMetadataHolder analysisMetadataHolder; diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java index 8378284069b..7dfad67d056 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java @@ -33,7 +33,7 @@ import org.sonar.db.component.KeyWithUuidDto; import static org.sonar.db.component.ComponentDto.removeBranchAndPullRequestFromKey; /** - * Cache a map of component key -> set<uuid> in sibling branches/PR that have open issues + * Cache a map of component key -> set<uuid> in sibling PRs that have open issues */ public class SiblingComponentsWithOpenIssues { private final DbClient dbClient; @@ -60,6 +60,7 @@ public class SiblingComponentsWithOpenIssues { uuidsByKey = new HashMap<>(); try (DbSession dbSession = dbClient.openSession(false)) { + // for the time being it still tries to load from short living branches List components = dbClient.componentDao().selectAllSiblingComponentKeysHavingOpenIssues(dbSession, referenceBranchUuid, currentBranchUuid); for (KeyWithUuidDto dto : components) { uuidsByKey.computeIfAbsent(removeBranchAndPullRequestFromKey(dto.key()), s -> new HashSet<>()).add(dto.uuid()); diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java index 84e259e03e8..d6bf03851e6 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java @@ -130,7 +130,7 @@ public class ComputeEngineContainerImplTest { + 27 // level 1 + 65 // content of DaoModule + 3 // content of EsModule - + 51 // content of CorePropertyDefinitions + + 50 // content of CorePropertyDefinitions + 1 // StopFlagContainer ); assertThat( diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java index e7a0b26e214..d36f6137f87 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java @@ -148,6 +148,6 @@ public class ProjectAnalysisTest { @Test public void verify_toString() { assertThat(underTest.toString()).isEqualTo( - "ProjectAnalysis{project=Project{uuid='uuid', key='key', name='name'}, ceTask=CeTask{id='id', status=SUCCESS}, branch=Branch{main=true, name='name', type=SHORT}, qualityGate=EvaluatedQualityGate{qualityGate=QualityGate{id=id, name='name', conditions=[]}, status=ERROR, evaluatedConditions=[]}, updatedAt=1, properties={a=b}, analysis=Analysis{uuid='analysis_uuid', date=1500, revision=sha1}}"); + "ProjectAnalysis{project=Project{uuid='uuid', key='key', name='name'}, ceTask=CeTask{id='id', status=SUCCESS}, branch=Branch{main=true, name='name', type=LONG}, qualityGate=EvaluatedQualityGate{qualityGate=QualityGate{id=id, name='name', conditions=[]}, status=ERROR, evaluatedConditions=[]}, updatedAt=1, properties={a=b}, analysis=Analysis{uuid='analysis_uuid', date=1500, revision=sha1}}"); } } diff --git a/sonar-core/src/main/java/org/sonar/core/config/ScannerProperties.java b/sonar-core/src/main/java/org/sonar/core/config/ScannerProperties.java index cb67a39fb17..5b29b91796e 100644 --- a/sonar-core/src/main/java/org/sonar/core/config/ScannerProperties.java +++ b/sonar-core/src/main/java/org/sonar/core/config/ScannerProperties.java @@ -34,6 +34,7 @@ public class ScannerProperties { public static final String ORGANIZATION = "sonar.organization"; public static final String BRANCH_NAME = "sonar.branch.name"; + @Deprecated public static final String BRANCH_TARGET = "sonar.branch.target"; public static final String PULL_REQUEST_KEY = "sonar.pullrequest.key"; @@ -73,13 +74,6 @@ public class ScannerProperties { .description("Provide a name for the branch being analyzed. It might match an existing branch of the project, otherwise a new branch will be created.") .hidden() .build(), - PropertyDefinition.builder(BRANCH_TARGET) - .name("Optional name of target branch to merge into") - .description( - "Defines the target branch of the branch being analyzed. The main branch cannot have a target. " - + "If no target is defined, the main branch is used as the target.") - .hidden() - .build(), PropertyDefinition.builder(PULL_REQUEST_BRANCH) .name("Optional name of pull request") .description("Provide a name for the pull request being analyzed. It might match an existing pull request of the project, otherwise a new pull request will be created.") diff --git a/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java b/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java index a5b84fbeac6..8fe8e9101a6 100644 --- a/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java @@ -30,7 +30,7 @@ public class CorePropertyDefinitionsTest { @Test public void all() { List defs = CorePropertyDefinitions.all(); - assertThat(defs).hasSize(51); + assertThat(defs).hasSize(50); } @Test diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java index d8f3e6c6606..ca4c9a32cf7 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java @@ -156,7 +156,7 @@ public class MetadataPublisher implements ReportPublisherStep { builder.setBranchName(branchConfiguration.branchName()); BranchType branchType = toProtobufBranchType(branchConfiguration.branchType()); builder.setBranchType(branchType); - String referenceBranch = branchConfiguration.longLivingSonarReferenceBranch(); + String referenceBranch = branchConfiguration.referenceBranchName(); if (referenceBranch != null) { builder.setMergeBranchName(referenceBranch); } diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesSupplier.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesSupplier.java index 790930a6493..1d2414b0b1f 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesSupplier.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesSupplier.java @@ -44,7 +44,7 @@ public class ProjectRepositoriesSupplier implements Supplier validationMessages) { - for (String param : Arrays.asList(BRANCH_NAME, BRANCH_TARGET)) { + for (String param : Arrays.asList(BRANCH_NAME)) { if (isNotEmpty(settings.get(param).orElse(null))) { validationMessages.add(format("To use the property \"%s\" and analyze branches, Developer Edition or above is required. " + "See %s for more information.", param, BRANCHES_DOC_LINK)); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfiguration.java index 26ab17a7b65..eaa4003f7d3 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfiguration.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfiguration.java @@ -26,11 +26,6 @@ import javax.annotation.concurrent.Immutable; public interface BranchConfiguration { /** - * The type of the branch we're on, determined by: - * - If the specified branch exists on the server, then its type - * - If the branch name matches the pattern of long-lived branches, then it's long-lived - * - Otherwise it's short-lived - * * @return type of the current branch */ BranchType branchType(); @@ -40,7 +35,7 @@ public interface BranchConfiguration { } /** - * For long/short living branches, this is the value of sonar.branch.name, and fallback on the default branch name configured in SQ + * For branches, this is the value of sonar.branch.name, and fallback on the default branch name configured in SQ * For PR: the name of the branch containing PR changes (sonar.pullrequest.branch) * * @return null if the branch feature is not available or no branch was specified. @@ -49,24 +44,22 @@ public interface BranchConfiguration { String branchName(); /** - * The long living server branch from which we should load project settings/quality profiles/compare changed files/... - * For long living branches, this is the sonar.branch.target (default to default branch) in case of first analysis, - * otherwise it's the branch itself. - * For short living branches, we look at sonar.branch.target (default to default branch). If it exists but is a short living branch or PR, we will - * transitively use its own target. + * The branch from which we should load project settings/quality profiles/compare changed files/... + * For branches, it's the to default branch in case of first analysis, otherwise it's the branch itself. * For PR, we look at sonar.pullrequest.base (default to default branch). If it exists but is a short living branch or PR, we will * transitively use its own target. If base is not analyzed, we will use default branch. * * @return null if the branch feature is not available or no branch was specified. */ @CheckForNull - String longLivingSonarReferenceBranch(); + String referenceBranchName(); /** - * Raw value of sonar.branch.target or sonar.pullrequest.base (fallback to the default branch). + * For P/Rs, it's the raw value of 'sonar.pullrequest.base'. + * For branches it's always null. * In the scanner side, it will be used by the SCM to compute changed files and changed lines. * - * @return null if the branch feature is not available, the branch being analyzed is the main branch or no branch was specified. + * @return null if the branch feature is not available or if it's not a P/R. */ @CheckForNull String targetBranchName(); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/DefaultBranchConfiguration.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/DefaultBranchConfiguration.java index a708727ea4b..b117b4a9546 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/DefaultBranchConfiguration.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/DefaultBranchConfiguration.java @@ -43,7 +43,7 @@ public class DefaultBranchConfiguration implements BranchConfiguration { @CheckForNull @Override - public String longLivingSonarReferenceBranch() { + public String referenceBranchName() { return null; } 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 8025b03034b..c769045d1f2 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 @@ -404,7 +404,7 @@ public class ScannerMediumTester extends ExternalResource { @CheckForNull @Override - public String longLivingSonarReferenceBranch() { + public String referenceBranchName() { return longLivingSonarReferenceBranch; } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java index ef3ebfe1611..fc50a63a9dd 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java @@ -107,19 +107,6 @@ public class ProjectReactorValidatorTest { underTest.validate(reactor); } - @Test - public void fail_when_branch_target_is_specified_but_branch_plugin_not_present() { - ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo"); - ProjectReactor reactor = new ProjectReactor(def); - - when(settings.get(eq(ScannerProperties.BRANCH_TARGET))).thenReturn(Optional.of("feature1")); - - thrown.expect(MessageException.class); - thrown.expectMessage("To use the property \"sonar.branch.target\" and analyze branches, Developer Edition or above is required"); - - underTest.validate(reactor); - } - @Test public void fail_when_pull_request_id_specified_but_branch_plugin_not_present() { ProjectDefinition def = ProjectDefinition.create().setProperty(CoreProperties.PROJECT_KEY_PROPERTY, "foo");