diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2017-07-27 12:43:35 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-07 11:44:06 +0200 |
commit | ff8c79248182e1b1e571dab021f725dc044222a6 (patch) | |
tree | 5fb9cfe2385d9c005f6a760f0695eab847168b3b | |
parent | 180fa079b253a4ae70db95b28ede4f09fb793728 (diff) | |
download | sonarqube-ff8c79248182e1b1e571dab021f725dc044222a6.tar.gz sonarqube-ff8c79248182e1b1e571dab021f725dc044222a6.zip |
SONAR-9577 Store incremental analysis flag in database
24 files changed, 168 insertions, 9 deletions
diff --git a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl index 81c8fe51945..c8cbe0b5ea4 100644 --- a/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl +++ b/server/sonar-db-core/src/main/resources/org/sonar/db/version/schema-h2.ddl @@ -124,7 +124,8 @@ CREATE TABLE "SNAPSHOTS" ( "PERIOD4_DATE" BIGINT, "PERIOD5_MODE" VARCHAR(100), "PERIOD5_PARAM" VARCHAR(100), - "PERIOD5_DATE" BIGINT + "PERIOD5_DATE" BIGINT, + "INCREMENTAL" BOOLEAN DEFAULT FALSE ); CREATE INDEX "SNAPSHOT_COMPONENT" ON "SNAPSHOTS" ("COMPONENT_UUID"); CREATE UNIQUE INDEX "ANALYSES_UUID" ON "SNAPSHOTS" ("UUID"); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java index e326b4da511..e2bb957ea7f 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java @@ -42,6 +42,7 @@ public final class SnapshotDto { private String periodMode; private String periodParam; private Long periodDate; + private boolean incremental = false; public Long getId() { return id; @@ -155,6 +156,15 @@ public final class SnapshotDto { return this; } + public boolean getIncremental() { + return incremental; + } + + public SnapshotDto setIncremental(boolean incremental) { + this.incremental = incremental; + return this; + } + /** * @return analysis date */ diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml index 8060e105448..b838cf23afe 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml @@ -14,7 +14,8 @@ s.version as version, s.period1_mode as periodMode, s.period1_param as periodParam, - s.period1_date as periodDate + s.period1_date as periodDate, + s.incremental as incremental </sql> <sql id="viewsSnapshotColumns"> @@ -180,7 +181,8 @@ version, period1_mode, period1_param, - period1_date) + period1_date, + incremental) values ( #{uuid, jdbcType=VARCHAR}, #{componentUuid, jdbcType=VARCHAR}, @@ -192,7 +194,8 @@ #{version, jdbcType=VARCHAR}, #{periodMode, jdbcType=VARCHAR}, #{periodParam, jdbcType=VARCHAR}, - #{periodDate, jdbcType=BIGINT}) + #{periodDate, jdbcType=BIGINT}, + #{incremental, jdbcType=BOOLEAN}) </insert> </mapper> diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java index aad175a6f50..291143024b4 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java @@ -73,6 +73,7 @@ public class SnapshotDaoTest { .setPeriodParam("30") .setPeriodDate(1500000000001L) .setVersion("2.1-SNAPSHOT") + .setIncremental(false) .setBuildDate(1500000000006L) .setCreatedAt(1403042400000L)); @@ -90,6 +91,8 @@ public class SnapshotDaoTest { assertThat(result.getBuildDate()).isEqualTo(1500000000006L); assertThat(result.getCreatedAt()).isEqualTo(1403042400000L); assertThat(result.getVersion()).isEqualTo("2.1-SNAPSHOT"); + assertThat(result.getIncremental()).isFalse(); + assertThat(underTest.selectByUuid(db.getSession(), "DOES_NOT_EXIST").isPresent()).isFalse(); } @@ -266,6 +269,7 @@ public class SnapshotDaoTest { .setPeriodDate(1500000000001L) .setVersion("2.1-SNAPSHOT") .setBuildDate(1500000000006L) + .setIncremental(true) .setCreatedAt(1403042400000L)); assertThat(dto.getId()).isNotNull(); @@ -280,6 +284,8 @@ public class SnapshotDaoTest { assertThat(dto.getBuildDate()).isEqualTo(1500000000006L); assertThat(dto.getCreatedAt()).isEqualTo(1403042400000L); assertThat(dto.getVersion()).isEqualTo("2.1-SNAPSHOT"); + assertThat(dto.getIncremental()).isTrue(); + } @Test @@ -387,7 +393,8 @@ public class SnapshotDaoTest { .setPeriodMode("days1") .setPeriodParam("30") .setPeriodDate(1_500_000_000_001L) - .setBuildDate(1_500_000_000_006L); + .setBuildDate(1_500_000_000_006L) + .setIncremental(false); } private CeActivityDto insertActivity(SnapshotDto analysis, CeActivityDto.Status status) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDtoTest.java index 4b8dd3e26af..04ad4267454 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDtoTest.java @@ -36,6 +36,7 @@ public class SnapshotDtoTest { .setVersion("1.0") .setPeriodMode("mode1") .setPeriodParam("param1") + .setIncremental(true) .setPeriodDate(parseDate("2014-06-01").getTime()); assertThat(snapshotDto.getId()).isEqualTo(10L); @@ -45,6 +46,7 @@ public class SnapshotDtoTest { assertThat(snapshotDto.getVersion()).isEqualTo("1.0"); assertThat(snapshotDto.getPeriodMode()).isEqualTo("mode1"); assertThat(snapshotDto.getPeriodModeParameter()).isEqualTo("param1"); + assertThat(snapshotDto.getIncremental()).isTrue(); assertThat(snapshotDto.getPeriodDate()).isEqualTo(parseDate("2014-06-01").getTime()); } diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml index 6cb45a58538..ef080fd3f64 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis-result.xml @@ -32,6 +32,7 @@ Note that measures, events and reviews are not deleted. created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <!--switched_off="[null]" permanent_id="[null]" FAILURE_LEVEL="2"--> @@ -96,6 +97,7 @@ Note that measures, events and reviews are not deleted. created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml index d086021a151..15104619310 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldPurgeAnalysis.xml @@ -24,6 +24,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <project_measures ID="1" @@ -88,6 +89,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <project_measures ID="2" diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/close_issues_clean_index_and_files_sources_of_specified_components-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/close_issues_clean_index_and_files_sources_of_specified_components-result.xml index de51ded1e35..5515cd38ea4 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/close_issues_clean_index_and_files_sources_of_specified_components-result.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/close_issues_clean_index_and_files_sources_of_specified_components-result.xml @@ -146,6 +146,7 @@ What has been changed : created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <!-- Open issue on file --> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/close_issues_clean_index_and_files_sources_of_specified_components.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/close_issues_clean_index_and_files_sources_of_specified_components.xml index 8db639ce361..43d7229f269 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/close_issues_clean_index_and_files_sources_of_specified_components.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/close_issues_clean_index_and_files_sources_of_specified_components.xml @@ -135,6 +135,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <!-- Open issue on file --> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml index e5c679bf4c5..dd294d38bf2 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds-result.xml @@ -50,6 +50,7 @@ Snapshot 2 has been deleted created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete --> @@ -77,6 +78,7 @@ Snapshot 2 has been deleted created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> </dataset> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml index 9acb701f9e9..3f493acd7eb 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAbortedBuilds.xml @@ -45,6 +45,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <!-- snapshot with status "unprocessed" -> to be deleted --> @@ -72,6 +73,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <!-- snapshot with status "processed" and flagged as "last" -> do not purge and do not delete --> @@ -99,6 +101,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> </dataset> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses-result.xml index 878595a3c80..d5393b6756a 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses-result.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses-result.xml @@ -25,6 +25,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <!-- delete only resource 1 --> @@ -52,6 +53,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> </dataset> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses.xml index d4cdd256532..9d351499f2a 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteAnalyses.xml @@ -25,6 +25,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <!-- delete only resource 1 --> @@ -52,6 +53,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <!-- to be deleted --> @@ -79,6 +81,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> </dataset> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml index 89086990a76..73c511a1b74 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles-result.xml @@ -148,6 +148,7 @@ What has been changed : purge_status=1 on snapshot 4 (PRJ) and snapshots 5 and 6 created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <!-- snapshots to be purged --> @@ -175,6 +176,7 @@ What has been changed : purge_status=1 on snapshot 4 (PRJ) and snapshots 5 and 6 created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> </dataset> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml index 38e737bf8f5..4abc4eefd73 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml @@ -136,6 +136,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <!-- snapshots to be purged --> @@ -163,6 +164,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> </dataset> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject-result.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject-result.xml index 5bfd2ffe1f5..e8178d60f1c 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject-result.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject-result.xml @@ -65,6 +65,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> @@ -93,6 +94,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <!-- snapshot to be purged --> @@ -120,6 +122,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> </dataset> diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject.xml index 8b86cbd140a..2c48394a5bc 100644 --- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject.xml +++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldPurgeProject.xml @@ -64,6 +64,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> @@ -92,6 +93,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> <!-- snapshot to be purged --> @@ -119,6 +121,7 @@ created_at="1228222680000" build_date="1228222680000" version="[null]" + incremental="[false]" /> </dataset> diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java index 25f9b7e35b5..43de1b33971 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/MigrationConfigurationModule.java @@ -31,6 +31,7 @@ import org.sonar.server.platform.db.migration.version.v62.DbVersion62; import org.sonar.server.platform.db.migration.version.v63.DbVersion63; import org.sonar.server.platform.db.migration.version.v64.DbVersion64; import org.sonar.server.platform.db.migration.version.v65.DbVersion65; +import org.sonar.server.platform.db.migration.version.v66.DbVersion66; public class MigrationConfigurationModule extends Module { @Override @@ -45,6 +46,7 @@ public class MigrationConfigurationModule extends Module { DbVersion63.class, DbVersion64.class, DbVersion65.class, + DbVersion66.class, // migration steps MigrationStepRegistryImpl.class, diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddIncrementalColumnToSnapshotsTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddIncrementalColumnToSnapshotsTable.java new file mode 100644 index 00000000000..960626c0ccf --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/AddIncrementalColumnToSnapshotsTable.java @@ -0,0 +1,45 @@ +/* + * 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.def.BooleanColumnDef; +import org.sonar.server.platform.db.migration.sql.AddColumnsBuilder; +import org.sonar.server.platform.db.migration.step.DdlChange; + +public class AddIncrementalColumnToSnapshotsTable extends DdlChange { + + public AddIncrementalColumnToSnapshotsTable(Database db) { + super(db); + } + + @Override + public void execute(Context context) throws SQLException { + context.execute(new AddColumnsBuilder(getDialect(), "snapshots") + .addColumn(BooleanColumnDef.newBooleanColumnDefBuilder() + .setColumnName("incremental") + .setDefaultValue(false) + .build()) + .build()); + } + +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java new file mode 100644 index 00000000000..a9bb2dc26be --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/DbVersion66.java @@ -0,0 +1,31 @@ +/* + * 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 org.sonar.server.platform.db.migration.step.MigrationStepRegistry; +import org.sonar.server.platform.db.migration.version.DbVersion; + +public class DbVersion66 implements DbVersion { + @Override + public void addSteps(MigrationStepRegistry registry) { + registry.add(1800, "Add incremental column to snapthots table", AddIncrementalColumnToSnapshotsTable.class); + } +} diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/package-info.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/package-info.java new file mode 100644 index 00000000000..d0c2be7543f --- /dev/null +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v66/package-info.java @@ -0,0 +1,24 @@ +/* + * 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. + */ +@ParametersAreNonnullByDefault +package org.sonar.server.platform.db.migration.version.v66; + +import javax.annotation.ParametersAreNonnullByDefault; + diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java index eb18aa71c0a..edea77696f7 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/MigrationConfigurationModuleTest.java @@ -37,7 +37,7 @@ public class MigrationConfigurationModuleTest { assertThat(container.getPicoContainer().getComponentAdapters()) .hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER // DbVersion classes - + 8 + + 9 // Others + 3); } diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisStep.java index ef8e57dc3a2..5af65d9c03f 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisStep.java +++ b/server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistAnalysisStep.java @@ -19,6 +19,8 @@ */ package org.sonar.server.computation.task.projectanalysis.step; +import javax.annotation.Nullable; + import org.sonar.api.utils.System2; import org.sonar.db.DbClient; import org.sonar.db.DbSession; @@ -76,14 +78,14 @@ public class PersistAnalysisStep implements ComputationStep { @Override public void visitProject(Component project) { - SnapshotDto snapshot = createAnalysis(analysisMetadataHolder.getUuid(), project, true); + SnapshotDto snapshot = createAnalysis(analysisMetadataHolder.getUuid(), project, true, analysisMetadataHolder.isIncrementalAnalysis()); updateSnapshotPeriods(snapshot); persist(snapshot, dbSession); } @Override public void visitView(Component view) { - SnapshotDto snapshot = createAnalysis(analysisMetadataHolder.getUuid(), view, false); + SnapshotDto snapshot = createAnalysis(analysisMetadataHolder.getUuid(), view, false, null); updateSnapshotPeriods(snapshot); persist(snapshot, dbSession); } @@ -98,12 +100,13 @@ public class PersistAnalysisStep implements ComputationStep { snapshotDto.setPeriodDate(period.getSnapshotDate()); } - private SnapshotDto createAnalysis(String snapshotUuid, Component component, boolean setVersion) { + private SnapshotDto createAnalysis(String snapshotUuid, Component component, boolean setVersion, @Nullable Boolean incremental) { String componentUuid = component.getUuid(); return new SnapshotDto() .setUuid(snapshotUuid) .setVersion(setVersion ? component.getReportAttributes().getVersion() : null) .setComponentUuid(componentUuid) + .setIncremental(incremental) .setLast(false) .setStatus(SnapshotDto.STATUS_UNPROCESSED) .setCreatedAt(analysisDate) 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 40fbf42f133..a892fc57f9d 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 @@ -98,6 +98,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { @Test public void persist_analysis() { + analysisMetadataHolder.setIncrementalAnalysis(false); OrganizationDto organizationDto = dbTester.organizations().insert(); ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setDbKey(PROJECT_KEY).setName("Project"); dbClient.componentDao().insert(dbTester.getSession(), projectDto); @@ -132,6 +133,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { assertThat(projectSnapshot.getStatus()).isEqualTo("U"); assertThat(projectSnapshot.getCreatedAt()).isEqualTo(analysisDate); assertThat(projectSnapshot.getBuildDate()).isEqualTo(now); + assertThat(projectSnapshot.getIncremental()).isFalse(); assertThat(dbIdsRepository.getComponentId(module)).isEqualTo(moduleDto.getId()); assertThat(dbIdsRepository.getComponentId(directory)).isEqualTo(directoryDto.getId()); @@ -140,6 +142,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { @Test public void persist_snapshots_with_leak_period() { + analysisMetadataHolder.setIncrementalAnalysis(false); OrganizationDto organizationDto = dbTester.organizations().insert(); ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(organizationDto, "ABCD").setDbKey(PROJECT_KEY).setName("Project"); dbClient.componentDao().insert(dbTester.getSession(), projectDto); @@ -162,6 +165,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { @Test public void only_persist_snapshots_with_leak_period_on_project_and_module() { + analysisMetadataHolder.setIncrementalAnalysis(false); periodsHolder.setPeriod(new Period(LEAK_PERIOD_MODE_PREVIOUS_ANALYSIS, null, analysisDate, "u1")); OrganizationDto organizationDto = dbTester.organizations().insert(); @@ -200,6 +204,7 @@ public class ReportPersistAnalysisStepTest extends BaseStepTest { @Test public void set_no_period_on_snapshots_when_no_period() { + analysisMetadataHolder.setIncrementalAnalysis(false); ComponentDto projectDto = ComponentTesting.newPrivateProjectDto(dbTester.organizations().insert(), "ABCD").setDbKey(PROJECT_KEY).setName("Project"); dbClient.componentDao().insert(dbTester.getSession(), projectDto); SnapshotDto snapshotDto = SnapshotTesting.newAnalysis(projectDto); |