public void addSteps(MigrationStepRegistry registry) {
registry
.add(1800, "Add incremental column to snapthots table", AddIncrementalColumnToSnapshotsTable.class)
- .add(1801, "Create table CE task characteristics", CreateTableCeTaskCharacteristics.class);
+ .add(1801, "Create table CE task characteristics", CreateTableCeTaskCharacteristics.class)
+ .add(1802, "Delete leak settings on views", DeleteLeakSettingsOnViews.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.v66;
+
+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 DeleteLeakSettingsOnViews extends DataChange {
+
+ public DeleteLeakSettingsOnViews(Database db) {
+ super(db);
+ }
+
+ @Override
+ protected void execute(Context context) throws SQLException {
+ MassUpdate massUpdate = context.prepareMassUpdate();
+ massUpdate.select("SELECT prop.id FROM properties prop " +
+ "INNER JOIN projects p ON p.id=prop.resource_id AND p.qualifier NOT IN ('TRK') " +
+ "WHERE prop.prop_key='sonar.leak.period' or prop.prop_key='sonar.timemachine.period1' ");
+ massUpdate.update("DELETE FROM properties WHERE id=?");
+ massUpdate.rowPluralName("properties");
+ massUpdate.execute((row, update) -> {
+ update.setLong(1, row.getLong(1));
+ return true;
+ });
+ }
+
+}
*/
package org.sonar.server.platform.db.migration.version.v66;
+import org.junit.Test;
+
import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMigrationCount;
import static org.sonar.server.platform.db.migration.version.DbVersionTestUtils.verifyMinimumMigrationNumber;
-import org.junit.Test;
-
public class DbVersion66Test {
private DbVersion66 underTest = new DbVersion66();
@Test
public void verify_migration_count() {
- verifyMigrationCount(underTest, 2);
+ verifyMigrationCount(underTest, 3);
}
}
--- /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.v66;
+
+import java.sql.SQLException;
+import java.util.Random;
+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.junit.rules.ExpectedException;
+import org.sonar.api.resources.Scopes;
+import org.sonar.core.util.Uuids;
+import org.sonar.db.CoreDbTester;
+
+import static java.lang.String.valueOf;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
+import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
+import static org.sonar.api.resources.Qualifiers.PROJECT;
+import static org.sonar.api.resources.Qualifiers.SUBVIEW;
+import static org.sonar.api.resources.Qualifiers.VIEW;
+
+public class DeleteLeakSettingsOnViewsTest {
+
+ @Rule
+ public CoreDbTester db = CoreDbTester.createForSchema(DeleteLeakSettingsOnViewsTest.class, "settings_and_projects.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private DeleteLeakSettingsOnViews underTest = new DeleteLeakSettingsOnViews(db.database());
+
+ @Test
+ public void migrate_leak_settings_on_views() throws SQLException {
+ long viewId = insertComponent(Scopes.PROJECT, VIEW);
+ long subViewId = insertComponent(Scopes.PROJECT, SUBVIEW);
+ insertProperty("sonar.leak.period", viewId);
+ insertProperty("sonar.leak.period", subViewId);
+
+ underTest.execute();
+
+ assertPropertiesIsEmpty();
+ }
+
+ @Test
+ public void migrate_old_leak_settings_on_views() throws SQLException {
+ long viewId = insertComponent(Scopes.PROJECT, VIEW);
+ long subViewId = insertComponent(Scopes.PROJECT, SUBVIEW);
+ insertProperty("sonar.timemachine.period1", viewId);
+ insertProperty("sonar.timemachine.period1", subViewId);
+
+ underTest.execute();
+
+ assertPropertiesIsEmpty();
+ }
+
+ @Test
+ public void does_nothing_on_leak_settings_not_on_views() throws SQLException {
+ long projectId = insertComponent(Scopes.PROJECT, PROJECT);
+ insertProperty("sonar.leak.period", projectId);
+ insertProperty("sonar.leak.period", null);
+
+ underTest.execute();
+
+ assertProperties(
+ tuple("sonar.leak.period", projectId),
+ tuple("sonar.leak.period", null));
+ }
+
+ @Test
+ public void does_nothing_on_non_leak_settings() throws SQLException {
+ long projectId = insertComponent(Scopes.PROJECT, PROJECT);
+ insertProperty("sonar.component", projectId);
+ insertProperty("sonar.global", null);
+
+ underTest.execute();
+
+ assertProperties(
+ tuple("sonar.component", projectId),
+ tuple("sonar.global", null));
+ }
+
+ private void assertPropertiesIsEmpty(){
+ assertThat(db.countRowsOfTable("properties")).isZero();
+ }
+
+ private void assertProperties(Tuple... expectedTuples) {
+ assertThat(db.select("SELECT PROP_KEY, RESOURCE_ID FROM PROPERTIES")
+ .stream()
+ .map(map -> new Tuple(map.get("PROP_KEY"), map.get("RESOURCE_ID")))
+ .collect(Collectors.toList()))
+ .containsExactlyInAnyOrder(expectedTuples);
+ }
+
+ public void insertProperty(String propertyName, @Nullable Long componentId) {
+ db.executeInsert(
+ "properties",
+ "prop_key", propertyName,
+ "resource_id", componentId,
+ "is_empty", "false",
+ "text_value", randomAlphabetic(2));
+ }
+
+ private long insertComponent(@Nullable String scope, @Nullable String qualifier) {
+ String uuid = Uuids.createFast();
+ db.executeInsert(
+ "projects",
+ "organization_uuid", randomAlphanumeric(3),
+ "uuid", uuid,
+ "uuid_path", "path_of_" + uuid,
+ "root_uuid", uuid,
+ "project_uuid", uuid,
+ "scope", scope,
+ "qualifier", qualifier,
+ "private", valueOf(new Random().nextBoolean()),
+ "enabled", valueOf(new Random().nextBoolean()));
+ return ((Long) db.selectFirst("select id as \"ID\" from projects where uuid='" + uuid + "'").get("ID")).intValue();
+ }
+
+}
--- /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(2147483647),
+ "CREATED_AT" BIGINT
+);
+CREATE INDEX "PROPERTIES_KEY" ON "PROPERTIES" ("PROP_KEY");
+
+CREATE TABLE "PROJECTS" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "ORGANIZATION_UUID" VARCHAR(40) NOT NULL,
+ "KEE" VARCHAR(400),
+ "UUID" VARCHAR(50) NOT NULL,
+ "UUID_PATH" VARCHAR(1500) NOT NULL,
+ "ROOT_UUID" VARCHAR(50) NOT NULL,
+ "PROJECT_UUID" VARCHAR(50) NOT NULL,
+ "MODULE_UUID" VARCHAR(50),
+ "MODULE_UUID_PATH" VARCHAR(1500),
+ "NAME" VARCHAR(2000),
+ "DESCRIPTION" VARCHAR(2000),
+ "PRIVATE" BOOLEAN NOT NULL,
+ "TAGS" VARCHAR(500),
+ "ENABLED" BOOLEAN NOT NULL DEFAULT TRUE,
+ "SCOPE" VARCHAR(3),
+ "QUALIFIER" VARCHAR(10),
+ "DEPRECATED_KEE" VARCHAR(400),
+ "PATH" VARCHAR(2000),
+ "LANGUAGE" VARCHAR(20),
+ "COPY_COMPONENT_UUID" VARCHAR(50),
+ "LONG_NAME" VARCHAR(2000),
+ "DEVELOPER_UUID" VARCHAR(50),
+ "CREATED_AT" TIMESTAMP,
+ "AUTHORIZATION_UPDATED_AT" BIGINT,
+ "B_CHANGED" BOOLEAN,
+ "B_COPY_COMPONENT_UUID" VARCHAR(50),
+ "B_DESCRIPTION" VARCHAR(2000),
+ "B_ENABLED" BOOLEAN,
+ "B_UUID_PATH" VARCHAR(1500),
+ "B_LANGUAGE" VARCHAR(20),
+ "B_LONG_NAME" VARCHAR(500),
+ "B_MODULE_UUID" VARCHAR(50),
+ "B_MODULE_UUID_PATH" VARCHAR(1500),
+ "B_NAME" VARCHAR(500),
+ "B_PATH" VARCHAR(2000),
+ "B_QUALIFIER" VARCHAR(10)
+);
+CREATE INDEX "PROJECTS_ORGANIZATION" ON "PROJECTS" ("ORGANIZATION_UUID");
+CREATE UNIQUE INDEX "PROJECTS_KEE" ON "PROJECTS" ("KEE");
+CREATE INDEX "PROJECTS_ROOT_UUID" ON "PROJECTS" ("ROOT_UUID");
+CREATE UNIQUE INDEX "PROJECTS_UUID" ON "PROJECTS" ("UUID");
+CREATE INDEX "PROJECTS_PROJECT_UUID" ON "PROJECTS" ("PROJECT_UUID");
+CREATE INDEX "PROJECTS_MODULE_UUID" ON "PROJECTS" ("MODULE_UUID");
+CREATE INDEX "PROJECTS_QUALIFIER" ON "PROJECTS" ("QUALIFIER");
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.task.projectanalysis.component.Component;
import org.sonar.server.computation.task.projectanalysis.component.ConfigurationRepository;
+import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
import org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler;
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
import org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter;
import org.sonar.server.computation.task.projectanalysis.period.PeriodHolderImpl;
import org.sonar.server.computation.task.step.ComputationStep;
-import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.PROJECT;
-import static org.sonar.server.computation.task.projectanalysis.component.Component.Type.VIEW;
import static org.sonar.server.computation.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
-import static org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit.reportMaxDepth;
/**
* Populates the {@link PeriodHolder}
* <p/>
* Here is how these periods are computed :
- * - Read the 5 period properties ${@link org.sonar.core.config.CorePropertyDefinitions#LEAK_PERIOD}
- * - Try to find the matching snapshots from the properties
- * - If a snapshot is found, a new period is added to the repository
+ * - Read the period property ${@link org.sonar.core.config.CorePropertyDefinitions#LEAK_PERIOD}
+ * - Try to find the matching snapshots from the property
+ * - If a snapshot is found, a period is set to the repository
*/
public class LoadPeriodsStep implements ComputationStep {
@Override
public void execute() {
new DepthTraversalTypeAwareCrawler(
- new TypeAwareVisitorAdapter(reportMaxDepth(PROJECT).withViewsMaxDepth(VIEW), PRE_ORDER) {
+ new TypeAwareVisitorAdapter(CrawlerDepthLimit.PROJECT, PRE_ORDER) {
@Override
public void visitProject(Component project) {
execute(project);
}
-
- @Override
- public void visitView(Component view) {
- execute(view);
- }
}).visit(treeRootHolder.getRoot());
}
*/
package org.sonar.server.computation.task.projectanalysis.step;
-import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
-import com.tngtech.java.junit.dataprovider.UseDataProvider;
import java.text.SimpleDateFormat;
import org.junit.Before;
import org.junit.Rule;
when(settingsRepository.getConfiguration(root)).thenReturn(settings.asConfig());
}
- @DataProvider
- public static Object[][] projectAndViewRoots() {
- return new Object[][] {
- {PROJECT_ROOT},
- {VIEW_ROOT}
- };
- }
-
@Test
- @UseDataProvider("projectAndViewRoots")
- public void no_period_on_first_analysis(Component root) {
- setupRoot(root);
+ public void no_period_on_first_analysis() {
+ setupRoot(PROJECT_ROOT);
// No project, no snapshot
underTest.execute();
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void feed_one_period(Component root) {
- setupRoot(root);
+ public void feed_one_period() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "shared.xml");
String textDate = "2008-11-22";
settings.setProperty("sonar.leak.period", textDate);
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void no_period_when_settings_match_no_analysis(Component root) {
- setupRoot(root);
+ public void no_period_when_settings_match_no_analysis() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "shared.xml");
settings.setProperty("sonar.leak.period", "UNKNWOWN VERSION");
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void no_period_when_settings_is_empty(Component root) {
- setupRoot(root);
+ public void no_period_when_settings_is_empty() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "shared.xml");
settings.setProperty("sonar.leak.period", "");
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void ignore_unprocessed_snapshots(Component root) {
- setupRoot(root);
+ public void ignore_unprocessed_snapshots() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "unprocessed_snapshots.xml");
settings.setProperty("sonar.leak.period", "100");
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void feed_period_by_date(Component root) {
- setupRoot(root);
+ public void feed_period_by_date() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "shared.xml");
String textDate = "2008-11-22";
settings.setProperty("sonar.leak.period", textDate);
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void search_by_date_return_nearest_later_analysis(Component root) {
- setupRoot(root);
+ public void search_by_date_return_nearest_later_analysis() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "shared.xml");
String date = "2008-11-24";
settings.setProperty("sonar.leak.period", date);
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void no_period_by_date(Component root) {
- setupRoot(root);
+ public void no_period_by_date() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "shared.xml");
// No analysis at and after this date
settings.setProperty("sonar.leak.period", "2008-11-30");
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void feed_period_by_days(Component root) {
- setupRoot(root);
+ public void feed_period_by_days() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "shared.xml");
settings.setProperty("sonar.leak.period", "10");
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void no_period_by_days(Component root) {
- setupRoot(root);
+ public void no_period_by_days() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "empty.xml");
settings.setProperty("sonar.leak.period", "0");
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void feed_period_by_previous_analysis(Component root) {
- setupRoot(root);
+ public void feed_period_by_previous_analysis() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "shared.xml");
settings.setProperty("sonar.leak.period", "previous_analysis");
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void no_period_by_previous_analysis(Component root) {
- setupRoot(root);
+ public void no_period_by_previous_analysis() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "empty.xml");
settings.setProperty("sonar.leak.period", "previous_analysis");
assertThat(logTester.logs(LoggerLevel.DEBUG).get(0)).startsWith("Compare to previous version (");
}
- @Test
- public void feed_period_by_previous_version_is_not_supported_for_views() {
- setupRoot(VIEW_ROOT);
- dbTester.prepareDbUnit(getClass(), "shared.xml");
- settings.setProperty("sonar.leak.period", "previous_version");
-
- underTest.execute();
-
- assertThat(periodsHolder.getPeriod()).isNull();
- }
-
@Test
public void feed_period_by_previous_version_with_previous_version_deleted() {
setupRoot(PROJECT_ROOT);
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void no_period_by_previous_version(Component root) {
- setupRoot(root);
+ public void no_period_by_previous_version() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "empty.xml");
settings.setProperty("sonar.leak.period", "previous_version");
}
@Test
- public void no_period_by_previous_version_when_no_event_version_for_views() {
- setupRoot(VIEW_ROOT);
- dbTester.prepareDbUnit(getClass(), "no_previous_version.xml");
- settings.setProperty("sonar.leak.period", "previous_version");
-
- underTest.execute();
-
- assertThat(periodsHolder.getPeriod()).isNull();
- }
-
- @Test
- @UseDataProvider("projectAndViewRoots")
- public void feed_period_by_version(Component root) {
- setupRoot(root);
+ public void feed_period_by_version() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "shared.xml");
settings.setProperty("sonar.leak.period", "0.9");
}
@Test
- @UseDataProvider("projectAndViewRoots")
- public void no_period_by_version(Component root) {
- setupRoot(root);
+ public void no_period_by_version() {
+ setupRoot(PROJECT_ROOT);
dbTester.prepareDbUnit(getClass(), "empty.xml");
settings.setProperty("sonar.leak.period", "0.8");
.defaultValue(DEFAULT_LEAK_PERIOD)
.category(CoreProperties.CATEGORY_GENERAL)
.subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS)
- .onQualifiers(Qualifiers.PROJECT, Qualifiers.VIEW)
+ .onQualifiers(Qualifiers.PROJECT)
.build(),
// CPD