assertThat(projectSnapshot.getLast()).isFalse();
assertThat(projectSnapshot.getStatus()).isEqualTo("U");
assertThat(projectSnapshot.getCreatedAt()).isEqualTo(analysisDate);
- assertThat(projectSnapshot.getBuildDate()).isEqualTo(now);
+ assertThat(projectSnapshot.getAnalysisDate()).isEqualTo(now);
assertThat(projectSnapshot.getRevision()).isEqualTo(REVISION_ID);
}
assertThat(viewSnapshot.getLast()).isFalse();
assertThat(viewSnapshot.getStatus()).isEqualTo("U");
assertThat(viewSnapshot.getCreatedAt()).isEqualTo(analysisDate);
- assertThat(viewSnapshot.getBuildDate()).isEqualTo(now);
+ assertThat(viewSnapshot.getAnalysisDate()).isEqualTo(now);
}
@Test
.hasMessage("Analysis Export failed after processing 1 analyses successfully");
}
- private static SnapshotDto newAnalysis(String uuid, long date, String componentUuid, @Nullable String version, boolean isLast, @Nullable String buildString, long buildDate) {
+ private static SnapshotDto newAnalysis(String uuid, long date, String componentUuid, @Nullable String version, boolean isLast, @Nullable String buildString, long analysisDate) {
return new SnapshotDto()
.setUuid(uuid)
.setCreatedAt(date)
.setBuildString(buildString)
.setLast(isLast)
.setStatus(SnapshotDto.STATUS_PROCESSED)
- .setBuildDate(buildDate);
+ .setAnalysisDate(analysisDate);
}
private static void assertAnalysis(ProjectDump.Analysis analysis, ComponentDto component, SnapshotDto dto) {
.setLast(false)
.setStatus(SnapshotDto.STATUS_UNPROCESSED)
.setCreatedAt(analysisDate)
- .setBuildDate(system2.now());
+ .setAnalysisDate(system2.now());
if (component.getType() == PROJECT) {
component.getProjectAttributes().getScmRevisionId().ifPresent(dto::setRevision);
" inner join components p on s.root_component_uuid=p.uuid" +
" inner join project_branches pb on pb.uuid=p.uuid" +
" where pb.project_uuid=? and pb.branch_type = 'BRANCH' and pb.exclude_from_purge=? and s.status=? and p.enabled=?" +
- " order by s.build_date asc";
+ " order by s.analysis_date asc";
private final DbClient dbClient;
private final ProjectHolder projectHolder;
// Stream of analyses stored in file analyses.pb, including project.
// Only analyses with status 'P' (processed) are exported. They are ordered
-// by build_date, so that parents are always located before children.
+// by analysis_date, so that parents are always located before children.
message Analysis {
int64 component_ref = 2;
int64 date = 3;
assertThat(scannerAnalysisCacheDao.selectData(dbSession, snapshot4.getRootComponentUuid())).isNull();
}
- private static SnapshotDto createSnapshot(long buildtime) {
+ private static SnapshotDto createSnapshot(long analysisTime) {
return new SnapshotDto()
.setUuid(uuidFactory.create())
.setRootComponentUuid(uuidFactory.create())
.setProjectVersion("2.1-SNAPSHOT")
.setPeriodMode("days1")
.setPeriodParam("30")
- .setPeriodDate(buildtime)
- .setBuildDate(buildtime);
+ .setPeriodDate(analysisTime)
+ .setAnalysisDate(analysisTime);
}
}
.setPeriodDate(1500000000001L)
.setProjectVersion("2.1.0")
.setBuildString("2.1.0.2336")
- .setBuildDate(1500000000006L)
+ .setAnalysisDate(1500000000006L)
.setCreatedAt(1403042400000L)
.setRevision("sha1"));
assertThat(result.getPeriodMode()).isEqualTo("days");
assertThat(result.getPeriodModeParameter()).isEqualTo("30");
assertThat(result.getPeriodDate()).isEqualTo(1500000000001L);
- assertThat(result.getBuildDate()).isEqualTo(1500000000006L);
+ assertThat(result.getAnalysisDate()).isEqualTo(1500000000006L);
assertThat(result.getCreatedAt()).isEqualTo(1403042400000L);
assertThat(result.getRevision()).isEqualTo("sha1");
.setPeriodParam("30")
.setPeriodDate(1500000000001L)
.setProjectVersion("2.1-SNAPSHOT")
- .setBuildDate(1500000000006L)
+ .setAnalysisDate(1500000000006L)
.setCreatedAt(1403042400000L));
assertThat(dto.getUuid()).isNotNull();
assertThat(dto.getPeriodMode()).isEqualTo("days");
assertThat(dto.getPeriodModeParameter()).isEqualTo("30");
assertThat(dto.getPeriodDate()).isEqualTo(1500000000001L);
- assertThat(dto.getBuildDate()).isEqualTo(1500000000006L);
+ assertThat(dto.getAnalysisDate()).isEqualTo(1500000000006L);
assertThat(dto.getCreatedAt()).isEqualTo(1403042400000L);
assertThat(dto.getProjectVersion()).isEqualTo("2.1-SNAPSHOT");
}
.setPeriodMode("days1")
.setPeriodParam("30")
.setPeriodDate(1_500_000_000_001L)
- .setBuildDate(1_500_000_000_006L);
+ .setAnalysisDate(1_500_000_000_006L);
}
private CeActivityDto insertActivity(String projectUuid, SnapshotDto analysis, CeActivityDto.Status status) {
return new ByteArrayInputStream(str.getBytes(StandardCharsets.UTF_8));
}
- private static SnapshotDto createSnapshot(long buildtime) {
+ private static SnapshotDto createSnapshot(long analysisTime) {
return new SnapshotDto()
.setUuid(uuidFactory.create())
.setRootComponentUuid(uuidFactory.create())
.setProjectVersion("2.1-SNAPSHOT")
.setPeriodMode("days1")
.setPeriodParam("30")
- .setPeriodDate(buildtime)
- .setBuildDate(buildtime);
+ .setPeriodDate(analysisTime)
+ .setAnalysisDate(analysisTime);
}
}
private String uuid;
private String rootComponentUuid;
private Long createdAt;
- private Long buildDate;
+ private Long analysisDate;
private String status = STATUS_UNPROCESSED;
private Boolean last;
// maps to "version" column in the table
return this.uuid;
}
- public Long getBuildDate() {
- return buildDate;
+ public Long getAnalysisDate() {
+ return analysisDate;
}
- public SnapshotDto setBuildDate(Long buildDate) {
- this.buildDate = buildDate;
+ public SnapshotDto setAnalysisDate(Long analysisDate) {
+ this.analysisDate = analysisDate;
return this;
}
return Objects.equals(uuid, that.uuid) &&
Objects.equals(rootComponentUuid, that.rootComponentUuid) &&
Objects.equals(createdAt, that.createdAt) &&
- Objects.equals(buildDate, that.buildDate) &&
+ Objects.equals(analysisDate, that.analysisDate) &&
Objects.equals(status, that.status) &&
Objects.equals(last, that.last) &&
Objects.equals(projectVersion, that.projectVersion) &&
@Override
public int hashCode() {
- return Objects.hash(uuid, rootComponentUuid, createdAt, buildDate, status, last, projectVersion, buildString, periodMode, periodParam, periodDate);
+ return Objects.hash(uuid, rootComponentUuid, createdAt, analysisDate, status, last, projectVersion, buildString, periodMode, periodParam, periodDate);
}
@Override
"uuid='" + uuid + '\'' +
", componentUuid='" + rootComponentUuid + '\'' +
", createdAt=" + createdAt +
- ", buildDate=" + buildDate +
+ ", analysisDate=" + analysisDate +
", status='" + status + '\'' +
", last=" + last +
", projectVersion='" + projectVersion + '\'' +
s.uuid as uuid,
s.root_component_uuid as rootComponentUuid,
s.created_at as createdAt,
- s.build_date as buildDate,
+ s.analysis_date as analysisDate,
s.status as status,
s.islast as last,
s.version as rawProjectVersion,
uuid,
root_component_uuid,
created_at,
- build_date,
+ analysis_date,
status,
islast,
version,
#{uuid, jdbcType=VARCHAR},
#{rootComponentUuid, jdbcType=VARCHAR},
#{createdAt, jdbcType=BIGINT},
- #{buildDate, jdbcType=BIGINT},
+ #{analysisDate, jdbcType=BIGINT},
#{status, jdbcType=VARCHAR},
#{last, jdbcType=BOOLEAN},
#{projectVersion, jdbcType=VARCHAR},
left outer join snapshots s on
sac.branch_uuid = s.root_component_uuid
where
- s.build_date < #{timestamp,jdbcType=BIGINT} and s.islast=${_true}
+ s.analysis_date < #{timestamp,jdbcType=BIGINT} and s.islast=${_true}
or s.islast is null
)
</delete>
"VERSION" CHARACTER VARYING(500),
"BUILD_STRING" CHARACTER VARYING(100),
"REVISION" CHARACTER VARYING(100),
- "BUILD_DATE" BIGINT,
+ "ANALYSIS_DATE" BIGINT,
"PERIOD1_MODE" CHARACTER VARYING(100),
"PERIOD1_PARAM" CHARACTER VARYING(100),
"PERIOD1_DATE" BIGINT,
@Test
public void test_getter_and_setter() {
- SnapshotDto snapshotDto = new SnapshotDto()
- .setBuildDate(parseDate("2014-07-02").getTime())
- .setRootComponentUuid("uuid_21")
- .setLast(true)
- .setProjectVersion("1.0")
- .setBuildString("1.0.1.123")
- .setPeriodMode("mode1")
- .setPeriodParam("param1")
- .setPeriodDate(parseDate("2014-06-01").getTime());
+ SnapshotDto snapshotDto = create();
- assertThat(snapshotDto.getBuildDate()).isEqualTo(parseDate("2014-07-02").getTime());
+ assertThat(snapshotDto.getAnalysisDate()).isEqualTo(parseDate("2014-07-02").getTime());
assertThat(snapshotDto.getRootComponentUuid()).isEqualTo("uuid_21");
assertThat(snapshotDto.getLast()).isTrue();
assertThat(snapshotDto.getProjectVersion()).isEqualTo("1.0");
" length (101) is longer than the maximum authorized (100). " +
"'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' was provided.");
}
+
+ @Test
+ public void equals_whenSameObject_shouldReturnTrue() {
+ SnapshotDto snapshotDto = create();
+ assertThat(snapshotDto.equals(snapshotDto)).isTrue();
+ }
+
+ @Test
+ public void equals_whenComparedToNull_shouldReturnFalse() {
+ SnapshotDto snapshotDto = create();
+ assertThat(snapshotDto.equals(null)).isFalse();
+ }
+
+ @Test
+ public void equals_whenComparedToDifferentClass_shouldReturnFalse() {
+ SnapshotDto snapshotDto = create();
+ Object differentObject = new Object();
+ assertThat(snapshotDto.equals(differentObject)).isFalse();
+ }
+
+ @Test
+ public void equals_whenComparedToDifferentInstanceWithSameValues_shouldReturnTrue() {
+ SnapshotDto snapshotDto1 = create();
+ SnapshotDto snapshotDto2 = create();
+ assertThat(snapshotDto1.equals(snapshotDto2)).isTrue();
+ assertThat(snapshotDto2.equals(snapshotDto1)).isTrue();
+ }
+
+ @Test
+ public void equals_whenComparedToDifferentInstanceWithDifferentValues_shouldReturnFalse() {
+ SnapshotDto snapshotDto1 = create();
+ SnapshotDto snapshotDto2 = create().setBuildString("some-other-string");
+ assertThat(snapshotDto1.equals(snapshotDto2)).isFalse();
+ assertThat(snapshotDto2.equals(snapshotDto1)).isFalse();
+ }
+
+ @Test
+ public void hashcode_whenDifferentInstanceWithSameValues_shouldBeEqual() {
+ SnapshotDto snapshotDto1 = create();
+ SnapshotDto snapshotDto2 = create();
+ assertThat(snapshotDto1).hasSameHashCodeAs(snapshotDto2);
+ }
+
+ @Test
+ public void hashcode_whenDifferentInstanceWithDifferentValues_shouldNotBeEqual() {
+ SnapshotDto snapshotDto1 = create();
+ SnapshotDto snapshotDto2 = create().setBuildString("some-other-string");
+ assertThat(snapshotDto1).doesNotHaveSameHashCodeAs(snapshotDto2);
+ }
+
+ private SnapshotDto create() {
+ return new SnapshotDto()
+ .setAnalysisDate(parseDate("2014-07-02").getTime())
+ .setRootComponentUuid("uuid_21")
+ .setLast(true)
+ .setProjectVersion("1.0")
+ .setBuildString("1.0.1.123")
+ .setPeriodMode("mode1")
+ .setPeriodParam("param1")
+ .setPeriodDate(parseDate("2014-06-01").getTime());
+ }
+
}
.setRootComponentUuid(uuid)
.setStatus(SnapshotDto.STATUS_PROCESSED)
.setCreatedAt(System.currentTimeMillis())
- .setBuildDate(System.currentTimeMillis())
+ .setAnalysisDate(System.currentTimeMillis())
.setRevision(randomAlphanumeric(50))
.setLast(true);
}
.setRootComponentUuid(randomAlphanumeric(40))
.setStatus(randomAscii(1))
.setCreatedAt(System.currentTimeMillis())
- .setBuildDate(System.currentTimeMillis())
+ .setAnalysisDate(System.currentTimeMillis())
.setLast(true);
}
}
.add(10_2_022, "Populate 'purged' column in 'snapshots' table", PopulatePurgedColumnInSnapshots.class)
.add(10_2_023, "Make 'purged' column not nullable in 'snapshots' table", MakePurgedColumnNotNullableInSnapshots.class)
.add(10_2_024, "Drop 'purge_status' column in 'snapshots' table", DropPurgeStatusColumnInSnapshots.class)
+ .add(10_2_025, "Rename 'build_date' in 'snapshots' table to 'analysis_date", RenameBuildDateInSnapshots.class)
;
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.DatabaseUtils;
+import org.sonar.server.platform.db.migration.def.BigIntegerColumnDef;
+import org.sonar.server.platform.db.migration.sql.RenameColumnsBuilder;
+import org.sonar.server.platform.db.migration.step.DdlChange;
+
+public class RenameBuildDateInSnapshots extends DdlChange {
+ private static final String TABLE_NAME = "snapshots";
+
+ private static final BigIntegerColumnDef columnDefinition = BigIntegerColumnDef.newBigIntegerColumnDefBuilder()
+ .setColumnName("analysis_date")
+ .setIsNullable(true)
+ .build();
+
+ public RenameBuildDateInSnapshots(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ try (Connection connection = getDatabase().getDataSource().getConnection()) {
+ if (!DatabaseUtils.tableColumnExists(connection, TABLE_NAME, "analysis_date")
+ && DatabaseUtils.tableColumnExists(connection, TABLE_NAME, "build_date")) {
+ context.execute(new RenameColumnsBuilder(getDialect(), TABLE_NAME)
+ .renameColumn("build_date", columnDefinition)
+ .build());
+ }
+ }
+ }
+}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2023 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.v102;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonar.db.CoreDbTester;
+
+public class RenameBuildDateInSnapshotsTest {
+ private static final String TABLE_NAME = "snapshots";
+
+ @Rule
+ public final CoreDbTester db = CoreDbTester.createForSchema(RenameBuildDateInSnapshotsTest.class, "schema.sql");
+
+ private final RenameBuildDateInSnapshots underTest = new RenameBuildDateInSnapshots(db.database());
+
+ @Test
+ public void execute_whenExecuted_shouldRenameColumn() throws SQLException {
+ assertColumnExists("build_date");
+ underTest.execute();
+ assertColumnExists("analysis_date");
+ }
+
+ @Test
+ public void execute_whenExecutedTwice_shouldNotFail() throws SQLException {
+ assertColumnExists("build_date");
+ underTest.execute();
+ underTest.execute();
+ assertColumnExists("analysis_date");
+ }
+
+ private void assertColumnExists(String columnName) {
+ db.assertColumnDefinition(TABLE_NAME, columnName, Types.BIGINT, null, true);
+ }
+}
--- /dev/null
+CREATE TABLE "SNAPSHOTS"(
+ "UUID" CHARACTER VARYING(50) NOT NULL,
+ "COMPONENT_UUID" CHARACTER VARYING(50) NOT NULL,
+ "STATUS" CHARACTER VARYING(4) DEFAULT 'U' NOT NULL,
+ "ISLAST" BOOLEAN DEFAULT FALSE NOT NULL,
+ "VERSION" CHARACTER VARYING(500),
+ "PURGE_STATUS" INTEGER,
+ "BUILD_STRING" CHARACTER VARYING(100),
+ "REVISION" CHARACTER VARYING(100),
+ "BUILD_DATE" BIGINT,
+ "PERIOD1_MODE" CHARACTER VARYING(100),
+ "PERIOD1_PARAM" CHARACTER VARYING(100),
+ "PERIOD1_DATE" BIGINT,
+ "CREATED_AT" BIGINT
+);
+ALTER TABLE "SNAPSHOTS" ADD CONSTRAINT "PK_SNAPSHOTS" PRIMARY KEY("UUID");
+CREATE INDEX "SNAPSHOT_COMPONENT" ON "SNAPSHOTS"("COMPONENT_UUID" NULLS FIRST);
\ No newline at end of file
List<String> branchUuids = branchesWithLargestNcloc.stream().map(ProjectLocDistributionDto::branchUuid).toList();
Map<String, Long> latestSnapshotMap = dbClient.snapshotDao().selectLastAnalysesByRootComponentUuids(dbSession, branchUuids)
.stream()
- .collect(toMap(SnapshotDto::getRootComponentUuid, SnapshotDto::getBuildDate));
+ .collect(toMap(SnapshotDto::getRootComponentUuid, SnapshotDto::getAnalysisDate));
data.setProjects(buildProjectsList(branchesWithLargestNcloc, latestSnapshotMap));
}
db.measures().insertLiveMeasure(mainBranch2, coverage, m -> m.setValue(80d));
db.measures().insertLiveMeasure(mainBranch2, nclocDistrib, m -> m.setValue(null).setData("java=180;js=20"));
- SnapshotDto project1Analysis = db.components().insertSnapshot(mainBranch1, t -> t.setLast(true).setBuildDate(analysisDate));
- SnapshotDto project2Analysis = db.components().insertSnapshot(mainBranch2, t -> t.setLast(true).setBuildDate(analysisDate));
+ SnapshotDto project1Analysis = db.components().insertSnapshot(mainBranch1, t -> t.setLast(true).setAnalysisDate(analysisDate));
+ SnapshotDto project2Analysis = db.components().insertSnapshot(mainBranch2, t -> t.setLast(true).setAnalysisDate(analysisDate));
db.measures().insertMeasure(mainBranch1, project1Analysis, nclocDistrib, m -> m.setData("java=70;js=30;kotlin=10"));
db.measures().insertMeasure(mainBranch2, project2Analysis, nclocDistrib, m -> m.setData("java=180;js=20"));
ProjectData projectData2 = db.components().insertPrivateProject();
ComponentDto mainBranch2 = projectData2.getMainBranchComponent();
- SnapshotDto project1Analysis1 = db.components().insertSnapshot(mainBranch1, t -> t.setLast(true).setBuildDate(analysisDate));
- SnapshotDto project1Analysis2 = db.components().insertSnapshot(mainBranch1, t -> t.setLast(true).setBuildDate(analysisDate));
- SnapshotDto project2Analysis = db.components().insertSnapshot(mainBranch2, t -> t.setLast(true).setBuildDate(analysisDate));
+ SnapshotDto project1Analysis1 = db.components().insertSnapshot(mainBranch1, t -> t.setLast(true).setAnalysisDate(analysisDate));
+ SnapshotDto project1Analysis2 = db.components().insertSnapshot(mainBranch1, t -> t.setLast(true).setAnalysisDate(analysisDate));
+ SnapshotDto project2Analysis = db.components().insertSnapshot(mainBranch2, t -> t.setLast(true).setAnalysisDate(analysisDate));
db.measures().insertMeasure(mainBranch1, project1Analysis1, qg, pm -> pm.setData("OK"));
db.measures().insertMeasure(mainBranch1, project1Analysis2, qg, pm -> pm.setData("ERROR"));
db.measures().insertMeasure(mainBranch2, project2Analysis, qg, pm -> pm.setData("ERROR"));