.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)
;
}
}
--- /dev/null
+/*
+ * 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;
+ });
+ }
+}
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 6);
+ verifyMigrationCount(underTest, 7);
}
}
--- /dev/null
+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);
+ }
+}
--- /dev/null
+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");
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;
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);
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();
}
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) {
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,
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;
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;
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();
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);
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 {
@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");
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
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;
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:
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);
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;
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;
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);
@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
*/
@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");
@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
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
@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");
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)),
@BeforeClass
public static void initPeriod() throws Exception {
- setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+ setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
}
@AfterClass
}
private static void initPeriod() {
- setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+ setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
}
@AfterClass
@BeforeClass
public static void beforeClass() {
- setServerProperty(orchestrator, "sonar.leak.period", "previous_analysis");
+ setServerProperty(orchestrator, "sonar.leak.period", "previous_version");
}
@AfterClass
@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");
@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()));
.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();
}
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")
@Before
public void initPeriod() throws Exception {
- tester.settings().setGlobalSettings("sonar.leak.period", "previous_analysis");
+ tester.settings().setGlobalSettings("sonar.leak.period", "previous_version");
}
/**
@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");
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");