"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");
private String periodMode;
private String periodParam;
private Long periodDate;
+ private boolean incremental = false;
public Long getId() {
return id;
return this;
}
+ public boolean getIncremental() {
+ return incremental;
+ }
+
+ public SnapshotDto setIncremental(boolean incremental) {
+ this.incremental = incremental;
+ return this;
+ }
+
/**
* @return analysis date
*/
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">
version,
period1_mode,
period1_param,
- period1_date)
+ period1_date,
+ incremental)
values (
#{uuid, jdbcType=VARCHAR},
#{componentUuid, jdbcType=VARCHAR},
#{version, jdbcType=VARCHAR},
#{periodMode, jdbcType=VARCHAR},
#{periodParam, jdbcType=VARCHAR},
- #{periodDate, jdbcType=BIGINT})
+ #{periodDate, jdbcType=BIGINT},
+ #{incremental, jdbcType=BOOLEAN})
</insert>
</mapper>
.setPeriodParam("30")
.setPeriodDate(1500000000001L)
.setVersion("2.1-SNAPSHOT")
+ .setIncremental(false)
.setBuildDate(1500000000006L)
.setCreatedAt(1403042400000L));
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();
}
.setPeriodDate(1500000000001L)
.setVersion("2.1-SNAPSHOT")
.setBuildDate(1500000000006L)
+ .setIncremental(true)
.setCreatedAt(1403042400000L));
assertThat(dto.getId()).isNotNull();
assertThat(dto.getBuildDate()).isEqualTo(1500000000006L);
assertThat(dto.getCreatedAt()).isEqualTo(1403042400000L);
assertThat(dto.getVersion()).isEqualTo("2.1-SNAPSHOT");
+ assertThat(dto.getIncremental()).isTrue();
+
}
@Test
.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) {
.setVersion("1.0")
.setPeriodMode("mode1")
.setPeriodParam("param1")
+ .setIncremental(true)
.setPeriodDate(parseDate("2014-06-01").getTime());
assertThat(snapshotDto.getId()).isEqualTo(10L);
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());
}
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
<!--switched_off="[null]" permanent_id="[null]" FAILURE_LEVEL="2"-->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
<project_measures ID="1"
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
<project_measures ID="2"
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
<!-- Open issue on file -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
<!-- Open issue on file -->
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 -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
<!-- snapshot with status "unprocessed" -> to be 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 -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
<!-- delete only resource 1 -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
<!-- delete only resource 1 -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
<!-- to be deleted -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
<!-- snapshots to be purged -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
<!-- snapshots to be purged -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
<!-- snapshot to be purged -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
</dataset>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
<!-- snapshot to be purged -->
created_at="1228222680000"
build_date="1228222680000"
version="[null]"
+ incremental="[false]"
/>
</dataset>
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
DbVersion63.class,
DbVersion64.class,
DbVersion65.class,
+ DbVersion66.class,
// migration steps
MigrationStepRegistryImpl.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.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());
+ }
+
+}
--- /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 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);
+ }
+}
--- /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.
+ */
+@ParametersAreNonnullByDefault
+package org.sonar.server.platform.db.migration.version.v66;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
assertThat(container.getPicoContainer().getComponentAdapters())
.hasSize(COMPONENTS_IN_EMPTY_COMPONENT_CONTAINER
// DbVersion classes
- + 8
+ + 9
// Others
+ 3);
}
*/
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;
@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);
}
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)
@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);
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());
@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);
@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();
@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);