]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9142 Remove 'previous_analysis' option
authorEric Hartmann <hartmann.eric@gmail.com>
Thu, 19 Oct 2017 11:47:56 +0000 (13:47 +0200)
committerEric Hartmann <hartmann.eric@gmail.Com>
Fri, 20 Oct 2017 10:26:58 +0000 (12:26 +0200)
22 files changed:
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java
server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersion.java [new file with mode: 0644]
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67Test.java
server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersionTest.java [new file with mode: 0644]
server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersionTest/properties.sql [new file with mode: 0644]
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PeriodResolver.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortAggregatorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistAnalysisStepTest.java
sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java
sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java
tests/src/test/java/org/sonarqube/tests/issue/NewIssuesMeasureTest.java
tests/src/test/java/org/sonarqube/tests/measure/DifferentialPeriodsTest.java
tests/src/test/java/org/sonarqube/tests/measure/MeasuresWsTest.java
tests/src/test/java/org/sonarqube/tests/measure/TimeMachineTest.java
tests/src/test/java/org/sonarqube/tests/projectSearch/LeakProjectsPageTest.java
tests/src/test/java/org/sonarqube/tests/projectSearch/SearchProjectsTest.java
tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateNotificationTest.java
tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java
tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java
tests/src/test/java/org/sonarqube/tests/qualityModel/NewDebtRatioMeasureTest.java
tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtAndIssueNewMeasuresTest.java

index c6eddef0edab8259af5486e127c0fd0cf88e2bac..0f06e00377e7ad0f87a5c07b9da5fa9841b6cb71 100644 (file)
@@ -32,6 +32,7 @@ public class DbVersion67 implements DbVersion {
       .add(1833, "Cleanup disabled users", CleanupDisabledUsers.class)
       .add(1834, "Set WEBHOOK_DELIVERIES.CE_TASK_UUID as nullable", UpdateCeTaskUuidColumnToNullableOnWebhookDeliveries.class)
       .add(1835, "Populate WEBHOOK_DELIVERIES.ANALYSIS_UUID", PopulateAnalysisUuidColumnOnWebhookDeliveries.class)
+      .add(1836, "Migrate 'previous_analysis' leak periods to 'previous_version'", MigratePreviousAnalysisToPreviousVersion.class)
     ;
   }
 }
diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersion.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersion.java
new file mode 100644 (file)
index 0000000..8f3e954
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+package org.sonar.server.platform.db.migration.version.v67;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.server.platform.db.migration.step.DataChange;
+import org.sonar.server.platform.db.migration.step.MassUpdate;
+
+public class MigratePreviousAnalysisToPreviousVersion extends DataChange {
+
+  public MigratePreviousAnalysisToPreviousVersion(Database db) {
+    super(db);
+  }
+
+  @Override
+  protected void execute(Context context) throws SQLException {
+    MassUpdate massUpdate = context.prepareMassUpdate();
+    massUpdate.select("select id from properties " +
+      " where prop_key = 'sonar.leak.period' and text_value='previous_analysis'");
+    massUpdate.update("update properties " +
+      " set text_value='previous_version', " +
+      " clob_value = null " +
+      " where id = ?");
+    massUpdate.rowPluralName("leak periods");
+    massUpdate.execute((row, update) -> {
+      update.setLong(1, row.getLong(1));
+      return true;
+    });
+  }
+}
index dc54ab65e84fed6685f4ba384e5819b197896c44..de678701f0bf525031df4c0961dd02601c30ba10 100644 (file)
@@ -36,7 +36,7 @@ public class DbVersion67Test {
 
   @Test
   public void verify_migration_count() {
-    verifyMigrationCount(underTest, 6);
+    verifyMigrationCount(underTest, 7);
   }
 
 }
diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersionTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersionTest.java
new file mode 100644 (file)
index 0000000..11de20c
--- /dev/null
@@ -0,0 +1,104 @@
+package org.sonar.server.platform.db.migration.version.v67;/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.stream.Collectors;
+import javax.annotation.Nullable;
+import org.assertj.core.groups.Tuple;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+
+public class MigratePreviousAnalysisToPreviousVersionTest {
+
+  private final static String SELECT_PROPERTIES = "SELECT prop_key, is_empty, text_value, clob_value FROM properties";
+
+  @Rule
+  public CoreDbTester db = CoreDbTester.createForSchema(MigratePreviousAnalysisToPreviousVersionTest.class, "properties.sql");
+
+  private MigratePreviousAnalysisToPreviousVersion underTest = new MigratePreviousAnalysisToPreviousVersion(db.database());
+
+  @Test
+  public void migration_must_update_the_database() throws SQLException {
+    insertProperty("sonar.leak.period", "any.value_here", null, false);
+    insertProperty("sonar.leak.period", "previous_version", null, false);
+    insertProperty("sonar.leak.period", "previous_analysis", null, false);
+    insertProperty("whatever.property", "nothingspecial", null, false);
+    insertProperty("whatever.property", null, "nothing.special", false);
+
+    underTest.execute();
+
+    assertPropertyContainsInAnyOrder(
+      tuple("sonar.leak.period", "any.value_here", null, false),
+      tuple("sonar.leak.period", "previous_version", null, false),
+      tuple("sonar.leak.period", "previous_version", null, false), // Single change
+      tuple("whatever.property", "nothingspecial", null, false),
+      tuple("whatever.property", null, "nothing.special", false)
+    );
+  }
+
+  @Test
+  public void migration_must_be_reentrant() throws SQLException {
+    insertProperty("sonar.leak.period", "any.value_here", null, false);
+    insertProperty("sonar.leak.period", "previous_version", null, false);
+    insertProperty("sonar.leak.period", "previous_analysis", null, false);
+    insertProperty("whatever.property", "nothingspecial", null, false);
+    insertProperty("whatever.property", null, "nothing.special", false);
+
+    underTest.execute();
+    underTest.execute();
+
+    assertPropertyContainsInAnyOrder(
+      tuple("sonar.leak.period", "any.value_here", null, false),
+      tuple("sonar.leak.period", "previous_version", null, false),
+      tuple("sonar.leak.period", "previous_version", null, false), // Single change
+      tuple("whatever.property", "nothingspecial", null, false),
+      tuple("whatever.property", null, "nothing.special", false)
+    );
+  }
+
+  @Test
+  public void migration_is_doing_nothing_when_no_data() throws SQLException {
+    assertThat(db.countRowsOfTable("properties")).isEqualTo(0);
+    underTest.execute();
+    assertThat(db.countRowsOfTable("properties")).isEqualTo(0);
+  }
+
+  private void insertProperty(String propKey, @Nullable String textValue, @Nullable String clobValue, boolean isEmpty) {
+    HashMap<String, Object> map = new HashMap<>();
+    map.put("PROP_KEY", propKey);
+    map.put("TEXT_VALUE", textValue);
+    map.put("CLOB_VALUE", clobValue);
+    map.put("IS_EMPTY", isEmpty);
+    db.executeInsert("PROPERTIES", map);
+  }
+
+  private void assertPropertyContainsInAnyOrder(Tuple... tuples) {
+    assertThat(db.select(SELECT_PROPERTIES)
+      .stream()
+      .map(p -> new Tuple(p.get("PROP_KEY"), p.get("TEXT_VALUE"), p.get("CLOB_VALUE"), p.get("IS_EMPTY")))
+      .collect(Collectors.toList()))
+      .containsExactlyInAnyOrder(tuples);
+  }
+}
diff --git a/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersionTest/properties.sql b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersionTest/properties.sql
new file mode 100644 (file)
index 0000000..d84c238
--- /dev/null
@@ -0,0 +1,11 @@
+CREATE TABLE "PROPERTIES" (
+  "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+  "PROP_KEY" VARCHAR(512) NOT NULL,
+  "RESOURCE_ID" INTEGER,
+  "USER_ID" INTEGER,
+  "IS_EMPTY" BOOLEAN NOT NULL,
+  "TEXT_VALUE" VARCHAR(4000),
+  "CLOB_VALUE" CLOB,
+  "CREATED_AT" BIGINT
+);
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES" ("PROP_KEY");
index 7a21affa5ac9e444b9316e0023ac0487b15de178..606cdcaca78e2038eaab2755a0b1ccf21b14dbb9 100644 (file)
@@ -38,7 +38,6 @@ import org.sonar.server.computation.task.projectanalysis.period.Period;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_DATE;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_DAYS;
-import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_VERSION;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_VERSION;
 import static org.sonar.db.component.SnapshotDto.STATUS_PROCESSED;
@@ -70,10 +69,6 @@ public class PeriodResolver {
     if (StringUtils.isBlank(propertyValue)) {
       return null;
     }
-    if (propertyValue.equals(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS)) {
-      LOG.warn("Leak period is set to deprecated value '{}'. This value will be removed in next SonarQube LTS, please use another one instead.",
-        LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS);
-    }
     Period period = resolve(propertyValue);
     if (period == null && StringUtils.isNotBlank(propertyValue)) {
       LOG.debug("Property " + LEAK_PERIOD + " is not valid: " + propertyValue);
@@ -91,9 +86,6 @@ public class PeriodResolver {
     if (date != null) {
       return findByDate(date);
     }
-    if (StringUtils.equals(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS, property)) {
-      return findByPreviousAnalysis();
-    }
     if (StringUtils.equals(LEAK_PERIOD_MODE_PREVIOUS_VERSION, property)) {
       return findByPreviousVersion();
     }
@@ -121,16 +113,6 @@ public class PeriodResolver {
     return new Period(LEAK_PERIOD_MODE_DAYS, String.valueOf(days), snapshot.getCreatedAt(), snapshot.getUuid());
   }
 
-  @CheckForNull
-  private Period findByPreviousAnalysis() {
-    SnapshotDto snapshot = findFirstSnapshot(session, createCommonQuery(projectUuid).setCreatedBefore(analysisDate).setIsLast(true).setSort(BY_DATE, DESC));
-    if (snapshot == null) {
-      return null;
-    }
-    LOG.debug("Compare to previous analysis ({})", formatDate(snapshot.getCreatedAt()));
-    return new Period(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS, formatDate(snapshot.getCreatedAt()), snapshot.getCreatedAt(), snapshot.getUuid());
-  }
-
   @CheckForNull
   private Period findByPreviousVersion() {
     if (currentVersion == null) {
index f567083f309aa308cfe509bdc9bfdccab6049839..64a19ba9da09ceb61806e83fb93bde2fd96aab3f 100644 (file)
@@ -45,11 +45,11 @@ import static org.sonar.api.measures.CoreMetrics.NEW_TECHNICAL_DEBT_KEY;
 import static org.sonar.api.rules.RuleType.BUG;
 import static org.sonar.api.rules.RuleType.CODE_SMELL;
 import static org.sonar.api.rules.RuleType.VULNERABILITY;
-import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS;
+import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_VERSION;
 
 public class NewEffortAggregatorTest {
 
-  private static final Period PERIOD = new Period(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS, null, 1_500_000_000L, "U1");
+  private static final Period PERIOD = new Period(LEAK_PERIOD_MODE_PREVIOUS_VERSION, null, 1_500_000_000L, "U1");
   private static final long[] OLD_ISSUES_DATES = new long[] {
     PERIOD.getSnapshotDate(),
     PERIOD.getSnapshotDate() - 1,
index 8d45b82f8a71d0a1da73f31609cc7681fad59fcc..9a1a708bc6e8544fcb2d45da5d63fa9fd17f7dcc 100644 (file)
@@ -24,6 +24,7 @@ import java.text.SimpleDateFormat;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 import org.junit.runner.RunWith;
 import org.sonar.api.config.internal.MapSettings;
 import org.sonar.api.utils.System2;
@@ -46,7 +47,6 @@ import static org.mockito.Mockito.mock;
 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_DAYS;
-import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_VERSION;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_VERSION;
 
@@ -66,6 +66,8 @@ public class LoadPeriodsStepTest extends BaseStepTest {
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
   @Rule
   public LogTester logTester = new LogTester();
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
 
   private PeriodHolderImpl periodsHolder = new PeriodHolderImpl();
   private DbClient dbClient = dbTester.getDbClient();
@@ -231,49 +233,6 @@ public class LoadPeriodsStepTest extends BaseStepTest {
     assertThat(periodsHolder.getPeriod()).isNull();
   }
 
-  @Test
-  public void feed_period_by_previous_analysis() {
-    setupRoot(PROJECT_ROOT);
-    dbTester.prepareDbUnit(getClass(), "shared.xml");
-    settings.setProperty("sonar.leak.period", "previous_analysis");
-
-    underTest.execute();
-
-    // return analysis from 2008-11-29
-    Period period = periodsHolder.getPeriod();
-    assertThat(period).isNotNull();
-    assertThat(period.getMode()).isEqualTo(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS);
-    assertThat(period.getModeParameter()).isNotNull();
-    assertThat(period.getSnapshotDate()).isEqualTo(1227934800000L);
-    assertThat(period.getAnalysisUuid()).isEqualTo("u1004");
-
-    assertThat(logTester.logs(LoggerLevel.DEBUG)).hasSize(1);
-    assertThat(logTester.logs(LoggerLevel.DEBUG).get(0)).startsWith("Compare to previous analysis (");
-  }
-
-  @Test
-  public void no_period_by_previous_analysis() {
-    setupRoot(PROJECT_ROOT);
-    dbTester.prepareDbUnit(getClass(), "empty.xml");
-    settings.setProperty("sonar.leak.period", "previous_analysis");
-
-    underTest.execute();
-
-    assertThat(periodsHolder.getPeriod()).isNull();
-  }
-
-  @Test
-  public void display_warning_log_when_using_previous_analysis() {
-    setupRoot(PROJECT_ROOT);
-    dbTester.prepareDbUnit(getClass(), "shared.xml");
-    settings.setProperty("sonar.leak.period", "previous_analysis");
-
-    underTest.execute();
-
-    assertThat(logTester.logs(LoggerLevel.WARN))
-      .containsOnly("Leak period is set to deprecated value 'previous_analysis'. This value will be removed in next SonarQube LTS, please use another one instead.");
-  }
-
   @Test
   public void feed_period_by_previous_version() {
     setupRoot(PROJECT_ROOT);
index 3a3bb64bdd871a75c3125c5f0f943aca0732fda4..aa1ba90c9a46308fd420244afb7daa0aec77dec7 100644 (file)
@@ -46,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 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_ANALYSIS;
+import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_VERSION;
 
 public class ReportPersistAnalysisStepTest extends BaseStepTest {
 
@@ -157,7 +157,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
 
   @Test
   public void only_persist_snapshots_with_leak_period_on_project_and_module() {
-    periodsHolder.setPeriod(new Period(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS, null, analysisDate, "u1"));
+    periodsHolder.setPeriod(new Period(LEAK_PERIOD_MODE_PREVIOUS_VERSION, null, analysisDate, "u1"));
 
     OrganizationDto organizationDto = dbTester.organizations().insert();
     ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setDbKey(PROJECT_KEY).setName("Project");
@@ -190,7 +190,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest {
     underTest.execute();
 
     SnapshotDto newProjectSnapshot = getUnprocessedSnapshot(projectDto.uuid());
-    assertThat(newProjectSnapshot.getPeriodMode()).isEqualTo(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS);
+    assertThat(newProjectSnapshot.getPeriodMode()).isEqualTo(LEAK_PERIOD_MODE_PREVIOUS_VERSION);
   }
 
   @Test
index 7aaecf3a41fdc8bfdb6cfda5d18325fa026c4349..4b05e3bae424e1f46e65b63e79be71109b436018 100644 (file)
@@ -33,7 +33,6 @@ import static org.apache.commons.lang.StringUtils.isNotBlank;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_DATE;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_DAYS;
-import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_VERSION;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_VERSION;
 
@@ -92,8 +91,6 @@ public class Periods {
         return labelForDays(param, date, shortLabel);
       case LEAK_PERIOD_MODE_VERSION:
         return labelForVersion(param, date, shortLabel);
-      case LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS:
-        return labelForPreviousAnalysis(date, shortLabel);
       case LEAK_PERIOD_MODE_PREVIOUS_VERSION:
         return labelForPreviousVersion(param, date, shortLabel);
       case LEAK_PERIOD_MODE_DATE:
@@ -117,13 +114,6 @@ public class Periods {
     return label("since_version_detailed", shortLabel, param, date);
   }
 
-  private String labelForPreviousAnalysis(@Nullable String date, boolean shortLabel) {
-    if (date == null) {
-      return label("since_previous_analysis", shortLabel);
-    }
-    return label("since_previous_analysis_detailed", shortLabel, date);
-  }
-
   private String labelForPreviousVersion(@Nullable String param, @Nullable String date, boolean shortLabel) {
     if (param == null && date == null) {
       return label("since_previous_version", shortLabel);
@@ -156,7 +146,7 @@ public class Periods {
       checkArgument(isNotBlank(periodProperty), "Period property should not be empty");
       Integer possibleDaysValue = findByDays(periodProperty);
       Date possibleDatesValue = findByDate(periodProperty);
-      if (LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS.equals(periodProperty) || LEAK_PERIOD_MODE_PREVIOUS_VERSION.equals(periodProperty)) {
+      if (LEAK_PERIOD_MODE_PREVIOUS_VERSION.equals(periodProperty)) {
         mode = periodProperty;
       } else if (possibleDaysValue != null) {
         mode = LEAK_PERIOD_MODE_DAYS;
index 7c307f066dbb1eccc6ac504c7fe3b47a8f447115..c3f137b2a96a41c7e6f49dc3b8d0654db9dbcb92 100644 (file)
@@ -37,7 +37,6 @@ import static org.sonar.api.utils.DateUtils.parseDate;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_DATE;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_DAYS;
-import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_PREVIOUS_VERSION;
 import static org.sonar.core.config.CorePropertyDefinitions.LEAK_PERIOD_MODE_VERSION;
 
@@ -128,43 +127,6 @@ public class PeriodsTest {
     verify(i18n).message(any(Locale.class), eq("since_version"), isNull(String.class), eq(VERSION));
   }
 
-  @Test
-  public void return_since_previous_analysis_label_when_no_date() {
-    periods.label(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS, null, (String) null);
-
-    verify(i18n).message(any(Locale.class), eq("since_previous_analysis"), isNull(String.class));
-  }
-
-  @Test
-  public void return_since_previous_analysis_abbreviation_when_no_date() {
-    periods.abbreviation(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS, null, null);
-
-    verify(i18n).message(any(Locale.class), eq("since_previous_analysis.short"), isNull(String.class));
-  }
-
-  @Test
-  public void return_since_previous_analysis_detailed_label_when_date_is_set() {
-    periods.label(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS, null, STRING_DATE);
-
-    verify(i18n).message(any(Locale.class), eq("since_previous_analysis_detailed"), isNull(String.class), eq(STRING_DATE));
-  }
-
-  @Test
-  public void return_since_previous_analysis_detailed_abbreviation_when_date_is_set() {
-    periods.abbreviation(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS, null, DATE);
-
-    verify(i18n).message(any(Locale.class), eq("since_previous_analysis_detailed.short"), isNull(String.class), anyString());
-  }
-
-  @Test
-  public void return_since_previous_analysis_label_using_settings() {
-    settings.setProperty(LEAK_PERIOD + PERIOD_INDEX, LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS);
-
-    periods.label(PERIOD_INDEX);
-
-    verify(i18n).message(any(Locale.class), eq("since_previous_analysis"), isNull(String.class));
-  }
-
   @Test
   public void return_since_previous_version_label_when_no_param() {
     periods.label(LEAK_PERIOD_MODE_PREVIOUS_VERSION, null, (String) null);
index 40a5de1ab183da7e521a27af229cbf63b1e92abf..7b6c4c79f9f4960c6043db4190adf2944b0efb3a 100644 (file)
@@ -53,7 +53,7 @@ public class NewIssuesMeasureTest extends AbstractIssueTest {
 
   @Test
   public void new_issues_measures() throws Exception {
-    setServerProperty(ORCHESTRATOR, "sonar.leak.period", "previous_analysis");
+    setServerProperty(ORCHESTRATOR, "sonar.leak.period", "previous_version");
     ORCHESTRATOR.getServer().provisionProject("sample", "Sample");
 
     // Execute an analysis in the past with no issue to have a past snapshot
@@ -96,7 +96,7 @@ public class NewIssuesMeasureTest extends AbstractIssueTest {
    */
   @Test
   public void new_issues_measures_consistent_with_variations() throws Exception {
-    setServerProperty(ORCHESTRATOR, "sonar.leak.period", "previous_analysis");
+    setServerProperty(ORCHESTRATOR, "sonar.leak.period", "previous_version");
     ORCHESTRATOR.getServer().provisionProject("sample", "Sample");
     ItUtils.restoreProfile(ORCHESTRATOR, getClass().getResource("/issue/one-issue-per-line-profile.xml"));
     ORCHESTRATOR.getServer().associateProjectToQualityProfile("sample", "xoo", "one-issue-per-line-profile");
@@ -124,7 +124,7 @@ public class NewIssuesMeasureTest extends AbstractIssueTest {
 
   @Test
   public void new_issues_measures_should_be_correctly_calculated_when_adding_a_new_module() throws Exception {
-    setServerProperty(ORCHESTRATOR, "sonar.leak.period", "previous_analysis");
+    setServerProperty(ORCHESTRATOR, "sonar.leak.period", "previous_version");
     ORCHESTRATOR.getServer().provisionProject("com.sonarsource.it.samples:multi-modules-sample", "com.sonarsource.it.samples:multi-modules-sample");
 
     // First analysis without module b
index 0597e0e8e97235da537b2313f7071f564e1167b8..8df93be6cf6d9caa70fda18383ef9a56522305f4 100644 (file)
@@ -82,7 +82,7 @@ public class DifferentialPeriodsTest {
     orchestrator.getServer().provisionProject(PROJECT_KEY, PROJECT_KEY);
 
     // Set a global property and a project property to ensure project property is used
-    setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+    setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
     setServerProperty(orchestrator, PROJECT_KEY, "sonar.leak.period", "30");
 
     // Execute an analysis in the past to have a past snapshot without any issues
@@ -133,7 +133,7 @@ public class DifferentialPeriodsTest {
   @Test
   public void compute_no_new_lines_measures_when_changes_but_no_scm() throws Exception {
     orchestrator.getServer().provisionProject(MULTI_MODULE_PROJECT_KEY, MULTI_MODULE_PROJECT_KEY);
-    setServerProperty(orchestrator, MULTI_MODULE_PROJECT_KEY, "sonar.leak.period", "previous_analysis");
+    setServerProperty(orchestrator, MULTI_MODULE_PROJECT_KEY, "sonar.leak.period", "previous_version");
 
     // Execute an analysis 60 days ago without module b
     orchestrator.getServer().associateProjectToQualityProfile(MULTI_MODULE_PROJECT_KEY, "xoo", "empty");
@@ -156,7 +156,7 @@ public class DifferentialPeriodsTest {
   public void compute_zero_new_lines_measures_when_no_changes_and_scm_available() throws Exception {
     String projectKey = "sample-scm";
     orchestrator.getServer().provisionProject(projectKey, projectKey);
-    setServerProperty(orchestrator, projectKey, "sonar.leak.period", "previous_analysis");
+    setServerProperty(orchestrator, projectKey, "sonar.leak.period", "previous_version");
 
     // Execute an analysis 60 days ago
     runProjectAnalysis(orchestrator, "scm/xoo-sample-with-scm", "sonar.projectDate", formatDate(addDays(new Date(), -60)),
index 53e20f39bc04848b111781252b4e50be42dcad32..6bbca17f4983eaa6bb9d522de55fe619e85abe36 100644 (file)
@@ -52,7 +52,7 @@ public class MeasuresWsTest {
 
   @BeforeClass
   public static void initPeriod() throws Exception {
-    setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+    setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
   }
 
   @AfterClass
index f95081a24a7e46faf155325bd7290e43aee29a15..5d5e5afdde1f339e2fc9480dca96f8372c5bc8f5 100644 (file)
@@ -75,7 +75,7 @@ public class TimeMachineTest {
   }
 
   private static void initPeriod() {
-    setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+    setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
   }
 
   @AfterClass
index 78c56f8bea282ef39f3f26c387635971627e7769..3bbe47d117457b3c882a5868795b05ad4bc9d4de 100644 (file)
@@ -56,7 +56,7 @@ public class LeakProjectsPageTest {
 
   @BeforeClass
   public static void beforeClass() {
-    setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+    setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
   }
 
   @AfterClass
index 8383935cab8eb22559a5a0c801deff19eee395f9..c466b813e11bb7bc57a14e8848e26616bf727182 100644 (file)
@@ -220,7 +220,7 @@ public class SearchProjectsTest {
 
   @Test
   public void should_return_facets_on_leak() throws Exception {
-    setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+    setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
     // This project has no duplication on new code
     String projectKey1 = newProjectKey();
     analyzeProject(projectKey1, "shared/xoo-sample", "sonar.projectDate", "2016-12-31");
index d946a40e5f226f6ea07bb13b78f36da9f9fb5aa3..9df387528bfe426673247658095213ecaf0a46be 100644 (file)
@@ -67,7 +67,7 @@ public class QualityGateNotificationTest {
 
   @Test
   public void status_on_metric_variation_and_send_notifications() throws Exception {
-    tester.settings().setGlobalSettings("sonar.leak.period", "previous_analysis");
+    tester.settings().setGlobalSettings("sonar.leak.period", "previous_version");
     tester.settings().setGlobalSettings("email.smtp_host.secured", "localhost");
     tester.settings().setGlobalSettings("email.smtp_port.secured", Integer.toString(SMTP_SERVER.getServer().getPort()));
 
@@ -113,7 +113,7 @@ public class QualityGateNotificationTest {
       .contains("Project: Sample")
       .contains("Version: 1.0-SNAPSHOT")
       .contains("Quality gate status: Orange (was Green)")
-      .contains("Quality gate threshold: Lines of Code variation = 0 since previous analysis")
+      .contains("Quality gate threshold: Lines of Code variation = 0 since previous version")
       .contains("/dashboard?id=" + project.getKey());
     assertThat(emails.hasNext()).isFalse();
   }
index 7630cde59225a52d9c782a7403246e4f64002782..c1005e3683ce3070008a8be8da25d94b02ef3031 100644 (file)
@@ -67,7 +67,7 @@ public class QualityGateOnRatingMeasuresTest {
     Project project = tester.projects().generate(null);
     WsQualityGates.CreateWsResponse qualityGate = tester.qGates().generate();
     tester.qGates().associateProject(qualityGate, project);
-    tester.settings().setGlobalSetting("sonar.leak.period", "previous_analysis");
+    tester.settings().setGlobalSetting("sonar.leak.period", "previous_version");
     tester.wsClient().qualityGates().createCondition(CreateConditionRequest.builder()
       .setQualityGateId(qualityGate.getId())
       .setMetricKey("new_security_rating")
index 0e89e544925e03dcfa94d221ddf2538b8ed49881..132e081054c1f1758c2857cebc2e614c9c0e9583 100644 (file)
@@ -56,7 +56,7 @@ public class QualityGateUiTest {
 
   @Before
   public void initPeriod() throws Exception {
-    tester.settings().setGlobalSettings("sonar.leak.period", "previous_analysis");
+    tester.settings().setGlobalSettings("sonar.leak.period", "previous_version");
   }
 
   /**
index 7b24e3e76a95dd153f9c0b6c3dfd57dcd62b759c..9279b40d50cf7ddff1a68a3f5d668c953c34a525 100644 (file)
@@ -64,7 +64,7 @@ public class NewDebtRatioMeasureTest {
 
   @Test
   public void new_debt_ratio_is_computed_from_new_debt_and_new_ncloc_count_per_file() throws Exception {
-    setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+    setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
 
     // run analysis on the day of after the first commit, with 'one-issue-per-line' profile
     defineQualityProfile("one-issue-per-line");
index 801b02d3c1e6bce8d8a6654896479fe5bad10499..637a6a982b393f5910e9294ff83f313c15f0bb88 100644 (file)
@@ -53,82 +53,6 @@ public class TechnicalDebtAndIssueNewMeasuresTest {
     orchestrator.resetData();
   }
 
-  @Test
-  public void since_previous_analysis_with_constant_effort() throws Exception {
-    setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
-    defineQualityProfile("one-issue-per-line");
-    provisionSampleProject();
-
-    // Execute an analysis in the past to have a past snapshot without any issues
-    setSampleProjectQualityProfile("empty");
-    runSampleProjectAnalysis("v1", "sonar.projectDate", DATE_31_DAYS_AGO);
-
-    // Second analysis issues will be created -> new issues and new technical debt
-    setSampleProjectQualityProfile("one-issue-per-line");
-    runSampleProjectAnalysis("v1");
-    assertLeakPeriodForComponent("sample", 26, 26);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/UnchangedClass.xoo", 13, 13);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/ClassToModify.xoo", 13, 13);
-
-    // Third analysis, with exactly the same profile -> no new issues so no new technical debt
-    runSampleProjectAnalysis("v1");
-    assertLeakPeriodForComponent("sample", 0, 0);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/UnchangedClass.xoo", 0, 0);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/ClassToModify.xoo", 0, 0);
-
-    // Fourth analysis, with new files and modified files -> new issues and new technical debt
-    runSampleProjectAnalysis("v2");
-    assertLeakPeriodForComponent("sample", 17, 17);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/UnchangedClass.xoo", 0, 0);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/ClassToModify.xoo", 4, 4);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/ClassAdded.xoo", 13, 13);
-
-    // Fifth analysis, no change -> no new issues so no new technical debt
-    runSampleProjectAnalysis("v2");
-    assertLeakPeriodForComponent("sample", 0, 0);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/UnchangedClass.xoo", 0, 0);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/ClassToModify.xoo", 0, 0);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/ClassAdded.xoo", 0, 0);
-  }
-
-  @Test
-  public void since_previous_analysis_with_effort_change() throws Exception {
-    setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
-    defineQualityProfile("one-issue-per-line");
-    provisionSampleProject();
-
-    // Execute an analysis in the past to have a past snapshot without any issues
-    setSampleProjectQualityProfile("empty");
-    runSampleProjectAnalysis("v1", "sonar.projectDate", DATE_31_DAYS_AGO);
-
-    // Second analysis issues will be created -> new issues and new technical debt
-    setSampleProjectQualityProfile("one-issue-per-line");
-    runSampleProjectAnalysis("v1");
-    assertLeakPeriodForComponent("sample", 26, 26);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/UnchangedClass.xoo", 13, 13);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/ClassToModify.xoo", 13, 13);
-
-    // Third analysis, no change but increased effort is ignored but only new issues are considered -> no new issues so no new technical debt
-    runSampleProjectAnalysis("v1", "sonar.oneIssuePerLine.effortToFix", "10");
-    assertLeakPeriodForComponent("sample", 0, 0);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/UnchangedClass.xoo", 0, 0);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/ClassToModify.xoo", 0, 0);
-
-    // Fourth analysis, with new files, modified files and increased effort -> new issues and new technical debt
-    runSampleProjectAnalysis("v2", "sonar.oneIssuePerLine.effortToFix", "10");
-    assertLeakPeriodForComponent("sample", 170, 17);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/UnchangedClass.xoo", 0, 0);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/ClassToModify.xoo", 40, 4);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/ClassAdded.xoo", 130, 13);
-
-    // Fifth analysis, no change -> no new issues so no new technical debt
-    runSampleProjectAnalysis("v2", "sonar.oneIssuePerLine.effortToFix", "10");
-    assertLeakPeriodForComponent("sample", 0, 0);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/UnchangedClass.xoo", 0, 0);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/ClassToModify.xoo", 0, 0);
-    assertLeakPeriodForComponent("sample:src/main/xoo/sample/ClassAdded.xoo", 0, 0);
-  }
-
   @Test
   public void since_30_days_with_constant_effort() throws Exception {
     setServerProperty(orchestrator, "sonar.leak.period", "30");