From f3de142860a4ebcc91f9f80771964a105f8ed982 Mon Sep 17 00:00:00 2001 From: Eric Hartmann Date: Thu, 19 Oct 2017 13:47:56 +0200 Subject: [PATCH] SONAR-9142 Remove 'previous_analysis' option --- .../db/migration/version/v67/DbVersion67.java | 1 + ...ratePreviousAnalysisToPreviousVersion.java | 49 +++++++++ .../version/v67/DbVersion67Test.java | 2 +- ...PreviousAnalysisToPreviousVersionTest.java | 104 ++++++++++++++++++ .../properties.sql | 11 ++ .../projectanalysis/step/PeriodResolver.java | 18 --- .../issue/NewEffortAggregatorTest.java | 4 +- .../step/LoadPeriodsStepTest.java | 47 +------- .../step/ReportPersistAnalysisStepTest.java | 6 +- .../org/sonar/core/timemachine/Periods.java | 12 +- .../sonar/core/timemachine/PeriodsTest.java | 38 ------- .../tests/issue/NewIssuesMeasureTest.java | 6 +- .../measure/DifferentialPeriodsTest.java | 6 +- .../tests/measure/MeasuresWsTest.java | 2 +- .../tests/measure/TimeMachineTest.java | 2 +- .../projectSearch/LeakProjectsPageTest.java | 2 +- .../projectSearch/SearchProjectsTest.java | 2 +- .../QualityGateNotificationTest.java | 4 +- .../QualityGateOnRatingMeasuresTest.java | 2 +- .../tests/qualityGate/QualityGateUiTest.java | 2 +- .../qualityModel/NewDebtRatioMeasureTest.java | 2 +- .../TechnicalDebtAndIssueNewMeasuresTest.java | 76 ------------- 22 files changed, 190 insertions(+), 208 deletions(-) create mode 100644 server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersion.java create mode 100644 server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersionTest.java create mode 100644 server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersionTest/properties.sql diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java index c6eddef0eda..0f06e00377e 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67.java @@ -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 index 00000000000..8f3e954967c --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersion.java @@ -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; + }); + } +} diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67Test.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67Test.java index dc54ab65e84..de678701f0b 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67Test.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/DbVersion67Test.java @@ -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 index 00000000000..11de20ca3ad --- /dev/null +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersionTest.java @@ -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 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 index 00000000000..d84c238cd48 --- /dev/null +++ b/server/sonar-db-migration/src/test/resources/org/sonar/server/platform/db/migration/version/v67/MigratePreviousAnalysisToPreviousVersionTest/properties.sql @@ -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"); diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PeriodResolver.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PeriodResolver.java index 7a21affa5ac..606cdcaca78 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PeriodResolver.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PeriodResolver.java @@ -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) { diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortAggregatorTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortAggregatorTest.java index f567083f309..64a19ba9da0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortAggregatorTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/NewEffortAggregatorTest.java @@ -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, diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest.java index 8d45b82f8a7..9a1a708bc6e 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/LoadPeriodsStepTest.java @@ -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); diff --git a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistAnalysisStepTest.java b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistAnalysisStepTest.java index 3a3bb64bdd8..aa1ba90c9a4 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistAnalysisStepTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistAnalysisStepTest.java @@ -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 diff --git a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java index 7aaecf3a41f..4b05e3bae42 100644 --- a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java +++ b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java @@ -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; diff --git a/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java b/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java index 7c307f066db..c3f137b2a96 100644 --- a/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java @@ -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); diff --git a/tests/src/test/java/org/sonarqube/tests/issue/NewIssuesMeasureTest.java b/tests/src/test/java/org/sonarqube/tests/issue/NewIssuesMeasureTest.java index 40a5de1ab18..7b6c4c79f9f 100644 --- a/tests/src/test/java/org/sonarqube/tests/issue/NewIssuesMeasureTest.java +++ b/tests/src/test/java/org/sonarqube/tests/issue/NewIssuesMeasureTest.java @@ -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 diff --git a/tests/src/test/java/org/sonarqube/tests/measure/DifferentialPeriodsTest.java b/tests/src/test/java/org/sonarqube/tests/measure/DifferentialPeriodsTest.java index 0597e0e8e97..8df93be6cf6 100644 --- a/tests/src/test/java/org/sonarqube/tests/measure/DifferentialPeriodsTest.java +++ b/tests/src/test/java/org/sonarqube/tests/measure/DifferentialPeriodsTest.java @@ -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)), diff --git a/tests/src/test/java/org/sonarqube/tests/measure/MeasuresWsTest.java b/tests/src/test/java/org/sonarqube/tests/measure/MeasuresWsTest.java index 53e20f39bc0..6bbca17f498 100644 --- a/tests/src/test/java/org/sonarqube/tests/measure/MeasuresWsTest.java +++ b/tests/src/test/java/org/sonarqube/tests/measure/MeasuresWsTest.java @@ -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 diff --git a/tests/src/test/java/org/sonarqube/tests/measure/TimeMachineTest.java b/tests/src/test/java/org/sonarqube/tests/measure/TimeMachineTest.java index f95081a24a7..5d5e5afdde1 100644 --- a/tests/src/test/java/org/sonarqube/tests/measure/TimeMachineTest.java +++ b/tests/src/test/java/org/sonarqube/tests/measure/TimeMachineTest.java @@ -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 diff --git a/tests/src/test/java/org/sonarqube/tests/projectSearch/LeakProjectsPageTest.java b/tests/src/test/java/org/sonarqube/tests/projectSearch/LeakProjectsPageTest.java index 78c56f8bea2..3bbe47d1174 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectSearch/LeakProjectsPageTest.java +++ b/tests/src/test/java/org/sonarqube/tests/projectSearch/LeakProjectsPageTest.java @@ -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 diff --git a/tests/src/test/java/org/sonarqube/tests/projectSearch/SearchProjectsTest.java b/tests/src/test/java/org/sonarqube/tests/projectSearch/SearchProjectsTest.java index 8383935cab8..c466b813e11 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectSearch/SearchProjectsTest.java +++ b/tests/src/test/java/org/sonarqube/tests/projectSearch/SearchProjectsTest.java @@ -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"); diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateNotificationTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateNotificationTest.java index d946a40e5f2..9df387528bf 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateNotificationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateNotificationTest.java @@ -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(); } diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java index 7630cde5922..c1005e3683c 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateOnRatingMeasuresTest.java @@ -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") diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java index 0e89e544925..132e081054c 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java @@ -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"); } /** diff --git a/tests/src/test/java/org/sonarqube/tests/qualityModel/NewDebtRatioMeasureTest.java b/tests/src/test/java/org/sonarqube/tests/qualityModel/NewDebtRatioMeasureTest.java index 7b24e3e76a9..9279b40d50c 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityModel/NewDebtRatioMeasureTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityModel/NewDebtRatioMeasureTest.java @@ -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"); diff --git a/tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtAndIssueNewMeasuresTest.java b/tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtAndIssueNewMeasuresTest.java index 801b02d3c1e..637a6a982b3 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtAndIssueNewMeasuresTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityModel/TechnicalDebtAndIssueNewMeasuresTest.java @@ -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"); -- 2.39.5