]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11631 Replace codePeriodVersion with buildString
authorJanos Gyerik <janos.gyerik@sonarsource.com>
Fri, 15 Mar 2019 14:11:38 +0000 (15:11 +0100)
committerSonarTech <sonartech@sonarsource.com>
Tue, 19 Mar 2019 19:21:27 +0000 (20:21 +0100)
50 files changed:
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/ProjectAttributes.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStep.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentImplTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentTreeBuilderTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ReportComponent.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/LoadPeriodsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/PersistEventsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistAnalysisStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistAnalysisStepTest.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotQuery.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDtoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotQueryTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeDaoTest.java
server/sonar-db-dao/src/test/resources/org/sonar/db/component/SnapshotDaoTest/select_snapshots_by_query.xml
server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java
server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/NewIssuesNotification.java
server/sonar-server-common/src/main/java/org/sonar/server/notification/email/AlertsEmailTemplate.java
server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java
server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java
server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesNotificationTest.java
server/sonar-server/src/main/java/org/sonar/server/component/ws/ComponentDtoToWsComponent.java
server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/CreateEventAction.java
server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/DeleteEventAction.java
server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/SearchResponseBuilder.java
server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/UpdateEventAction.java
server/sonar-server/src/main/java/org/sonar/server/ui/ws/ComponentAction.java
server/sonar-server/src/test/java/org/sonar/server/component/ws/ShowActionTest.java
server/sonar-server/src/test/java/org/sonar/server/notification/email/AlertsEmailTemplateTest.java
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/CreateEventActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/DeleteEventActionTest.java
server/sonar-server/src/test/java/org/sonar/server/projectanalysis/ws/UpdateEventActionTest.java
server/sonar-server/src/test/java/org/sonar/server/ui/ws/ComponentActionTest.java
sonar-plugin-api/src/main/java/org/sonar/api/CoreProperties.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/ProjectInfo.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/report/MetadataPublisher.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/ProjectInfoTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/report/MetadataPublisherTest.java
sonar-scanner-protocol/src/main/protobuf/scanner_report.proto
sonar-ws/src/main/protobuf/ws-projectanalyses.proto

index 0acceca325558a0668a4ac62eb16707f7aadacef..051c7f0cec32b96fa1571cc30e8f2a005899067d 100644 (file)
@@ -26,27 +26,22 @@ import static java.util.Objects.requireNonNull;
 
 public class ProjectAttributes {
   private final String projectVersion;
-  private final String codePeriodVersion;
+
+  @Nullable
   private final String buildString;
 
-  public ProjectAttributes(@Nullable String projectVersion, String codePeriodVersion, String buildString) {
-    this.projectVersion = projectVersion;
-    this.codePeriodVersion = requireNonNull(codePeriodVersion, "codePeriod version can't be null");
+  public ProjectAttributes(String projectVersion, @Nullable String buildString) {
+    this.projectVersion = requireNonNull(projectVersion, "project version can't be null");
     this.buildString = buildString;
   }
 
   public ProjectAttributes(ProjectAttributes projectAttributes) {
     this.projectVersion = projectAttributes.projectVersion;
-    this.codePeriodVersion = projectAttributes.codePeriodVersion;
     this.buildString = projectAttributes.buildString;
   }
 
-  public Optional<String> getProjectVersion() {
-    return Optional.ofNullable(projectVersion);
-  }
-
-  public String getCodePeriodVersion() {
-    return codePeriodVersion;
+  public String getProjectVersion() {
+    return projectVersion;
   }
 
   public Optional<String> getBuildString() {
@@ -57,7 +52,6 @@ public class ProjectAttributes {
   public String toString() {
     return "ProjectAttributes{" +
       "projectVersion='" + projectVersion + '\'' +
-      "codePeriodVersion='" + codePeriodVersion + '\'' +
       "buildString='" + buildString + '\'' +
       '}';
   }
index 1bd1d95f9eede0de12f9a020f1d8dc159d51d476..b4788259f408b2b05954bd5d207a5ebc29eb3e69 100644 (file)
@@ -111,23 +111,17 @@ public class BuildComponentTreeStep implements ComputationStep {
   }
 
   private static ProjectAttributes createProjectAttributes(ScannerReport.Metadata metadata, @Nullable SnapshotDto baseAnalysis) {
-    String projectVersion = trimToNull(metadata.getProjectVersion());
-    String codePeriodVersion = computeCodePeriodVersion(metadata.getCodePeriodVersion(), projectVersion, baseAnalysis);
+    String projectVersion = computeProjectVersion(trimToNull(metadata.getProjectVersion()), baseAnalysis);
     String buildString = trimToNull(metadata.getBuildString());
-    return new ProjectAttributes(projectVersion, codePeriodVersion, buildString);
+    return new ProjectAttributes(projectVersion, buildString);
   }
 
-  private static String computeCodePeriodVersion(String rawCodePeriodVersion, @Nullable String projectVersion, @Nullable SnapshotDto baseAnalysis) {
-    String codePeriodVersion = trimToNull(rawCodePeriodVersion);
-    if (codePeriodVersion != null) {
-      return codePeriodVersion;
-    }
-    // support case (legacy but not forbidden) where only projectVersion is set
+  private static String computeProjectVersion(@Nullable String projectVersion, @Nullable SnapshotDto baseAnalysis) {
     if (projectVersion != null) {
       return projectVersion;
     }
     if (baseAnalysis != null) {
-      return firstNonNull(baseAnalysis.getCodePeriodVersion(), DEFAULT_PROJECT_VERSION);
+      return firstNonNull(baseAnalysis.getProjectVersion(), DEFAULT_PROJECT_VERSION);
     }
     return DEFAULT_PROJECT_VERSION;
   }
index b8cc247a6c13e09351626106dd53e07055eea917..5894c17a8ce247126df93df2b35324af72fdda7d 100644 (file)
@@ -109,7 +109,7 @@ public class LoadPeriodsStep implements ComputationStep {
   }
 
   private Optional<Period> resolvePeriod(Component projectOrView) {
-    String currentVersion = projectOrView.getProjectAttributes().getCodePeriodVersion();
+    String currentVersion = projectOrView.getProjectAttributes().getProjectVersion();
     Optional<String> propertyValue = configRepository.getConfiguration().get(LEAK_PERIOD)
       .filter(t -> !t.isEmpty());
     checkPeriodProperty(propertyValue.isPresent(), "", "property is undefined or value is empty");
index c693268c341765629677219cbbbf85d4b4da3f32..c6bc3bdc068516e96e5cebc0329622f1e7e3e6a4 100644 (file)
@@ -102,12 +102,10 @@ public class PersistAnalysisStep implements ComputationStep {
 
     private SnapshotDto createAnalysis(String snapshotUuid, Component component) {
       String componentUuid = component.getUuid();
-      String codePeriodVersion = component.getType() == PROJECT ? component.getProjectAttributes().getCodePeriodVersion() : null;
-      String projectVersion = component.getType() == PROJECT ? component.getProjectAttributes().getProjectVersion().orElse(null) : null;
+      String projectVersion = component.getType() == PROJECT ? component.getProjectAttributes().getProjectVersion() : null;
       String buildString = component.getType() == PROJECT ? component.getProjectAttributes().getBuildString().orElse(null) : null;
       return new SnapshotDto()
         .setUuid(snapshotUuid)
-        .setCodePeriodVersion(codePeriodVersion)
         .setProjectVersion(projectVersion)
         .setBuildString(buildString)
         .setComponentUuid(componentUuid)
index 3c08852cd4ca9c157f3b9f3c8bfe9f89ceeedc37..8f73c54f8cc7722a2de58b71f5b8fc23a69685b8 100644 (file)
@@ -101,10 +101,10 @@ public class PersistEventsStep implements ComputationStep {
     }
 
     private void saveVersionEvent(DbSession session, Component component, Long analysisDate) {
-      String codePeriodVersion = component.getProjectAttributes().getCodePeriodVersion();
-      deletePreviousEventsHavingSameVersion(session, codePeriodVersion, component);
+      String projectVersion = component.getProjectAttributes().getProjectVersion();
+      deletePreviousEventsHavingSameVersion(session, projectVersion, component);
       dbClient.eventDao().insert(session, newBaseEvent(component, analysisDate)
-        .setName(codePeriodVersion)
+        .setName(projectVersion)
         .setCategory(EventDto.CATEGORY_VERSION));
     }
 
index b65e2ce6298b090bb2b99e87b28fae69dc9ca770..a19b3c0553c9c77a818c4b997fed3c0ac6e4eaec 100644 (file)
@@ -132,7 +132,7 @@ public class QualityGateEventsStep implements ComputationStep {
       .setDefaultMessage(String.format("Alert on %s: %s", project.getName(), label))
       .setFieldValue("projectName", project.getName())
       .setFieldValue("projectKey", project.getKey())
-      .setFieldValue("codePeriodVersion", project.getProjectAttributes().getCodePeriodVersion())
+      .setFieldValue("projectVersion", project.getProjectAttributes().getProjectVersion())
       .setFieldValue("alertName", label)
       .setFieldValue("alertText", rawStatus.getText())
       .setFieldValue("alertLevel", rawStatus.getStatus().toString())
index 1288006d6be83ec1223e81c5a1a96a64d60c2776..28e29107eaf8a26dd5c2908a662265f88bbeea1c 100644 (file)
@@ -165,7 +165,7 @@ public class SendIssueNotificationsStep implements ComputationStep {
     NewIssuesNotification notification = newIssuesNotificationFactory
       .newNewIssuesNotification()
       .setProject(project.getKey(), project.getName(), getBranchName(), getPullRequest())
-      .setCodePeriodVersion(project.getProjectAttributes().getCodePeriodVersion())
+      .setProjectVersion(project.getProjectAttributes().getProjectVersion())
       .setAnalysisDate(new Date(analysisDate))
       .setStatistics(project.getName(), globalStatistics)
       .setDebt(Duration.create(globalStatistics.effort().getOnLeak()));
@@ -186,7 +186,7 @@ public class SendIssueNotificationsStep implements ComputationStep {
           .setAssignee(userDtoByUuid.get(assigneeUuid));
         myNewIssuesNotification
           .setProject(project.getKey(), project.getName(), getBranchName(), getPullRequest())
-          .setCodePeriodVersion(project.getProjectAttributes().getCodePeriodVersion())
+          .setProjectVersion(project.getProjectAttributes().getProjectVersion())
           .setAnalysisDate(new Date(analysisDate))
           .setStatistics(project.getName(), assigneeStatistics)
           .setDebt(Duration.create(assigneeStatistics.effort().getOnLeak()));
index ce49e193645641c87207e87434236e59902397b8..e1e7d216e73ad48a4e0cafe59d7eca5086c0065d 100644 (file)
@@ -249,7 +249,7 @@ public class ComponentImplTest {
       .setReportAttributes(ReportAttributes.newBuilder(dbKey.hashCode()).build());
     if (type == PROJECT) {
       String buildString = randomAlphabetic(15);
-      builder.setProjectAttributes(new ProjectAttributes(null, "version_1", buildString));
+      builder.setProjectAttributes(new ProjectAttributes("version_1", buildString));
     }
     return builder;
   }
index cd49f88736983e8b64cb17110ce6c8995d545185..c62af5f23b09247bc139a0a263e3de4b0d6dd8d9 100644 (file)
@@ -19,9 +19,6 @@
  */
 package org.sonar.ce.task.projectanalysis.component;
 
-import com.tngtech.java.junit.dataprovider.DataProvider;
-import com.tngtech.java.junit.dataprovider.DataProviderRunner;
-import com.tngtech.java.junit.dataprovider.UseDataProvider;
 import java.util.Arrays;
 import java.util.EnumSet;
 import java.util.HashMap;
@@ -31,12 +28,10 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.Random;
 import java.util.function.Function;
-import javax.annotation.Nullable;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.junit.rules.ExternalResource;
-import org.junit.runner.RunWith;
 import org.sonar.ce.task.projectanalysis.analysis.Branch;
 import org.sonar.core.component.ComponentKeys;
 import org.sonar.scanner.protocol.output.ScannerReport;
@@ -58,7 +53,6 @@ import static org.sonar.scanner.protocol.output.ScannerReport.Component.Componen
 import static org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType.UNRECOGNIZED;
 import static org.sonar.scanner.protocol.output.ScannerReport.Component.newBuilder;
 
-@RunWith(DataProviderRunner.class)
 public class ComponentTreeBuilderTest {
 
   private static final ComponentKeyGenerator KEY_GENERATOR = (projectKey, path) -> "generated_"
@@ -70,8 +64,7 @@ public class ComponentTreeBuilderTest {
   private static final String NO_SCM_BASE_PATH = "";
   // both no project as "" or null should be supported
   private static final ProjectAttributes SOME_PROJECT_ATTRIBUTES = new ProjectAttributes(
-    new Random().nextBoolean() ? null : randomAlphabetic(12),
-    randomAlphabetic(20), randomAlphabetic(21));
+    randomAlphabetic(20), new Random().nextBoolean() ? null : randomAlphabetic(12));
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
@@ -128,8 +121,7 @@ public class ComponentTreeBuilderTest {
   }
 
   @Test
-  @UseDataProvider("projectVersionOrNull")
-  public void by_default_project_fields_are_loaded_from_report(@Nullable String projectVersion) {
+  public void by_default_project_fields_are_loaded_from_report() {
     String nameInReport = "the name";
     String descriptionInReport = "the desc";
     String buildString = randomAlphabetic(21);
@@ -139,7 +131,7 @@ public class ComponentTreeBuilderTest {
       .setRef(42)
       .setName(nameInReport)
       .setDescription(descriptionInReport)
-      .build(), NO_SCM_BASE_PATH, new ProjectAttributes(projectVersion, "6.5", buildString));
+      .build(), NO_SCM_BASE_PATH, new ProjectAttributes("6.5", buildString));
 
     assertThat(root.getUuid()).isEqualTo("generated_K1_uuid");
     assertThat(root.getDbKey()).isEqualTo("generated_K1");
@@ -149,24 +141,11 @@ public class ComponentTreeBuilderTest {
     assertThat(root.getShortName()).isEqualTo(nameInReport);
     assertThat(root.getDescription()).isEqualTo(descriptionInReport);
     assertThat(root.getReportAttributes().getRef()).isEqualTo(42);
-    if (projectVersion == null) {
-      assertThat(root.getProjectAttributes().getProjectVersion()).isEmpty();
-    } else {
-      assertThat(root.getProjectAttributes().getProjectVersion()).contains(projectVersion);
-    }
-    assertThat(root.getProjectAttributes().getCodePeriodVersion()).isEqualTo("6.5");
+    assertThat(root.getProjectAttributes().getProjectVersion()).contains("6.5");
     assertThat(root.getProjectAttributes().getBuildString()).isEqualTo(Optional.of(buildString));
     assertThatFileAttributesAreNotSet(root);
   }
 
-  @DataProvider
-  public static Object[][] projectVersionOrNull() {
-    return new Object[][] {
-      {null},
-      {randomAlphabetic(15)}
-    };
-  }
-
   @Test
   public void project_name_is_loaded_from_db_if_absent_from_report() {
     Component root = call(newBuilder()
index da34e9235d8a50bfefa7e1149fdeae2657e471cd..68b6439652558f1a9be3c4d4d5c7af223d1e21de 100644 (file)
@@ -43,7 +43,7 @@ public class ReportComponent implements Component {
     .setPublicKey("PUBLIC_PROJECT_KEY")
     .setUuid("PROJECT_UUID")
     .setName("Project Name")
-    .setCodePeriodVersion("1.0-SNAPSHOT")
+    .setProjectVersion("1.0-SNAPSHOT")
     .build();
 
   private final Type type;
@@ -69,8 +69,8 @@ public class ReportComponent implements Component {
     this.shortName = builder.shortName == null ? this.name : builder.shortName;
     this.description = builder.description;
     this.uuid = builder.uuid;
-    this.projectAttributes = Optional.ofNullable(builder.codePeriodVersion)
-      .map(t -> new ProjectAttributes(builder.projectVersion, t, builder.buildString))
+    this.projectAttributes = Optional.ofNullable(builder.projectVersion)
+      .map(v -> new ProjectAttributes(v, builder.buildString))
       .orElse(null);
     this.reportAttributes = ReportAttributes.newBuilder(builder.ref)
       .build();
@@ -205,7 +205,6 @@ public class ReportComponent implements Component {
     private String publicKey;
     private String name;
     private String shortName;
-    private String codePeriodVersion;
     private String projectVersion;
     private String buildString;
     private String description;
@@ -217,7 +216,7 @@ public class ReportComponent implements Component {
       this.type = type;
       this.ref = ref;
       if (type == Type.PROJECT) {
-        this.codePeriodVersion = "toBeDefined";
+        this.projectVersion = "toBeDefined";
       }
     }
 
@@ -251,18 +250,14 @@ public class ReportComponent implements Component {
       return this;
     }
 
-    public Builder setCodePeriodVersion(String s) {
-      checkArgument(type != Type.PROJECT ^ s != null, "CodePeriod version must and can only be set on Project");
-      this.codePeriodVersion = s;
-      return this;
-    }
-
-    public Builder setProjectVersion(@Nullable String projectVersion) {
-      this.projectVersion = projectVersion;
+    public Builder setProjectVersion(@Nullable String s) {
+      checkProjectVersion(s);
+      this.projectVersion = s;
       return this;
     }
 
     public Builder setBuildString(@Nullable String buildString) {
+      checkBuildString(buildString);
       this.buildString = buildString;
       return this;
     }
@@ -287,9 +282,17 @@ public class ReportComponent implements Component {
     }
 
     public ReportComponent build() {
-      checkArgument(type != Type.PROJECT ^ this.codePeriodVersion != null, "CodePeriod version must and can only be set on Project");
-      checkArgument(type == Type.PROJECT || this.buildString == null, "BuildString can only be set on Project");
+      checkProjectVersion(this.projectVersion);
+      checkBuildString(this.buildString);
       return new ReportComponent(this);
     }
+
+    private void checkProjectVersion(@Nullable String s) {
+      checkArgument(type != Type.PROJECT ^ s != null, "Project version must and can only be set on Project");
+    }
+
+    private void checkBuildString(@Nullable String s) {
+      checkArgument(type == Type.PROJECT || s == null, "BuildString can only be set on Project");
+    }
   }
 }
index 1fa66c1a2856cd9a11a6f6a2f766035a637cae09..b4968b4518bcb3aba78e088fec479ee21e2d6291 100644 (file)
@@ -66,7 +66,7 @@ import static org.sonar.scanner.protocol.output.ScannerReport.Component.Componen
 @RunWith(DataProviderRunner.class)
 public class BuildComponentTreeStepTest {
   private static final String NO_SCANNER_PROJECT_VERSION = null;
-  private static final String NO_SCANNER_CODE_PERIOD_VERSION = null;
+  private static final String NO_SCANNER_BUILD_STRING = null;
 
   private static final int ROOT_REF = 1;
   private static final int FILE_1_REF = 4;
@@ -91,7 +91,7 @@ public class BuildComponentTreeStepTest {
   @Rule
   public DbTester dbTester = DbTester.create(System2.INSTANCE);
   @Rule
-  public BatchReportReaderRule reportReader = new BatchReportReaderRule().setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, NO_SCANNER_CODE_PERIOD_VERSION));
+  public BatchReportReaderRule reportReader = new BatchReportReaderRule().setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, NO_SCANNER_BUILD_STRING));
   @Rule
   public MutableTreeRootHolderRule treeRootHolder = new MutableTreeRootHolderRule();
   @Rule
@@ -322,161 +322,70 @@ public class BuildComponentTreeStepTest {
   }
 
   @Test
-  public void set_codePeriodVersion_to_not_provided_when_both_codePeriod_and_project_version_are_not_set_on_first_analysis() {
+  public void set_projectVersion_to_not_provided_when_not_set_on_first_analysis() {
     setAnalysisMetadataHolder();
     reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
 
     underTest.execute(new TestComputationStepContext());
 
-    assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion()).isEqualTo("not provided");
+    assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).isEqualTo("not provided");
   }
 
   @Test
   @UseDataProvider("oneParameterNullNonNullCombinations")
-  public void set_codePeriodVersion_to_previous_analysis_codePeriodVersion_when_both_codePeriod_and_project_version_are_not_set(
-    @Nullable String previousAnalysisCodePeriodVersion) {
+  public void set_projectVersion_to_previous_analysis_when_not_set(@Nullable String previousAnalysisProjectVersion) {
     setAnalysisMetadataHolder();
     OrganizationDto organizationDto = dbTester.organizations().insert();
     ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY));
-    insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true));
+    insertSnapshot(newAnalysis(project).setProjectVersion(previousAnalysisProjectVersion).setLast(true));
     reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
 
     underTest.execute(new TestComputationStepContext());
 
-    String codePeriodVersion = treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion();
-    if (previousAnalysisCodePeriodVersion == null) {
-      assertThat(codePeriodVersion).isEqualTo("not provided");
+    String projectVersion = treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion();
+    if (previousAnalysisProjectVersion == null) {
+      assertThat(projectVersion).isEqualTo("not provided");
     } else {
-      assertThat(codePeriodVersion).isEqualTo(previousAnalysisCodePeriodVersion);
+      assertThat(projectVersion).isEqualTo(previousAnalysisProjectVersion);
     }
   }
 
   @Test
-  public void set_codePeriodVersion_to_projectVersion_when_codePeriodVersion_is_unset_and_projectVersion_is_set_on_first_analysis() {
+  public void set_projectVersion_when_it_is_set_on_first_analysis() {
     String scannerProjectVersion = randomAlphabetic(12);
     setAnalysisMetadataHolder();
-    reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_CODE_PERIOD_VERSION));
+    reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_BUILD_STRING));
     reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
 
     underTest.execute(new TestComputationStepContext());
 
-    assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion())
+    assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion())
       .isEqualTo(scannerProjectVersion);
   }
 
   @Test
   @UseDataProvider("oneParameterNullNonNullCombinations")
-  public void set_codePeriodVersion_to_projectVersion_when_codePeriodVersion_is_unset_and_projectVersion_is_set_on_later_analysis(
-    @Nullable String previousAnalysisCodePeriodVersion) {
+  public void set_projectVersion_when_it_is_set_on_later_analysis(@Nullable String previousAnalysisProjectVersion) {
     String scannerProjectVersion = randomAlphabetic(12);
     setAnalysisMetadataHolder();
-    reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_CODE_PERIOD_VERSION));
+    reportReader.setMetadata(createReportMetadata(scannerProjectVersion, NO_SCANNER_BUILD_STRING));
     OrganizationDto organizationDto = dbTester.organizations().insert();
     ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY));
-    insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true));
+    insertSnapshot(newAnalysis(project).setProjectVersion(previousAnalysisProjectVersion).setLast(true));
     reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
 
     underTest.execute(new TestComputationStepContext());
 
-    assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion())
+    assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion())
       .isEqualTo(scannerProjectVersion);
   }
 
-  @Test
-  @UseDataProvider("oneParameterNullNonNullCombinations")
-  public void set_codePeriodVersion_to_codePeriodVersion_when_it_is_set_on_first_analysis(@Nullable String projectVersion) {
-    String scannerCodePeriodVersion = randomAlphabetic(12);
-    setAnalysisMetadataHolder();
-    reportReader.setMetadata(createReportMetadata(projectVersion, scannerCodePeriodVersion));
-    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
-
-    underTest.execute(new TestComputationStepContext());
-
-    assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion())
-      .isEqualTo(scannerCodePeriodVersion);
-  }
-
-  @Test
-  @UseDataProvider("twoParametersNullNonNullCombinations")
-  public void set_codePeriodVersion_to_codePeriodVersion_when_it_is_set_on_later_analysis(@Nullable String projectVersion, @Nullable String previousAnalysisCodePeriodVersion) {
-    String scannerCodePeriodVersion = randomAlphabetic(12);
-    setAnalysisMetadataHolder();
-    reportReader.setMetadata(createReportMetadata(projectVersion, scannerCodePeriodVersion));
-    OrganizationDto organizationDto = dbTester.organizations().insert();
-    ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY));
-    insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true));
-    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
-
-    underTest.execute(new TestComputationStepContext());
-
-    assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getCodePeriodVersion())
-      .isEqualTo(scannerCodePeriodVersion);
-  }
-
-  @Test
-  @UseDataProvider("oneParameterNullNonNullCombinations")
-  public void set_projectVersion_to_null_when_projectVersion_is_unset_on_first_analysis(@Nullable String codePeriodVersion) {
-    setAnalysisMetadataHolder();
-    reportReader.setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, codePeriodVersion));
-    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
-
-    underTest.execute(new TestComputationStepContext());
-
-    assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).isEmpty();
-  }
-
-  @Test
-  @UseDataProvider("twoParametersNullNonNullCombinations")
-  public void set_projectVersion_to_null_when_projectVersion_is_unset_on_later_analysis(@Nullable String codePeriodVersion, @Nullable String previousAnalysisCodePeriodVersion) {
-    setAnalysisMetadataHolder();
-    reportReader.setMetadata(createReportMetadata(NO_SCANNER_PROJECT_VERSION, codePeriodVersion));
-    OrganizationDto organizationDto = dbTester.organizations().insert();
-    ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY));
-    insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true));
-    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
-
-    underTest.execute(new TestComputationStepContext());
-
-    assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).isEmpty();
-  }
-
-  @Test
-  @UseDataProvider("oneParameterNullNonNullCombinations")
-  public void set_projectVersion_to_projectVersion_when_projectVersion_is_set_on_first_analysis(@Nullable String codePeriodVersion) {
-    String projectVersion = randomAlphabetic(7);
-    setAnalysisMetadataHolder();
-    reportReader.setMetadata(createReportMetadata(projectVersion, codePeriodVersion));
-    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
-
-    underTest.execute(new TestComputationStepContext());
-
-    assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).contains(projectVersion);
-  }
-
-  @Test
-  @UseDataProvider("twoParametersNullNonNullCombinations")
-  public void set_projectVersion_to_projectVersion_when_projectVersion_is_set_on_later_analysis(@Nullable String codePeriodVersion,
-    @Nullable String previousAnalysisCodePeriodVersion) {
-    String projectVersion = randomAlphabetic(7);
-    setAnalysisMetadataHolder();
-    reportReader.setMetadata(createReportMetadata(projectVersion, codePeriodVersion));
-    OrganizationDto organizationDto = dbTester.organizations().insert();
-    ComponentDto project = insertComponent(newPrivateProjectDto(organizationDto, "ABCD").setDbKey(REPORT_PROJECT_KEY));
-    insertSnapshot(newAnalysis(project).setCodePeriodVersion(previousAnalysisCodePeriodVersion).setLast(true));
-    reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
-
-    underTest.execute(new TestComputationStepContext());
-
-    assertThat(treeRootHolder.getReportTreeRoot().getProjectAttributes().getProjectVersion()).contains(projectVersion);
-  }
-
   @Test
   @UseDataProvider("oneParameterNullNonNullCombinations")
   public void set_buildString(@Nullable String buildString) {
     String projectVersion = randomAlphabetic(7);
-    String codePeriodVersion = randomAlphabetic(8);
     setAnalysisMetadataHolder();
-    reportReader.setMetadata(createReportMetadata(projectVersion, codePeriodVersion, buildString));
+    reportReader.setMetadata(createReportMetadata(projectVersion, buildString));
     reportReader.putComponent(component(ROOT_REF, PROJECT, REPORT_PROJECT_KEY));
 
     underTest.execute(new TestComputationStepContext());
@@ -492,16 +401,6 @@ public class BuildComponentTreeStepTest {
     };
   }
 
-  @DataProvider
-  public static Object[][] twoParametersNullNonNullCombinations() {
-    return new Object[][] {
-      {null, null},
-      {randomAlphabetic(7), null},
-      {null, randomAlphabetic(8)},
-      {randomAlphabetic(9), randomAlphabetic(10)}
-    };
-  }
-
   private void verifyComponent(Component component, Component.Type type, @Nullable Integer componentRef, int size) {
     assertThat(component.getType()).isEqualTo(type);
     assertThat(component.getReportAttributes().getRef()).isEqualTo(componentRef);
@@ -622,15 +521,10 @@ public class BuildComponentTreeStepTest {
       .setProject(Project.from(newPrivateProjectDto(newOrganizationDto()).setDbKey(REPORT_PROJECT_KEY)));
   }
 
-  public static ScannerReport.Metadata createReportMetadata(@Nullable String projectVersion, @Nullable String scannerCodePeriodVersion) {
-    return createReportMetadata(projectVersion, scannerCodePeriodVersion, null);
-  }
-
-  public static ScannerReport.Metadata createReportMetadata(@Nullable String projectVersion, @Nullable String scannerCodePeriodVersion, @Nullable String buildString) {
+  public static ScannerReport.Metadata createReportMetadata(@Nullable String projectVersion, @Nullable String buildString) {
     ScannerReport.Metadata.Builder builder = ScannerReport.Metadata.newBuilder()
       .setProjectKey(REPORT_PROJECT_KEY)
       .setRootComponentRef(ROOT_REF);
-    ofNullable(scannerCodePeriodVersion).ifPresent(builder::setCodePeriodVersion);
     ofNullable(projectVersion).ifPresent(builder::setProjectVersion);
     ofNullable(buildString).ifPresent(builder::setBuildString);
     return builder.build();
index a0cd375b0a8b2f21f6e5c852cf0879dffdca0b35..a1ad8c75e3d0480d2eaf2be0eb29b7e102e5ed08 100644 (file)
@@ -156,7 +156,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
     SnapshotDto analysis1 = dbTester.components()
       .insertSnapshot(project, snapshot -> snapshot.setStatus(STATUS_UNPROCESSED).setCreatedAt(1226379600000L).setLast(false));// 2008-11-11
     SnapshotDto analysis2 = dbTester.components().insertSnapshot(project,
-      snapshot -> snapshot.setStatus(STATUS_PROCESSED).setCodePeriodVersion("not provided").setCreatedAt(1226379600000L).setLast(false));// 2008-11-29
+      snapshot -> snapshot.setStatus(STATUS_PROCESSED).setProjectVersion("not provided").setCreatedAt(1226379600000L).setLast(false));// 2008-11-29
     dbTester.events().insertEvent(newEvent(analysis1).setName("not provided").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt()));
     dbTester.events().insertEvent(newEvent(analysis2).setName("not provided").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt()));
     when(analysisMetadataHolder.getAnalysisDate()).thenReturn(november30th2008.getTime());
@@ -366,11 +366,11 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   }
 
   @Test
-  public void feed_period_parameter_as_null_when_manual_baseline_has_same_project_and_codePeriod_version() {
+  public void feed_period_parameter_as_null_when_manual_baseline_has_same_project_version() {
     String version = randomAlphabetic(12);
     OrganizationDto organization = dbTester.organizations().insert();
     ComponentDto project = dbTester.components().insertMainBranch(organization);
-    SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setCodePeriodVersion(version).setProjectVersion(version));
+    SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setProjectVersion(version).setProjectVersion(version));
     dbTester.components().setManualBaseline(project, manualBaselineAnalysis);
     when(analysisMetadataHolder.getBranch()).thenReturn(branchOf(project));
     setupRoot(project);
@@ -382,24 +382,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   }
 
   @Test
-  public void feed_no_period_parameter_as_projectVersion_when_manual_baseline_has_project_version_and_other_codePeriod_version() {
-    String codePeriodVersion = randomAlphabetic(12);
-    String projectVersion = randomAlphabetic(15);
-    OrganizationDto organization = dbTester.organizations().insert();
-    ComponentDto project = dbTester.components().insertMainBranch(organization);
-    SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setCodePeriodVersion(codePeriodVersion).setProjectVersion(projectVersion));
-    dbTester.components().setManualBaseline(project, manualBaselineAnalysis);
-    when(analysisMetadataHolder.getBranch()).thenReturn(branchOf(project));
-    setupRoot(project);
-
-    settings.setProperty("sonar.leak.period", "ignored");
-    underTest.execute(new TestComputationStepContext());
-
-    assertPeriod(LEAK_PERIOD_MODE_MANUAL_BASELINE, null, manualBaselineAnalysis.getCreatedAt(), manualBaselineAnalysis.getUuid());
-  }
-
-  @Test
-  public void feed_no_period_parameter_as_projectVersion_when_manual_baseline_has_project_version_and_no_codePeriod_version() {
+  public void feed_no_period_parameter_as_projectVersion_when_manual_baseline_has_project_version() {
     String projectVersion = randomAlphabetic(15);
     OrganizationDto organization = dbTester.organizations().insert();
     ComponentDto project = dbTester.components().insertMainBranch(organization);
@@ -415,13 +398,12 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   }
 
   @Test
-  @UseDataProvider("projectAndCodePeriodVersionsCombinations")
-  public void feed_no_period_parameter_as_version_event_version_when_manual_baseline_has_one_over_any_other_version(
-    @Nullable String codePeriodVersion, @Nullable String projectVersion) {
+  @UseDataProvider("projectVersionNullOrNot")
+  public void feed_no_period_parameter_as_version_event_version_when_manual_baseline_has_one(@Nullable String projectVersion) {
     String eventVersion = randomAlphabetic(15);
     OrganizationDto organization = dbTester.organizations().insert();
     ComponentDto project = dbTester.components().insertMainBranch(organization);
-    SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setCodePeriodVersion(codePeriodVersion).setProjectVersion(projectVersion));
+    SnapshotDto manualBaselineAnalysis = dbTester.components().insertSnapshot(project, t -> t.setProjectVersion(projectVersion));
     dbTester.events().insertEvent(EventTesting.newEvent(manualBaselineAnalysis).setCategory(CATEGORY_VERSION).setName(eventVersion));
     dbTester.components().setManualBaseline(project, manualBaselineAnalysis);
     when(analysisMetadataHolder.getBranch()).thenReturn(branchOf(project));
@@ -434,15 +416,10 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   }
 
   @DataProvider
-  public static Object[][] projectAndCodePeriodVersionsCombinations() {
-    String codePeriodVersion = randomAlphabetic(12);
-    String projectVersion = randomAlphabetic(15);
+  public static Object[][] projectVersionNullOrNot() {
     return new Object[][] {
-      {null, null},
-      {codePeriodVersion, null},
-      {codePeriodVersion, projectVersion},
-      {projectVersion, projectVersion},
-      {null, projectVersion}
+      {null},
+      {randomAlphabetic(15)},
     };
   }
 
@@ -614,11 +591,11 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   public void fail_with_MessageException_if_string_is_not_an_existing_version_event(String propertyValue) {
     OrganizationDto organization = dbTester.organizations().insert();
     ComponentDto project = dbTester.components().insertMainBranch(organization);
-    SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(false)); // 2008-11-11
-    SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setCodePeriodVersion("1.0").setLast(false)); // 2008-11-12
-    SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-20
-    SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-22
-    SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setCodePeriodVersion("1.1").setLast(true)); // 2008-11-29
+    SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11
+    SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12
+    SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20
+    SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setProjectVersion("1.1").setLast(false)); // 2008-11-22
+    SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29
     dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt()));
     dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt()));
     dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION).setDate(analysis4.getCreatedAt()));
@@ -717,11 +694,11 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   public void feed_period_by_previous_version() {
     OrganizationDto organization = dbTester.organizations().insert();
     ComponentDto project = dbTester.components().insertMainBranch(organization);
-    SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(false)); // 2008-11-11
-    SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setCodePeriodVersion("1.0").setLast(false)); // 2008-11-12
-    SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-20
-    SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-22
-    SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setCodePeriodVersion("1.1").setLast(true)); // 2008-11-29
+    SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11
+    SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12
+    SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20
+    SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setProjectVersion("1.1").setLast(false)); // 2008-11-22
+    SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29
     dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION).setDate(analysis1.getCreatedAt()));
     dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION).setDate(analysis2.getCreatedAt()));
     dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION).setDate(analysis4.getCreatedAt()));
@@ -743,9 +720,9 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   public void feed_period_by_previous_version_with_previous_version_deleted() {
     OrganizationDto organization = dbTester.organizations().insert();
     ComponentDto project = dbTester.components().insertMainBranch(organization);
-    SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(false)); // 2008-11-11
-    SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setCodePeriodVersion("1.0").setLast(false)); // 2008-11-12
-    SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-20
+    SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11
+    SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12
+    SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20
     dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION));
     // The "1.0" version was deleted from the history
     dbTester.events().insertEvent(newEvent(analysis3).setName("1.1").setCategory(CATEGORY_VERSION));
@@ -765,8 +742,8 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   public void feed_period_by_previous_version_with_first_analysis_when_no_previous_version_found() {
     OrganizationDto organization = dbTester.organizations().insert();
     ComponentDto project = dbTester.components().insertMainBranch(organization);
-    SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-11
-    SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setCodePeriodVersion("1.1").setLast(true)); // 2008-11-29
+    SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("1.1").setLast(false)); // 2008-11-11
+    SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29
     dbTester.events().insertEvent(newEvent(analysis2).setName("1.1").setCategory(CATEGORY_VERSION));
     when(system2Mock.now()).thenReturn(november30th2008.getTime());
     when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
@@ -785,7 +762,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   public void feed_period_by_previous_version_with_first_analysis_when_previous_snapshot_is_the_last_one() {
     OrganizationDto organization = dbTester.organizations().insert();
     ComponentDto project = dbTester.components().insertMainBranch(organization);
-    SnapshotDto analysis = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(true)); // 2008-11-11
+    SnapshotDto analysis = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(true)); // 2008-11-11
     dbTester.events().insertEvent(newEvent(analysis).setName("0.9").setCategory(CATEGORY_VERSION));
     when(system2Mock.now()).thenReturn(november30th2008.getTime());
     when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
@@ -803,11 +780,11 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   public void feed_period_by_version() {
     OrganizationDto organization = dbTester.organizations().insert();
     ComponentDto project = dbTester.components().insertMainBranch(organization);
-    SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(false)); // 2008-11-11
-    SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setCodePeriodVersion("1.0").setLast(false)); // 2008-11-12
-    SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-20
-    SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setCodePeriodVersion("1.1").setLast(false)); // 2008-11-22
-    SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setCodePeriodVersion("1.1").setLast(true)); // 2008-11-29
+    SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(false)); // 2008-11-11
+    SnapshotDto analysis2 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226494680000L).setProjectVersion("1.0").setLast(false)); // 2008-11-12
+    SnapshotDto analysis3 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227157200000L).setProjectVersion("1.1").setLast(false)); // 2008-11-20
+    SnapshotDto analysis4 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227358680000L).setProjectVersion("1.1").setLast(false)); // 2008-11-22
+    SnapshotDto analysis5 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1227934800000L).setProjectVersion("1.1").setLast(true)); // 2008-11-29
     dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION));
     dbTester.events().insertEvent(newEvent(analysis2).setName("1.0").setCategory(CATEGORY_VERSION));
     dbTester.events().insertEvent(newEvent(analysis5).setName("1.1").setCategory(CATEGORY_VERSION));
@@ -831,7 +808,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   public void feed_period_by_version_with_only_one_existing_version() {
     OrganizationDto organization = dbTester.organizations().insert();
     ComponentDto project = dbTester.components().insertMainBranch(organization);
-    SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setCodePeriodVersion("0.9").setLast(true)); // 2008-11-11
+    SnapshotDto analysis1 = dbTester.components().insertSnapshot(project, snapshot -> snapshot.setCreatedAt(1226379600000L).setProjectVersion("0.9").setLast(true)); // 2008-11-11
     dbTester.events().insertEvent(newEvent(analysis1).setName("0.9").setCategory(CATEGORY_VERSION));
     when(system2Mock.now()).thenReturn(november30th2008.getTime());
     when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(false);
@@ -878,7 +855,7 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   }
 
   private void setupRoot(ComponentDto project, String version) {
-    treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()).setCodePeriodVersion(version).build());
+    treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(project.uuid()).setKey(project.getKey()).setProjectVersion(version).build());
     when(configurationRepository.getConfiguration()).thenReturn(settings.asConfig());
   }
 
index 71a3aa1c713d5802f36b8571ce23a07a21d17af5..cbddab6f46e309d52d8a41e5023a50c40b5ff24d 100644 (file)
@@ -58,7 +58,7 @@ public class PersistEventsStepTest extends BaseStepTest {
   private static final long NOW = 1225630680000L;
   private static final ReportComponent ROOT = builder(PROJECT, 1)
     .setUuid("ABCD")
-    .setCodePeriodVersion("version_1")
+    .setProjectVersion("version_1")
     .addChildren(
       builder(DIRECTORY, 2)
         .setUuid("BCDE")
@@ -107,7 +107,7 @@ public class PersistEventsStepTest extends BaseStepTest {
     when(system2.now()).thenReturn(NOW);
     Component project = builder(PROJECT, 1)
       .setUuid("ABCD")
-      .setCodePeriodVersion("1.0")
+      .setProjectVersion("1.0")
       .addChildren(
         builder(DIRECTORY, 2)
           .setUuid("BCDE")
@@ -197,7 +197,7 @@ public class PersistEventsStepTest extends BaseStepTest {
 
     Component project = builder(PROJECT, 1)
       .setUuid(projectDto.uuid())
-      .setCodePeriodVersion("1.5-SNAPSHOT")
+      .setProjectVersion("1.5-SNAPSHOT")
       .addChildren(
         builder(DIRECTORY, 2)
           .setUuid("BCDE")
index aa11a4b2d4c8996ed51b2086c31eec35548ccb48..12251c53a1b00e8d8c1b1cbda17f24dac2f8260b 100644 (file)
@@ -60,12 +60,12 @@ import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.ERROR;
 import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.OK;
 
 public class QualityGateEventsStepTest {
-  private static final String PROJECT_VERSION = new Random().nextBoolean() ? null : randomAlphabetic(19);
+  private static final String PROJECT_VERSION = randomAlphabetic(19);
   private static final ReportComponent PROJECT_COMPONENT = ReportComponent.builder(Component.Type.PROJECT, 1)
     .setUuid("uuid 1")
     .setKey("key 1")
-    .setCodePeriodVersion("V1.9")
     .setProjectVersion(PROJECT_VERSION)
+    .setBuildString("V1.9")
     .addChildren(ReportComponent.builder(Component.Type.DIRECTORY, 2).build())
     .build();
   private static final String INVALID_ALERT_STATUS = "trololo";
@@ -182,7 +182,7 @@ public class QualityGateEventsStepTest {
     assertThat(notification.getType()).isEqualTo("alerts");
     assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
-    assertThat(notification.getFieldValue("codePeriodVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getCodePeriodVersion());
+    assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion());
     assertThat(notification.getFieldValue("branch")).isNull();
     assertThat(notification.getFieldValue("alertLevel")).isEqualTo(rawAlterStatus.name());
     assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel);
@@ -233,7 +233,7 @@ public class QualityGateEventsStepTest {
     assertThat(notification.getType()).isEqualTo("alerts");
     assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
-    assertThat(notification.getFieldValue("codePeriodVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getCodePeriodVersion());
+    assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion());
     assertThat(notification.getFieldValue("branch")).isNull();
     assertThat(notification.getFieldValue("alertLevel")).isEqualTo(newQualityGateStatus.getStatus().name());
     assertThat(notification.getFieldValue("alertName")).isEqualTo(expectedLabel);
@@ -263,7 +263,7 @@ public class QualityGateEventsStepTest {
     assertThat(notification.getType()).isEqualTo("alerts");
     assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
-    assertThat(notification.getFieldValue("codePeriodVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getCodePeriodVersion());
+    assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion());
     assertThat(notification.getFieldValue("branch")).isEqualTo(branchName);
 
     reset(measureRepository, eventRepository, notificationService);
@@ -285,7 +285,7 @@ public class QualityGateEventsStepTest {
     assertThat(notification.getType()).isEqualTo("alerts");
     assertThat(notification.getFieldValue("projectKey")).isEqualTo(PROJECT_COMPONENT.getKey());
     assertThat(notification.getFieldValue("projectName")).isEqualTo(PROJECT_COMPONENT.getName());
-    assertThat(notification.getFieldValue("codePeriodVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getCodePeriodVersion());
+    assertThat(notification.getFieldValue("projectVersion")).isEqualTo(PROJECT_COMPONENT.getProjectAttributes().getProjectVersion());
     assertThat(notification.getFieldValue("branch")).isEqualTo(null);
 
     reset(measureRepository, eventRepository, notificationService);
index 22e6835fc61af091827444b87e7bde4c1e670e8e..932c459716509ef83c11a0f6e40eb277543f3fdf 100644 (file)
  */
 package org.sonar.ce.task.projectanalysis.step;
 
-import com.tngtech.java.junit.dataprovider.DataProvider;
-import com.tngtech.java.junit.dataprovider.DataProviderRunner;
-import com.tngtech.java.junit.dataprovider.UseDataProvider;
 import java.util.List;
 import java.util.Optional;
-import javax.annotation.Nullable;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
-import org.junit.runner.RunWith;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
@@ -56,7 +51,6 @@ import static org.mockito.Mockito.when;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_DATE;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_VERSION;
 
-@RunWith(DataProviderRunner.class)
 public class ReportPersistAnalysisStepTest extends BaseStepTest {
 
   private static final String PROJECT_KEY = "PROJECT_KEY";
@@ -101,8 +95,8 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
   }
 
   @Test
-  @UseDataProvider("projectVersionOrNull")
-  public void persist_analysis(@Nullable String projectVersion) {
+  public void persist_analysis() {
+    String projectVersion = randomAlphabetic(10);
     OrganizationDto organizationDto = dbTester.organizations().insert();
     ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setDbKey(PROJECT_KEY).setName("Project");
     dbClient.componentDao().insert(dbTester.getSession(), projectDto);
@@ -120,7 +114,6 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
     Component project = ReportComponent.builder(Component.Type.PROJECT, 1)
       .setUuid("ABCD")
       .setKey(PROJECT_KEY)
-      .setCodePeriodVersion("1.0")
       .setProjectVersion(projectVersion)
       .setBuildString(buildString)
       .addChildren(directory)
@@ -138,7 +131,6 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
     SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
     assertThat(projectSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID);
     assertThat(projectSnapshot.getComponentUuid()).isEqualTo(project.getUuid());
-    assertThat(projectSnapshot.getCodePeriodVersion()).isEqualTo("1.0");
     assertThat(projectSnapshot.getProjectVersion()).isEqualTo(projectVersion);
     assertThat(projectSnapshot.getBuildString()).isEqualTo(buildString);
     assertThat(projectSnapshot.getLast()).isFalse();
@@ -150,14 +142,6 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
     assertThat(dbIdsRepository.getComponentId(file)).isEqualTo(fileDto.getId());
   }
 
-  @DataProvider
-  public static Object[][] projectVersionOrNull() {
-    return new Object[][] {
-      {null},
-      {randomAlphabetic(17)}
-    };
-  }
-
   @Test
   public void persist_snapshots_with_leak_period() {
     OrganizationDto organizationDto = dbTester.organizations().insert();
index f50cb10f08da32ba2715aff1da1132c895138c0f..f9b53d98b598cb433341b4222a9b07742314ce6d 100644 (file)
@@ -96,7 +96,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
 
   private static final Component FILE = builder(Type.FILE, 11).build();
   private static final Component PROJECT = builder(Type.PROJECT, 1)
-    .setCodePeriodVersion(randomAlphanumeric(10))
+    .setProjectVersion(randomAlphanumeric(10))
     .addChildren(FILE).build();
 
   @Rule
@@ -509,7 +509,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
   private NewIssuesNotification createNewIssuesNotificationMock() {
     NewIssuesNotification notification = mock(NewIssuesNotification.class);
     when(notification.setProject(any(), any(), any(), any())).thenReturn(notification);
-    when(notification.setCodePeriodVersion(any())).thenReturn(notification);
+    when(notification.setProjectVersion(any())).thenReturn(notification);
     when(notification.setAnalysisDate(any())).thenReturn(notification);
     when(notification.setStatistics(any(), any())).thenReturn(notification);
     when(notification.setDebt(any())).thenReturn(notification);
@@ -520,7 +520,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
     MyNewIssuesNotification notification = mock(MyNewIssuesNotification.class);
     when(notification.setAssignee(any(UserDto.class))).thenReturn(notification);
     when(notification.setProject(any(), any(), any(), any())).thenReturn(notification);
-    when(notification.setCodePeriodVersion(any())).thenReturn(notification);
+    when(notification.setProjectVersion(any())).thenReturn(notification);
     when(notification.setAnalysisDate(any())).thenReturn(notification);
     when(notification.setStatistics(any(), any())).thenReturn(notification);
     when(notification.setDebt(any())).thenReturn(notification);
index 603fe2a6a037c2f2d6863022db49c38c0cf12241..9f7937dd0cfa6dc78387df3146dd168410d2f384 100644 (file)
@@ -111,7 +111,6 @@ public class ViewsPersistAnalysisStepTest extends BaseStepTest {
     SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.uuid());
     assertThat(viewSnapshot.getUuid()).isEqualTo(ANALYSIS_UUID);
     assertThat(viewSnapshot.getComponentUuid()).isEqualTo(view.getUuid());
-    assertThat(viewSnapshot.getCodePeriodVersion()).isNull();
     assertThat(viewSnapshot.getProjectVersion()).isNull();
     assertThat(viewSnapshot.getLast()).isFalse();
     assertThat(viewSnapshot.getStatus()).isEqualTo("U");
index d6c8766fc2e616c177497f45867c17cd9e52857c..7cdbdba7c519645a4cc3841dd5792ea5979fcbcc 100644 (file)
@@ -24,6 +24,7 @@ import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.commons.lang.StringUtils.trimToNull;
 
 public final class SnapshotDto {
 
@@ -33,6 +34,7 @@ public final class SnapshotDto {
   public static final String STATUS_UNPROCESSED = "U";
   public static final String STATUS_PROCESSED = "P";
   public static final int MAX_VERSION_LENGTH = 100;
+  public static final int MAX_BUILD_STRING_LENGTH = 100;
 
   private Long id;
   private String uuid;
@@ -41,7 +43,7 @@ public final class SnapshotDto {
   private Long buildDate;
   private String status = STATUS_UNPROCESSED;
   private Boolean last;
-  private String codePeriodVersion;
+  // maps to "version" column in the table
   private String projectVersion;
   private String buildString;
   private String periodMode;
@@ -102,36 +104,15 @@ public final class SnapshotDto {
     return this;
   }
 
-  /**
-   * Version is only available on projects and modules
-   */
-  @CheckForNull
-  public String getCodePeriodVersion() {
-    return codePeriodVersion;
-  }
-
-  public SnapshotDto setCodePeriodVersion(@Nullable String codePeriodVersion) {
-    checkVersion(codePeriodVersion, "codePeriodVersion");
-    this.codePeriodVersion = codePeriodVersion;
-    return this;
-  }
-
-  private static void checkVersion(@Nullable String version, String versionLabel) {
-    if (version != null) {
-      checkArgument(version.length() <= MAX_VERSION_LENGTH,
-        "%s length (%s) is longer than the maximum authorized (%s). '%s' was provided.", versionLabel, version.length(), MAX_VERSION_LENGTH, version);
+  private static void checkLength(int maxLength, @Nullable String s, String label) {
+    if (s != null) {
+      checkArgument(s.length() <= maxLength,
+        "%s length (%s) is longer than the maximum authorized (%s). '%s' was provided.", label, s.length(), maxLength, s);
     }
   }
 
-  /**
-   * Used by MyBatis
-   */
-  private void setRawCodePeriodVersion(@Nullable String codePeriodVersion) {
-    this.codePeriodVersion = codePeriodVersion;
-  }
-
   public SnapshotDto setProjectVersion(@Nullable String projectVersion) {
-    checkVersion(projectVersion, "projectVersion");
+    checkLength(MAX_VERSION_LENGTH, projectVersion, "projectVersion");
     this.projectVersion = projectVersion;
     return this;
   }
@@ -145,7 +126,7 @@ public final class SnapshotDto {
    * Used by MyBatis
    */
   private void setRawProjectVersion(@Nullable String projectVersion) {
-    this.projectVersion = projectVersion;
+    this.projectVersion = trimToNull(projectVersion);
   }
 
   @CheckForNull
@@ -154,10 +135,18 @@ public final class SnapshotDto {
   }
 
   public SnapshotDto setBuildString(@Nullable String buildString) {
+    checkLength(MAX_BUILD_STRING_LENGTH, buildString, "buildString");
     this.buildString = buildString;
     return this;
   }
 
+  /**
+   * Used by MyBatis
+   */
+  private void setRawBuildString(@Nullable String buildString) {
+    this.buildString = trimToNull(buildString);
+  }
+
   public SnapshotDto setPeriodMode(@Nullable String p) {
     periodMode = p;
     return this;
@@ -216,8 +205,8 @@ public final class SnapshotDto {
       Objects.equals(buildDate, that.buildDate) &&
       Objects.equals(status, that.status) &&
       Objects.equals(last, that.last) &&
-      Objects.equals(codePeriodVersion, that.codePeriodVersion) &&
       Objects.equals(projectVersion, that.projectVersion) &&
+      Objects.equals(buildString, that.buildString) &&
       Objects.equals(periodMode, that.periodMode) &&
       Objects.equals(periodParam, that.periodParam) &&
       Objects.equals(periodDate, that.periodDate);
@@ -225,7 +214,7 @@ public final class SnapshotDto {
 
   @Override
   public int hashCode() {
-    return Objects.hash(id, uuid, componentUuid, createdAt, buildDate, status, last, codePeriodVersion, projectVersion, periodMode, periodParam, periodDate);
+    return Objects.hash(id, uuid, componentUuid, createdAt, buildDate, status, last, projectVersion, buildString, periodMode, periodParam, periodDate);
   }
 
   @Override
@@ -238,8 +227,8 @@ public final class SnapshotDto {
       ", buildDate=" + buildDate +
       ", status='" + status + '\'' +
       ", last=" + last +
-      ", codePeriodVersion='" + codePeriodVersion + '\'' +
       ", projectVersion='" + projectVersion + '\'' +
+      ", buildString='" + buildString + '\'' +
       ", periodMode='" + periodMode + '\'' +
       ", periodParam='" + periodParam + '\'' +
       ", periodDate=" + periodDate +
index 4b11d58891384293c9a55b1af16e003fafe9783b..89b54eeb7cb79a8c2b23441725649418f2d6784f 100644 (file)
@@ -46,7 +46,7 @@ public final class SnapshotQuery {
   private Long createdAfter;
   private Long createdBefore;
   private String status;
-  private String codePeriodVersion;
+  private String projectVersion;
   private Boolean isLast;
   private String sortField;
   private String sortOrder;
@@ -108,12 +108,12 @@ public final class SnapshotQuery {
   }
 
   @CheckForNull
-  public String getCodePeriodVersion() {
-    return codePeriodVersion;
+  public String getProjectVersion() {
+    return projectVersion;
   }
 
-  public SnapshotQuery setCodePeriodVersion(@Nullable String codePeriodVersion) {
-    this.codePeriodVersion = codePeriodVersion;
+  public SnapshotQuery setProjectVersion(@Nullable String projectVersion) {
+    this.projectVersion = projectVersion;
     return this;
   }
 
index 15fd82615495757544a570ea730130595ca95737..7c760b5d5df022ad14db6b9bfce3e3514ef92add 100644 (file)
@@ -10,8 +10,7 @@
     s.build_date as buildDate,
     s.status as status,
     s.islast as last,
-    s.version as rawCodePeriodVersion,
-    s.project_version as rawProjectVersion,
+    s.version as rawProjectVersion,
     s.build_string as buildString,
     s.period1_mode as periodMode,
     s.period1_param as periodParam,
@@ -73,8 +72,8 @@
       <if test="query.status != null">
         AND s.status=#{query.status,jdbcType=VARCHAR}
       </if>
-      <if test="query.codePeriodVersion != null">
-        AND s.version=#{query.codePeriodVersion,jdbcType=VARCHAR}
+      <if test="query.projectVersion != null">
+        AND s.version=#{query.projectVersion,jdbcType=VARCHAR}
       </if>
       <if test="query.isLast != null">
         AND s.islast=#{query.isLast}
 
   <update id="update" parameterType="Snapshot">
     update snapshots
-    set version = #{codePeriodVersion, jdbcType=VARCHAR},
+    set version = #{projectVersion, jdbcType=VARCHAR},
         status = #{status, jdbcType=VARCHAR}
     where uuid = #{uuid,jdbcType=VARCHAR}
   </update>
       status,
       islast,
       version,
-      project_version,
       build_string,
       period1_mode,
       period1_param,
       #{buildDate, jdbcType=BIGINT},
       #{status, jdbcType=VARCHAR},
       #{last, jdbcType=BOOLEAN},
-      #{codePeriodVersion, jdbcType=VARCHAR},
       #{projectVersion, jdbcType=VARCHAR},
       #{buildString, jdbcType=VARCHAR},
       #{periodMode, jdbcType=VARCHAR},
index 8041a7b6e60e0bf5712d99bc434a7fda0d3c2291..62592fb6d8248e2dc53d9e0fd915d9d0bc699860 100644 (file)
  */
 package org.sonar.db.component;
 
+import com.tngtech.java.junit.dataprovider.DataProvider;
+import com.tngtech.java.junit.dataprovider.DataProviderRunner;
+import com.tngtech.java.junit.dataprovider.UseDataProvider;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 import java.util.Optional;
+import javax.annotation.Nullable;
 import org.apache.commons.lang.StringUtils;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
@@ -43,6 +48,7 @@ import static java.util.Collections.singletonList;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
 import static org.apache.commons.lang.math.RandomUtils.nextLong;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
 import static org.assertj.core.groups.Tuple.tuple;
 import static org.sonar.db.ce.CeActivityDto.Status.CANCELED;
 import static org.sonar.db.ce.CeActivityDto.Status.SUCCESS;
@@ -54,6 +60,7 @@ import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.ASC;
 import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.DESC;
 import static org.sonar.db.component.SnapshotTesting.newAnalysis;
 
+@RunWith(DataProviderRunner.class)
 public class SnapshotDaoTest {
 
   @Rule
@@ -76,8 +83,8 @@ public class SnapshotDaoTest {
       .setPeriodMode("days")
       .setPeriodParam("30")
       .setPeriodDate(1500000000001L)
-      .setCodePeriodVersion("2.1-SNAPSHOT")
-      .setProjectVersion("2.1.0.2336")
+      .setProjectVersion("2.1.0")
+      .setBuildString("2.1.0.2336")
       .setBuildDate(1500000000006L)
       .setCreatedAt(1403042400000L));
 
@@ -87,14 +94,13 @@ public class SnapshotDaoTest {
     assertThat(result.getComponentUuid()).isEqualTo(project.uuid());
     assertThat(result.getStatus()).isEqualTo("P");
     assertThat(result.getLast()).isTrue();
-    assertThat(result.getCodePeriodVersion()).isEqualTo("2.1-SNAPSHOT");
-    assertThat(result.getProjectVersion()).isEqualTo("2.1.0.2336");
+    assertThat(result.getProjectVersion()).isEqualTo("2.1.0");
+    assertThat(result.getBuildString()).isEqualTo("2.1.0.2336");
     assertThat(result.getPeriodMode()).isEqualTo("days");
     assertThat(result.getPeriodModeParameter()).isEqualTo("30");
     assertThat(result.getPeriodDate()).isEqualTo(1500000000001L);
     assertThat(result.getBuildDate()).isEqualTo(1500000000006L);
     assertThat(result.getCreatedAt()).isEqualTo(1403042400000L);
-    assertThat(result.getCodePeriodVersion()).isEqualTo("2.1-SNAPSHOT");
 
     assertThat(underTest.selectByUuid(db.getSession(), "DOES_NOT_EXIST").isPresent()).isFalse();
   }
@@ -152,14 +158,14 @@ public class SnapshotDaoTest {
     assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery())).hasSize(6);
 
     assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD").setSort(BY_DATE, ASC)))
-      .extracting(SnapshotDto::getId, SnapshotDto::getCodePeriodVersion, SnapshotDto::getProjectVersion)
+      .extracting(SnapshotDto::getId, SnapshotDto::getProjectVersion, SnapshotDto::getBuildString)
       .containsOnly(
         tuple(1L, "2.0-SNAPSHOT", "2.0.0.2363"),
         tuple(2L, "2.1-SNAPSHOT", "2.1.0.11"),
         tuple(3L, "2.2-SNAPSHOT", "2.2.0.8869")
       );
     assertThat(underTest.selectAnalysesByQuery(db.getSession(), new SnapshotQuery().setComponentUuid("ABCD").setSort(BY_DATE, DESC)))
-      .extracting(SnapshotDto::getId, SnapshotDto::getCodePeriodVersion, SnapshotDto::getProjectVersion)
+      .extracting(SnapshotDto::getId, SnapshotDto::getProjectVersion, SnapshotDto::getBuildString)
       .containsOnly(
         tuple(3L, "2.2-SNAPSHOT", "2.2.0.8869"),
         tuple(2L, "2.1-SNAPSHOT", "2.1.0.11"),
@@ -300,7 +306,7 @@ public class SnapshotDaoTest {
       .setPeriodMode("days")
       .setPeriodParam("30")
       .setPeriodDate(1500000000001L)
-      .setCodePeriodVersion("2.1-SNAPSHOT")
+      .setProjectVersion("2.1-SNAPSHOT")
       .setBuildDate(1500000000006L)
       .setCreatedAt(1403042400000L));
 
@@ -314,8 +320,36 @@ public class SnapshotDaoTest {
     assertThat(dto.getPeriodDate()).isEqualTo(1500000000001L);
     assertThat(dto.getBuildDate()).isEqualTo(1500000000006L);
     assertThat(dto.getCreatedAt()).isEqualTo(1403042400000L);
-    assertThat(dto.getCodePeriodVersion()).isEqualTo("2.1-SNAPSHOT");
+    assertThat(dto.getProjectVersion()).isEqualTo("2.1-SNAPSHOT");
+  }
+
+  @Test
+  @UseDataProvider("nullAndEmptyNonEmptyStrings")
+  public void insert_with_null_and_empty_and_non_empty_projectVersion(@Nullable String projectVersion) {
+    ComponentDto project = db.components().insertPrivateProject();
+
+    SnapshotDto dto = underTest.insert(db.getSession(), newAnalysis(project).setProjectVersion(projectVersion));
 
+    assertThat(dto.getProjectVersion()).isEqualTo(projectVersion);
+  }
+
+  @Test
+  @UseDataProvider("nullAndEmptyNonEmptyStrings")
+  public void insert_with_null_and_empty_and_non_empty_buildString(@Nullable String buildString) {
+    ComponentDto project = db.components().insertPrivateProject();
+
+    SnapshotDto dto = underTest.insert(db.getSession(), newAnalysis(project).setBuildString(buildString));
+
+    assertThat(dto.getBuildString()).isEqualTo(buildString);
+  }
+
+  @DataProvider
+  public static Object[][] nullAndEmptyNonEmptyStrings() {
+    return new Object[][] {
+      {null},
+      {""},
+      {randomAlphanumeric(7)},
+    };
   }
 
   @Test
@@ -386,31 +420,17 @@ public class SnapshotDaoTest {
     db.commit();
     analysis
       .setComponentUuid("P42")
-      .setCodePeriodVersion("5.6.3")
+      .setProjectVersion("5.6.3")
       .setStatus(STATUS_UNPROCESSED);
 
     underTest.update(dbSession, analysis);
 
     SnapshotDto result = underTest.selectByUuid(dbSession, "A1").get();
-    assertThat(result.getCodePeriodVersion()).isEqualTo("5.6.3");
+    assertThat(result.getProjectVersion()).isEqualTo("5.6.3");
     assertThat(result.getStatus()).isEqualTo(STATUS_UNPROCESSED);
     assertThat(result.getComponentUuid()).isEqualTo("P1");
   }
 
-  @Test
-  public void snashotDto_can_hold_version_larger_than_100_read_from_database() {
-    SnapshotDto analysis = insertAnalysis("P1", "A1", STATUS_PROCESSED, false);
-    db.commit();
-    String tooLongVersion = StringUtils.repeat("d", 200);
-    db.executeUpdateSql("update snapshots set version='" + tooLongVersion + "' where uuid='" + analysis.getUuid() + "'");
-    db.commit();
-
-    assertThat(underTest.selectByUuid(dbSession, analysis.getUuid())
-      .map(SnapshotDto::getCodePeriodVersion))
-        .contains(tooLongVersion);
-
-  }
-
   private SnapshotDto insertAnalysis(String projectUuid, String uuid, String status, boolean isLastFlag) {
     SnapshotDto snapshot = newAnalysis(newPrivateProjectDto(OrganizationTesting.newOrganizationDto(), projectUuid))
       .setLast(isLastFlag)
@@ -432,7 +452,7 @@ public class SnapshotDaoTest {
       .setComponentUuid("uuid_3")
       .setStatus("P")
       .setLast(true)
-      .setCodePeriodVersion("2.1-SNAPSHOT")
+      .setProjectVersion("2.1-SNAPSHOT")
       .setPeriodMode("days1")
       .setPeriodParam("30")
       .setPeriodDate(1_500_000_000_001L)
index bc5eaa6a8a8449c1b6cbf776ec23b098f037c090..7ce0746dac1a55c3de81d390c42563355d2b04e3 100644 (file)
@@ -39,7 +39,8 @@ public class SnapshotDtoTest {
       .setBuildDate(parseDate("2014-07-02").getTime())
       .setComponentUuid("uuid_21")
       .setLast(true)
-      .setCodePeriodVersion("1.0")
+      .setProjectVersion("1.0")
+      .setBuildString("1.0.1.123")
       .setPeriodMode("mode1")
       .setPeriodParam("param1")
       .setPeriodDate(parseDate("2014-06-01").getTime());
@@ -48,24 +49,40 @@ public class SnapshotDtoTest {
     assertThat(snapshotDto.getBuildDate()).isEqualTo(parseDate("2014-07-02").getTime());
     assertThat(snapshotDto.getComponentUuid()).isEqualTo("uuid_21");
     assertThat(snapshotDto.getLast()).isTrue();
-    assertThat(snapshotDto.getCodePeriodVersion()).isEqualTo("1.0");
+    assertThat(snapshotDto.getProjectVersion()).isEqualTo("1.0");
+    assertThat(snapshotDto.getBuildString()).isEqualTo("1.0.1.123");
     assertThat(snapshotDto.getPeriodMode()).isEqualTo("mode1");
     assertThat(snapshotDto.getPeriodModeParameter()).isEqualTo("param1");
     assertThat(snapshotDto.getPeriodDate()).isEqualTo(parseDate("2014-06-01").getTime());
   }
 
   @Test
-  public void fail_if_version_name_is_longer_then_100_characters() {
+  public void fail_if_projectVersion_is_longer_then_100_characters() {
     SnapshotDto snapshotDto = new SnapshotDto();
-    snapshotDto.setCodePeriodVersion(null);
-    snapshotDto.setCodePeriodVersion("1.0");
-    snapshotDto.setCodePeriodVersion(repeat("a", 100));
+    snapshotDto.setProjectVersion(null);
+    snapshotDto.setProjectVersion("1.0");
+    snapshotDto.setProjectVersion(repeat("a", 100));
 
     expectedException.expect(IllegalArgumentException.class);
-    expectedException.expectMessage("codePeriodVersion" +
+    expectedException.expectMessage("projectVersion" +
       " length (101) is longer than the maximum authorized (100). " +
       "'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' was provided.");
 
-    snapshotDto.setCodePeriodVersion(repeat("a", 101));
+    snapshotDto.setProjectVersion(repeat("a", 101));
+  }
+
+  @Test
+  public void fail_if_buildString_is_longer_then_100_characters() {
+    SnapshotDto snapshotDto = new SnapshotDto();
+    snapshotDto.setBuildString(null);
+    snapshotDto.setBuildString("1.0");
+    snapshotDto.setBuildString(repeat("a", 100));
+
+    expectedException.expect(IllegalArgumentException.class);
+    expectedException.expectMessage("buildString" +
+      " length (101) is longer than the maximum authorized (100). " +
+      "'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' was provided.");
+
+    snapshotDto.setBuildString(repeat("a", 101));
   }
 }
index 95ab68f91079bd480cf1c393c610984d5cd64eaa..2faa3bba864abfe4c09c34e74e47740768c6128b 100644 (file)
@@ -33,7 +33,7 @@ public class SnapshotQueryTest {
       .setComponentUuid("abcd")
       .setIsLast(true)
       .setStatus("P")
-      .setCodePeriodVersion("1.0")
+      .setProjectVersion("1.0")
       .setCreatedAfter(10L)
       .setCreatedBefore(20L)
       .setSort(BY_DATE, ASC);
@@ -41,7 +41,7 @@ public class SnapshotQueryTest {
     assertThat(query.getComponentUuid()).isEqualTo("abcd");
     assertThat(query.getIsLast()).isTrue();
     assertThat(query.getStatus()).isEqualTo("P");
-    assertThat(query.getCodePeriodVersion()).isEqualTo("1.0");
+    assertThat(query.getProjectVersion()).isEqualTo("1.0");
     assertThat(query.getCreatedAfter()).isEqualTo(10L);
     assertThat(query.getCreatedBefore()).isEqualTo(20L);
     assertThat(query.getSortField()).isEqualTo("created_at");
index c772a438cd81391a6ad3f7b5559a62b8152068a2..d9fbfce6e4fcc5eaec7c063726ac296aeb3a2e21 100644 (file)
@@ -399,7 +399,7 @@ public class PurgeDaoTest {
         .setComponentUuid(PROJECT_UUID)
         .setStatus(STATUS_PROCESSED)
         .setLast(false)
-        .setCodePeriodVersion("V5")
+        .setProjectVersion("V5")
     };
     db.components().insertSnapshots(analyses);
     db.events().insertEvent(EventTesting.newEvent(analyses[4])
index 79cc26947fd8df7d4c5902e3a9e2cf0b7b6d1474..f957a9bcc64e34f5770a2ffe0a8687fca534af06 100644 (file)
@@ -47,7 +47,7 @@
              created_at="1228172400001"
              build_date="1317247200000"
              version="2.0-SNAPSHOT"
-             project_version="2.0.0.2363"
+             build_string="2.0.0.2363"
   />
   <snapshots id="2"
              uuid="u2"
@@ -73,7 +73,7 @@
              created_at="1228172400002"
              build_date="1317247200000"
              version="2.1-SNAPSHOT"
-             project_version="2.1.0.11"
+             build_string="2.1.0.11"
   />
   <snapshots id="3"
              uuid="u3"
@@ -99,7 +99,7 @@
              created_at="1228172400003"
              build_date="1317247200000"
              version="2.2-SNAPSHOT"
-             project_version="2.2.0.8869"
+             build_string="2.2.0.8869"
   />
 
   <!-- PROJECT_ID = 2 -->
              created_at="1228172400000"
              build_date="1317247200000"
              version="2.1-SNAPSHOT"
-             project_version="2.1.0.66"
+             build_string="2.1.0.66"
   />
   <!-- Unprocessed snapshot -->
   <snapshots organization_uuid="org1"
              created_at="1228172400000"
              build_date="1317247200000"
              version="2.1-SNAPSHOT"
-             project_version="2.1.0.1"
+             build_string="2.1.0.1"
   />
 
   <!-- PROJECT_ID = 3 - no last snapshot -->
              created_at="1228172400000"
              build_date="1317247200000"
              version="2.1-SNAPSHOT"
-             project_version="2.1.0.5586"
+             build_string="2.1.0.5586"
   />
 
   <!-- PROJECT_ID = 4 - no snapshot -->
index cd557d47d64f2230efccb0af506193f502dded43..65580d20ca0d3b15592ba9b03a5d2bdb1d6a8a07 100644 (file)
@@ -51,7 +51,7 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate {
   static final String FIELD_PROJECT_NAME = "projectName";
   static final String FIELD_PROJECT_KEY = "projectKey";
   static final String FIELD_PROJECT_DATE = "projectDate";
-  static final String FIELD_CODE_PERIOD_VERSION = "codePeriodVersion";
+  static final String FIELD_PROJECT_VERSION = "projectVersion";
   static final String FIELD_ASSIGNEE = "assignee";
   static final String FIELD_BRANCH = "branch";
   static final String FIELD_PULL_REQUEST = "pullRequest";
@@ -89,7 +89,7 @@ public abstract class AbstractNewIssuesEmailTemplate extends EmailTemplate {
     if (pullRequest!= null) {
       message.append("Pull request: ").append(pullRequest).append(NEW_LINE);
     }
-    String version = notification.getFieldValue(FIELD_CODE_PERIOD_VERSION);
+    String version = notification.getFieldValue(FIELD_PROJECT_VERSION);
     if (version != null) {
       message.append("Version: ").append(version).append(NEW_LINE);
     }
index 5cac9b570039453a33e60c970886edc2b8361e27..b50ca9ca2a1d9b6011b233ee1cfb45de04f4bec8 100644 (file)
@@ -47,7 +47,7 @@ import org.sonar.server.issue.notification.NewIssuesStatistics.Metric;
 import static java.util.stream.Collectors.toMap;
 import static java.util.stream.Collectors.toSet;
 import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_BRANCH;
-import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_CODE_PERIOD_VERSION;
+import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_PROJECT_VERSION;
 import static org.sonar.server.issue.notification.AbstractNewIssuesEmailTemplate.FIELD_PULL_REQUEST;
 import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_DATE;
 import static org.sonar.server.issue.notification.NewIssuesEmailTemplate.FIELD_PROJECT_KEY;
@@ -92,9 +92,9 @@ public class NewIssuesNotification extends Notification {
     return this;
   }
 
-  public NewIssuesNotification setCodePeriodVersion(@Nullable String version) {
+  public NewIssuesNotification setProjectVersion(@Nullable String version) {
     if (version != null) {
-      setFieldValue(FIELD_CODE_PERIOD_VERSION, version);
+      setFieldValue(FIELD_PROJECT_VERSION, version);
     }
     return this;
   }
index 9c4afbd0e532ed71e25bddd5665f1945ece72c3b..519ac52d5026eb8f771aa530941a18e5c53240d0 100644 (file)
@@ -50,7 +50,7 @@ public class AlertsEmailTemplate extends EmailTemplate {
     String projectId = notification.getFieldValue("projectId");
     String projectKey = notification.getFieldValue("projectKey");
     String projectName = notification.getFieldValue("projectName");
-    String projectVersion = notification.getFieldValue("codePeriodVersion");
+    String projectVersion = notification.getFieldValue("projectVersion");
     String branchName = notification.getFieldValue("branch");
     String alertName = notification.getFieldValue("alertName");
     String alertText = notification.getFieldValue("alertText");
index 3482a1c64971a462eff950afa0d5b693426ed9f1..633799f7c2aa986e3112f6ebba05d59389508568 100644 (file)
@@ -120,7 +120,7 @@ public class MyNewIssuesEmailTemplateTest {
   @Test
   public void format_email_with_no_assignees_tags_nor_components() {
     Notification notification = newNotification(32)
-      .setFieldValue("codePeriodVersion", "52.0");
+      .setFieldValue("projectVersion", "52.0");
 
     EmailMessage message = underTest.format(notification);
 
@@ -140,7 +140,7 @@ public class MyNewIssuesEmailTemplateTest {
   @Test
   public void format_email_with_issue_on_branch() {
     Notification notification = newNotification(32)
-      .setFieldValue("codePeriodVersion", "52.0")
+      .setFieldValue("projectVersion", "52.0")
       .setFieldValue("branch", "feature1");
 
     EmailMessage message = underTest.format(notification);
index e5f8cf062533e937d0a3beffd39303bce29ba148..6a78053a360aa5f76ac15bcf6a10a8a17d26cb9c 100644 (file)
@@ -88,7 +88,7 @@ public class NewIssuesEmailTemplateTest {
   @Test
   public void format_email_with_all_fields_filled() {
     Notification notification = newNotification(32)
-      .setFieldValue("codePeriodVersion", "42.1.1");
+      .setFieldValue("projectVersion", "42.1.1");
     addAssignees(notification);
     addRules(notification);
     addTags(notification);
@@ -179,7 +179,7 @@ public class NewIssuesEmailTemplateTest {
   public void format_email_with_issue_on_branch_with_version() {
     Notification notification = newNotification(32)
       .setFieldValue("branch", "feature1")
-      .setFieldValue("codePeriodVersion", "42.1.1");
+      .setFieldValue("projectVersion", "42.1.1");
 
     EmailMessage message = template.format(notification);
 
index 660de8f91e7ce40dc99a351fbc8db0694b3fde66..c7f54833a889c480422da18f477042968ac947dc 100644 (file)
@@ -85,16 +85,16 @@ public class NewIssuesNotificationTest {
   public void set_project_version() {
     String version = randomAlphanumeric(5);
 
-    underTest.setCodePeriodVersion(version);
+    underTest.setProjectVersion(version);
 
-    assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_CODE_PERIOD_VERSION)).isEqualTo(version);
+    assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_VERSION)).isEqualTo(version);
   }
 
   @Test
   public void set_project_version_supports_null() {
-    underTest.setCodePeriodVersion(null);
+    underTest.setProjectVersion(null);
 
-    assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_CODE_PERIOD_VERSION)).isNull();
+    assertThat(underTest.getFieldValue(NewIssuesEmailTemplate.FIELD_PROJECT_VERSION)).isNull();
   }
 
   @Test
index 6ff44a2b6ae25b7c3646b78c482ed737b78fedc1..6f83c3c744105b7f279950a7cb1104a324a00307 100644 (file)
@@ -71,7 +71,7 @@ class ComponentDtoToWsComponent {
       analysis -> {
         wsComponent.setAnalysisDate(formatDateTime(analysis.getCreatedAt()));
         ofNullable(analysis.getPeriodDate()).ifPresent(leak -> wsComponent.setLeakPeriodDate(formatDateTime(leak)));
-        ofNullable(analysis.getCodePeriodVersion()).ifPresent(wsComponent::setVersion);
+        ofNullable(analysis.getProjectVersion()).ifPresent(wsComponent::setVersion);
       });
     if (QUALIFIERS_WITH_VISIBILITY.contains(dto.qualifier())) {
       wsComponent.setVisibility(Visibility.getLabel(dto.isPrivate()));
index 0b15bb9970a12b0b08d1665ed2de1ef4bbe87a93..a3dbb8e75a0152c2ff1dca089b3f6d914023805e 100644 (file)
@@ -127,7 +127,7 @@ public class CreateEventAction implements ProjectAnalysesWsAction {
   private EventDto insertDbEvent(DbSession dbSession, CreateEventRequest request, SnapshotDto analysis) {
     EventDto dbEvent = dbClient.eventDao().insert(dbSession, toDbEvent(request, analysis));
     if (VERSION.equals(request.getCategory())) {
-      analysis.setCodePeriodVersion(request.getName());
+      analysis.setProjectVersion(request.getName());
       dbClient.snapshotDao().update(dbSession, analysis);
     }
     dbSession.commit();
index ef7cf3849fa3864e7055ff32084bf5b7ad3b3291..e02e5c5a9b4267e2e2e86309fe3cbd8c35f73c16 100644 (file)
@@ -92,7 +92,7 @@ public class DeleteEventAction implements ProjectAnalysesWsAction {
       SnapshotDto analysis = dbClient.snapshotDao().selectByUuid(dbSession, dbEvent.getAnalysisUuid())
         .orElseThrow(() -> new IllegalStateException(format("Analysis '%s' not found", dbEvent.getAnalysisUuid())));
       checkArgument(!analysis.getLast(), "Cannot delete the version event of last analysis");
-      analysis.setCodePeriodVersion(null);
+      analysis.setProjectVersion(null);
       dbClient.snapshotDao().update(dbSession, analysis);
     }
     dbClient.eventDao().delete(dbSession, dbEvent.getUuid());
index 9801a104d25709d5675f0e3ad61af545f2951763..6e15593c4af8cd2b53a286ed0e797224e0d60ca5 100644 (file)
@@ -83,7 +83,6 @@ class SearchResponseBuilder {
       .setKey(dbAnalysis.getUuid())
       .setDate(formatDateTime(dbAnalysis.getCreatedAt()))
       .setManualNewCodePeriodBaseline(searchData.getManualBaseline().filter(dbAnalysis.getUuid()::equals).isPresent());
-    ofNullable(dbAnalysis.getCodePeriodVersion()).ifPresent(builder::setCodePeriodVersion);
     ofNullable(dbAnalysis.getProjectVersion()).ifPresent(builder::setProjectVersion);
     ofNullable(dbAnalysis.getBuildString()).ifPresent(builder::setBuildString);
 
index c63827aea3669c3cd586a9fd186b884fee3ff521..d9ac06544dc2d269f8f5e1af2937b47710464dd0 100644 (file)
@@ -119,7 +119,7 @@ public class UpdateEventAction implements ProjectAnalysesWsAction {
       dbClient.eventDao().update(dbSession, event.getUuid(), event.getName(), event.getDescription());
       if (VERSION.getLabel().equals(event.getCategory())) {
         SnapshotDto analysis = getAnalysis(dbSession, event);
-        analysis.setCodePeriodVersion(event.getName());
+        analysis.setProjectVersion(event.getName());
         dbClient.snapshotDao().update(dbSession, analysis);
       }
       dbSession.commit();
index d602f73e9f79684acbfd6f89947e46fac3400d01..aec992515718e9b3cb944281dff80c5d02715316 100644 (file)
@@ -229,7 +229,7 @@ public class ComponentAction implements NavigationWsAction {
     List<Page> pages = pageRepository.getComponentPages(false, component.qualifier());
     writeExtensions(json, component, pages);
     if (analysis != null) {
-      json.prop("version", analysis.getCodePeriodVersion())
+      json.prop("version", analysis.getProjectVersion())
         .prop("analysisDate", formatDateTime(new Date(analysis.getCreatedAt())));
     }
   }
index 64aa94bdb4766792c398f260fbf5384e685ee9ad..7a49308d9f0621925c65be89b6ad6f139506e1d9 100644 (file)
@@ -276,7 +276,7 @@ public class ShowActionTest {
     ComponentDto module = db.components().insertComponent(newModuleDto(project));
     ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
     ComponentDto file = db.components().insertComponent(newFileDto(directory));
-    db.components().insertSnapshot(project, s -> s.setCodePeriodVersion("1.1"));
+    db.components().insertSnapshot(project, s -> s.setProjectVersion("1.1"));
     userSession.addProjectPermission(USER, project);
 
     ShowWsResponse response = newRequest(null, file.getDbKey());
@@ -296,7 +296,7 @@ public class ShowActionTest {
     ComponentDto module = db.components().insertComponent(newModuleDto(branch));
     ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
     ComponentDto file = db.components().insertComponent(newFileDto(directory));
-    db.components().insertSnapshot(branch, s -> s.setCodePeriodVersion("1.1"));
+    db.components().insertSnapshot(branch, s -> s.setProjectVersion("1.1"));
 
     ShowWsResponse response = ws.newRequest()
       .setParam(PARAM_COMPONENT, file.getKey())
@@ -322,7 +322,7 @@ public class ShowActionTest {
     ComponentDto module = db.components().insertComponent(newModuleDto(branch));
     ComponentDto directory = db.components().insertComponent(newDirectory(module, "dir"));
     ComponentDto file = db.components().insertComponent(newFileDto(directory));
-    db.components().insertSnapshot(branch, s -> s.setCodePeriodVersion("1.1"));
+    db.components().insertSnapshot(branch, s -> s.setProjectVersion("1.1"));
 
     ShowWsResponse response = ws.newRequest()
       .setParam(PARAM_COMPONENT, file.getKey())
@@ -448,7 +448,7 @@ public class ShowActionTest {
       .setQualifier(Qualifiers.PROJECT)
       .setTagsString("language, plugin"));
     db.components().insertSnapshot(project, snapshot -> snapshot
-      .setCodePeriodVersion("1.1")
+      .setProjectVersion("1.1")
       .setCreatedAt(parseDateTime("2017-03-01T11:39:03+0100").getTime())
       .setPeriodDate(parseDateTime("2017-01-01T11:39:03+0100").getTime()));
     ComponentDto directory = newDirectory(project, "AVIF-FfgA3Ax6PH2efPF", "src/main/java/com/sonarsource/markdown/impl")
index 560df67dfe985a5b98d8bb68220b89821fa92b1f..164abbbaf7253c628a9a2847637c3e422aaa78f8 100644 (file)
@@ -128,7 +128,7 @@ public class AlertsEmailTemplateTest {
   @Test
   public void shouldFormatNewAlertWithoutVersion() {
     Notification notification = createNotification("Red (was Green)", "violations > 4", "ERROR", "true")
-        .setFieldValue("codePeriodVersion", null);
+        .setFieldValue("projectVersion", null);
 
     EmailMessage message = template.format(notification);
     assertThat(message.getMessageId(), is("alerts/45"));
@@ -200,7 +200,7 @@ public class AlertsEmailTemplateTest {
         .setFieldValue("projectName", "Foo")
         .setFieldValue("projectKey", "org.sonar.foo:foo")
         .setFieldValue("projectId", "45")
-        .setFieldValue("codePeriodVersion", "V1-SNAP")
+        .setFieldValue("projectVersion", "V1-SNAP")
         .setFieldValue("alertName", alertName)
         .setFieldValue("alertText", alertText)
         .setFieldValue("alertLevel", alertLevel)
index 6f25952f6bfde703d5b038c50b0662da90f6b119..ea90b01fee41b25430c419cb2d34a85667e19f2c 100644 (file)
@@ -144,7 +144,7 @@ public class CreateEventActionTest {
     call(VERSION.name(), "5.6.3", analysis.getUuid());
 
     Optional<SnapshotDto> newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid());
-    assertThat(newAnalysis.get().getCodePeriodVersion()).isEqualTo("5.6.3");
+    assertThat(newAnalysis.get().getProjectVersion()).isEqualTo("5.6.3");
   }
 
   @Test
@@ -156,7 +156,7 @@ public class CreateEventActionTest {
     CreateEventResponse result = call(OTHER.name(), "Project Import", analysis.getUuid());
 
     SnapshotDto newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get();
-    assertThat(analysis.getCodePeriodVersion()).isEqualTo(newAnalysis.getCodePeriodVersion());
+    assertThat(analysis.getProjectVersion()).isEqualTo(newAnalysis.getProjectVersion());
     ProjectAnalyses.Event wsEvent = result.getEvent();
     assertThat(wsEvent.getKey()).isNotEmpty();
     assertThat(wsEvent.getCategory()).isEqualTo(OTHER.name());
index 59fa8707de03193bd5dbf60a6c199b44130313d2..5f1390f5f31711ee240b885697b66bd157799434 100644 (file)
@@ -76,20 +76,20 @@ public class DeleteEventActionTest {
   @Test
   public void delete_version_event() {
     ComponentDto project = db.components().insertPrivateProject();
-    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setCodePeriodVersion("5.6.3").setLast(false));
+    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setProjectVersion("5.6.3").setLast(false));
     db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel()));
     logInAsProjectAdministrator(project);
 
     call("E1");
 
     SnapshotDto newAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get();
-    assertThat(newAnalysis.getCodePeriodVersion()).isNull();
+    assertThat(newAnalysis.getProjectVersion()).isNull();
   }
 
   @Test
   public void fail_if_version_for_last_analysis() {
     ComponentDto project = db.components().insertPrivateProject();
-    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setCodePeriodVersion("5.6.3").setLast(true));
+    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setProjectVersion("5.6.3").setLast(true));
     db.events().insertEvent(newEvent(analysis).setUuid("E1").setCategory(VERSION.getLabel()));
     logInAsProjectAdministrator(project);
 
index ce8f057c75bf810978c30101bab7e6e1389c9385..7d8647b5d5c83ca693a9ef2a1ec5d1e17ae56d42 100644 (file)
@@ -121,7 +121,7 @@ public class UpdateEventActionTest {
     call("E1", "6.3");
 
     SnapshotDto updatedAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get();
-    assertThat(updatedAnalysis.getCodePeriodVersion()).isEqualTo("6.3");
+    assertThat(updatedAnalysis.getProjectVersion()).isEqualTo("6.3");
   }
 
   @Test
@@ -132,7 +132,7 @@ public class UpdateEventActionTest {
     call("E1", "6.3");
 
     SnapshotDto updatedAnalysis = dbClient.snapshotDao().selectByUuid(dbSession, analysis.getUuid()).get();
-    assertThat(updatedAnalysis.getCodePeriodVersion()).isEqualTo("5.6");
+    assertThat(updatedAnalysis.getProjectVersion()).isEqualTo("5.6");
   }
 
   @Test
@@ -256,7 +256,7 @@ public class UpdateEventActionTest {
 
   private SnapshotDto createAnalysisAndLogInAsProjectAdministrator(String version) {
     ComponentDto project = db.components().insertPrivateProject();
-    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setCodePeriodVersion(version));
+    SnapshotDto analysis = db.components().insertSnapshot(newAnalysis(project).setProjectVersion(version));
     logInAsProjectAdministrator(project);
     return analysis;
   }
index 3769f7f7a4b30ac3070ecfc7c0bc986a51da20b6..78791469832af9086391c99d9792b41fd5eaa3ba 100644 (file)
@@ -157,7 +157,7 @@ public class ComponentActionTest {
     ComponentDto project = insertOrganizationAndProject();
     db.components().insertSnapshot(project, snapshot -> snapshot
       .setCreatedAt(parseDateTime("2015-04-22T11:44:00+0200").getTime())
-      .setCodePeriodVersion("3.14"));
+      .setProjectVersion("3.14"));
     userSession.addProjectPermission(UserRole.USER, project);
     init();
 
@@ -530,7 +530,7 @@ public class ComponentActionTest {
     componentDbTester.insertComponent(project);
     SnapshotDto analysis = newAnalysis(project)
       .setCreatedAt(parseDateTime("2016-12-06T11:44:00+0200").getTime())
-      .setCodePeriodVersion("6.3")
+      .setProjectVersion("6.3")
       .setLast(true);
     componentDbTester.insertSnapshot(analysis);
     when(resourceTypes.get(project.qualifier())).thenReturn(DefaultResourceTypes.get().getRootType());
index 368072b7eff467907a315a4ea25ace9c6880bcf3..1fbd5925c0e278cb3db78fe197fb10c6910ecff8 100644 (file)
@@ -146,7 +146,6 @@ public interface CoreProperties {
   @Deprecated
   String PROJECT_BRANCH_PROPERTY = "sonar.branch";
   String PROJECT_VERSION_PROPERTY = "sonar.projectVersion";
-  String CODE_PERIOD_VERSION_PROPERTY = "sonar.codePeriodVersion";
   String BUILD_STRING_PROPERTY = "sonar.buildString";
 
   /**
index 6c00301f47363081e9a441125f1414f2fe6c7950..b8bc5760fa4bab570a9b78afbafd877aeec04e82 100644 (file)
@@ -32,7 +32,6 @@ import org.sonar.api.utils.MessageException;
 
 import static java.lang.String.format;
 import static org.sonar.api.CoreProperties.BUILD_STRING_PROPERTY;
-import static org.sonar.api.CoreProperties.CODE_PERIOD_VERSION_PROPERTY;
 import static org.sonar.api.CoreProperties.PROJECT_VERSION_PROPERTY;
 
 /**
@@ -46,7 +45,6 @@ public class ProjectInfo implements Startable {
 
   private Date analysisDate;
   private String projectVersion;
-  private String codePeriodVersion;
   private String buildString;
 
   public ProjectInfo(Configuration settings, Clock clock) {
@@ -62,10 +60,6 @@ public class ProjectInfo implements Startable {
     return Optional.ofNullable(projectVersion);
   }
 
-  public Optional<String> getCodePeriodVersion() {
-    return Optional.ofNullable(codePeriodVersion);
-  }
-
   public Optional<String> getBuildString() {
     return Optional.ofNullable(buildString);
   }
@@ -96,10 +90,6 @@ public class ProjectInfo implements Startable {
       .map(StringUtils::trimToNull)
       .filter(validateLengthLimit("project version"))
       .orElse(null);
-    this.codePeriodVersion = settings.get(CODE_PERIOD_VERSION_PROPERTY)
-      .map(StringUtils::trimToNull)
-      .filter(validateLengthLimit("codePeriod version"))
-      .orElse(projectVersion);
     this.buildString = settings.get(BUILD_STRING_PROPERTY)
       .map(StringUtils::trimToNull)
       .filter(validateLengthLimit("buildString"))
index ae97aedbf7a2d6427f8754f43fd79b9c0de20135..69891747295eba28533a91e8fd792e2cde7a3080 100644 (file)
@@ -89,7 +89,6 @@ public class MetadataPublisher implements ReportPublisherStep {
       .setCrossProjectDuplicationActivated(cpdSettings.isCrossProjectDuplicationEnabled())
       .setRootComponentRef(rootProject.scannerId());
     projectInfo.getProjectVersion().ifPresent(builder::setProjectVersion);
-    projectInfo.getCodePeriodVersion().ifPresent(builder::setCodePeriodVersion);
     projectInfo.getBuildString().ifPresent(builder::setBuildString);
 
     properties.organizationKey().ifPresent(builder::setOrganizationKey);
index 6786709a6b79ae9a9d4bd6bead0a2dde83b82de1..a882ca0afcf865369b2b9da60c595bb7791364c4 100644 (file)
@@ -112,54 +112,54 @@ public class ProjectInfoTest {
   }
 
   @Test
-  @UseDataProvider("projectVersions")
-  public void getCodePeriodVersion_has_value_of_projectVersion_if_property_is_unset(@Nullable String projectVersion) {
+  @UseDataProvider("emptyOrNullString")
+  public void getProjectVersion_is_empty_if_property_is_empty_or_null(@Nullable String projectVersion) {
     settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
     settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, projectVersion);
 
     underTest.start();
 
-    if (projectVersion == null) {
-      assertThat(underTest.getCodePeriodVersion()).isEmpty();
-    } else {
-      assertThat(underTest.getCodePeriodVersion()).contains(projectVersion);
-    }
+    assertThat(underTest.getProjectVersion()).isEmpty();
   }
 
   @Test
-  @UseDataProvider("projectVersions")
-  public void getCodePeriodVersion_is_empty_if_property_is_empty(@Nullable String projectVersion) {
+  public void getProjectVersion_contains_value_of_property() {
+    String value = RandomStringUtils.randomAlphabetic(10);
     settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
-    settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, projectVersion);
-    settings.setProperty(CoreProperties.CODE_PERIOD_VERSION_PROPERTY, "");
+    settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, value);
 
     underTest.start();
 
-    if (projectVersion == null) {
-      assertThat(underTest.getCodePeriodVersion()).isEmpty();
-    } else {
-      assertThat(underTest.getCodePeriodVersion()).contains(projectVersion);
-    }
+    assertThat(underTest.getProjectVersion()).contains(value);
   }
 
   @Test
-  @UseDataProvider("projectVersions")
-  public void getCodePeriodVersion_contains_value_of_property(@Nullable String projectVersion) {
-    String version = RandomStringUtils.randomAlphabetic(10);
+  @UseDataProvider("emptyOrNullString")
+  public void getBuildString_is_empty_if_property_is_empty_or_null(@Nullable String buildString) {
     settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
-    settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, projectVersion);
-    settings.setProperty(CoreProperties.CODE_PERIOD_VERSION_PROPERTY, version);
+    settings.setProperty(CoreProperties.BUILD_STRING_PROPERTY, buildString);
+
+    underTest.start();
+
+    assertThat(underTest.getBuildString()).isEmpty();
+  }
+
+  @Test
+  public void getBuildString_contains_value_of_property() {
+    String value = RandomStringUtils.randomAlphabetic(10);
+    settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01");
+    settings.setProperty(CoreProperties.BUILD_STRING_PROPERTY, value);
 
     underTest.start();
 
-    assertThat(underTest.getCodePeriodVersion()).contains(version);
+    assertThat(underTest.getBuildString()).contains(value);
   }
 
   @DataProvider
-  public static Object[][] projectVersions() {
+  public static Object[][] emptyOrNullString() {
     return new Object[][] {
+      {""},
       {null},
-      {randomAlphabetic(12)}
     };
   }
 }
index 75043c9997d4b38e48fc00006cd20b2665a4aecd..f7df36536d944c951d11d3e8d993f033266d91ec 100644 (file)
@@ -215,33 +215,6 @@ public class MetadataPublisherTest {
     };
   }
 
-  @Test
-  @UseDataProvider("codePeriodVersions")
-  public void write_codePeriod_version(@Nullable String codePeriodVersion, String expected) throws Exception {
-    when(projectInfo.getCodePeriodVersion()).thenReturn(Optional.ofNullable(codePeriodVersion));
-    when(properties.organizationKey()).thenReturn(Optional.of("SonarSource"));
-
-    File outputDir = temp.newFolder();
-    ScannerReportWriter writer = new ScannerReportWriter(outputDir);
-
-    underTest.publish(writer);
-
-    ScannerReportReader reader = new ScannerReportReader(outputDir);
-    ScannerReport.Metadata metadata = reader.readMetadata();
-    assertThat(metadata.getCodePeriodVersion()).isEqualTo(expected);
-  }
-
-  @DataProvider
-  public static Object[][] codePeriodVersions() {
-    String randomVersion = randomAlphabetic(15);
-    return new Object[][] {
-      {null, ""},
-      {"", ""},
-      {"5.6.3", "5.6.3"},
-      {randomVersion, randomVersion}
-    };
-  }
-
   @Test
   @UseDataProvider("buildStrings")
   public void write_buildString(@Nullable String buildString, String expected) throws Exception {
index b809619222acc03773cd40e7c54c154469828458..c6dd243c9958e282648dbfc6453a455805a13203 100644 (file)
@@ -50,8 +50,7 @@ message Metadata {
   map<string, string> modules_project_relative_path_by_key = 15;
 
   string projectVersion = 16;
-  string codePeriodVersion = 17;
-  string buildString = 18;
+  string buildString = 17;
 
   message QProfile {
     string key = 1;
index 891c5e52565d4d90ed067399c10932c67885a647..bde8d5aad80becfb120c994056e641d35ce1fecc 100644 (file)
@@ -56,10 +56,9 @@ message Analysis {
   optional string key = 1;
   optional string date = 2;
   repeated Event events = 3;
-  optional string codePeriodVersion = 4;
-  optional string projectVersion = 5;
+  optional string projectVersion = 4;
+  optional string buildString = 5;
   optional bool manualNewCodePeriodBaseline = 6;
-  optional string buildString = 7;
 }
 
 message QualityGate {