]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12668 Drop 'sonar.branch.target'
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Wed, 6 Nov 2019 16:17:10 +0000 (10:17 -0600)
committerSonarTech <sonartech@sonarsource.com>
Mon, 9 Dec 2019 19:46:15 +0000 (20:46 +0100)
13 files changed:
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/MergeAndTargetBranchComponentUuids.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/SiblingComponentsWithOpenIssues.java
server/sonar-ce/src/test/java/org/sonar/ce/container/ComputeEngineContainerImplTest.java
server/sonar-server-common/src/test/java/org/sonar/server/webhook/ProjectAnalysisTest.java
sonar-core/src/main/java/org/sonar/core/config/ScannerProperties.java
sonar-core/src/test/java/org/sonar/core/config/CorePropertyDefinitionsTest.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/ProjectRepositoriesSupplier.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/ProjectReactorValidator.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/BranchConfiguration.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/DefaultBranchConfiguration.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/ScannerMediumTester.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorValidatorTest.java

index 76268c9984ea244750bc846defcedd539aad69b3..22faf3f1d9b196c311c2f5fe6a54a74637c6f68a 100644 (file)
@@ -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;
index 8378284069b17c32cf6eff28d2f628e84f5f62cf..7dfad67d056531154a1d3b664afc5b9cc8d3041b 100644 (file)
@@ -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&lt;uuid&gt; in sibling branches/PR that have open issues
+ * Cache a map of component key -> set&lt;uuid&gt; 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<KeyWithUuidDto> components = dbClient.componentDao().selectAllSiblingComponentKeysHavingOpenIssues(dbSession, referenceBranchUuid, currentBranchUuid);
       for (KeyWithUuidDto dto : components) {
         uuidsByKey.computeIfAbsent(removeBranchAndPullRequestFromKey(dto.key()), s -> new HashSet<>()).add(dto.uuid());
index 84e259e03e87112b2fd5e86b2bf33fe6878f5f9c..d6bf03851e6daae113bbc2c6b49f422ce830be1c 100644 (file)
@@ -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(
index e7a0b26e2140abe8b3e936193c53fe5169cfedf4..d36f6137f87cf3d5d286ac71733b41bdc6b816e3 100644 (file)
@@ -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}}");
   }
 }
index cb67a39fb17cab02c619ed89f94a6be174bdbb6a..5b29b91796e3e62ba45ed1a1f361d052b381b9e8 100644 (file)
@@ -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.")
index a5b84fbeac6a2636a35f5aec80b26226a8446448..8fe8e9101a6ea4f79a2ae9dc4d5c3d7e6d18fda6 100644 (file)
@@ -30,7 +30,7 @@ public class CorePropertyDefinitionsTest {
   @Test
   public void all() {
     List<PropertyDefinition> defs = CorePropertyDefinitions.all();
-    assertThat(defs).hasSize(51);
+    assertThat(defs).hasSize(50);
   }
 
   @Test
index d8f3e6c6606a9e1738ab3a9c18f24fe2a7ed3213..ca4c9a32cf7734027d9627ba8a58d020fed62822 100644 (file)
@@ -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);
     }
index 790930a6493223e98450ee060815a26e3c08220a..1d2414b0b1fd33541582d114435197d651f1a8eb 100644 (file)
@@ -44,7 +44,7 @@ public class ProjectRepositoriesSupplier implements Supplier<ProjectRepositories
   public ProjectRepositories get() {
     if (project == null) {
       Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG);
-      project = loader.load(scannerProperties.getProjectKey(), branchConfig.longLivingSonarReferenceBranch());
+      project = loader.load(scannerProperties.getProjectKey(), branchConfig.referenceBranchName());
       profiler.stopInfo();
     }
 
index 9310ba93a6db1ec1003c50a83453e734ca549052..8c2153e7bac5c246f5dc7d1f228e8f384ef26f35 100644 (file)
@@ -36,7 +36,6 @@ import static java.util.Objects.nonNull;
 import static org.apache.commons.lang.StringUtils.isNotEmpty;
 import static org.sonar.core.config.ScannerProperties.BRANCHES_DOC_LINK;
 import static org.sonar.core.config.ScannerProperties.BRANCH_NAME;
-import static org.sonar.core.config.ScannerProperties.BRANCH_TARGET;
 import static org.sonar.core.config.ScannerProperties.PULL_REQUEST_BASE;
 import static org.sonar.core.config.ScannerProperties.PULL_REQUEST_BRANCH;
 import static org.sonar.core.config.ScannerProperties.PULL_REQUEST_KEY;
@@ -83,7 +82,7 @@ public class ProjectReactorValidator {
   }
 
   private void validateBranchParamsWhenPluginAbsent(List<String> 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));
index 26ab17a7b659dc88395fd59c18100c563e959a26..eaa4003f7d36564fb5cc978e23ed1e33b864a6cd 100644 (file)
@@ -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();
index a708727ea4b58c0f2692eebe5f00012fcdca2c64..b117b4a95461fced786a940adc5e1b2add7c06f7 100644 (file)
@@ -43,7 +43,7 @@ public class DefaultBranchConfiguration implements BranchConfiguration {
 
   @CheckForNull
   @Override
-  public String longLivingSonarReferenceBranch() {
+  public String referenceBranchName() {
     return null;
   }
 
index 8025b03034b30372590bb55f958a68159f0e75fa..c769045d1f2fc4126ff72e5227be31baf32be327 100644 (file)
@@ -404,7 +404,7 @@ public class ScannerMediumTester extends ExternalResource {
 
     @CheckForNull
     @Override
-    public String longLivingSonarReferenceBranch() {
+    public String referenceBranchName() {
       return longLivingSonarReferenceBranch;
     }
 
index ef3ebfe1611a264ee44945860de19cff97a35c0c..fc50a63a9dddb729854c84f4b39e1068ce930f10 100644 (file)
@@ -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");