aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2019-05-06 16:43:28 +0200
committerSonarTech <sonartech@sonarsource.com>2019-05-22 20:21:16 +0200
commit07ad2bae039d15a83fe6e50dcee5f571f589f25c (patch)
tree740925ae1ce9c0935114747ffa125de96c9e3ca0 /server/sonar-db-dao
parentabf908c2a51ed98d856b567663ba4eedf996c102 (diff)
downloadsonarqube-07ad2bae039d15a83fe6e50dcee5f571f589f25c.tar.gz
sonarqube-07ad2bae039d15a83fe6e50dcee5f571f589f25c.zip
SONAR-11950 add SnapshotDto#revision
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java17
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml9
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java6
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotTesting.java1
4 files changed, 27 insertions, 6 deletions
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 7cdbdba7c51..058c7ce71dc 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
@@ -50,6 +50,12 @@ public final class SnapshotDto {
private String periodParam;
private Long periodDate;
+ /**
+ * SCM revision is provided by scanner and is optional.
+ */
+ @Nullable
+ private String revision;
+
public Long getId() {
return id;
}
@@ -189,6 +195,17 @@ public final class SnapshotDto {
return createdAt;
}
+ @Nullable
+ public String getRevision() {
+ return revision;
+ }
+
+ public SnapshotDto setRevision(@Nullable String revision) {
+ checkLength(100, revision, "revision");
+ this.revision = revision;
+ return this;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
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 7c760b5d5df..b4a648e2828 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.build_string as buildString,
s.period1_mode as periodMode,
s.period1_param as periodParam,
- s.period1_date as periodDate
+ s.period1_date as periodDate,
+ s.revision as revision
</sql>
<sql id="viewsSnapshotColumns">
@@ -168,7 +169,8 @@
build_string,
period1_mode,
period1_param,
- period1_date
+ period1_date,
+ revision
)
values (
#{uuid, jdbcType=VARCHAR},
@@ -181,7 +183,8 @@
#{buildString, jdbcType=VARCHAR},
#{periodMode, jdbcType=VARCHAR},
#{periodParam, jdbcType=VARCHAR},
- #{periodDate, jdbcType=BIGINT}
+ #{periodDate, jdbcType=BIGINT},
+ #{revision, jdbcType=VARCHAR}
)
</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 62592fb6d82..bd601aa277b 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
@@ -27,7 +27,6 @@ import java.util.Date;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
-import org.apache.commons.lang.StringUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@@ -48,7 +47,6 @@ import static java.util.Collections.singletonList;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.apache.commons.lang.math.RandomUtils.nextLong;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.groups.Tuple.tuple;
import static org.sonar.db.ce.CeActivityDto.Status.CANCELED;
import static org.sonar.db.ce.CeActivityDto.Status.SUCCESS;
@@ -86,7 +84,8 @@ public class SnapshotDaoTest {
.setProjectVersion("2.1.0")
.setBuildString("2.1.0.2336")
.setBuildDate(1500000000006L)
- .setCreatedAt(1403042400000L));
+ .setCreatedAt(1403042400000L)
+ .setRevision("sha1"));
SnapshotDto result = underTest.selectByUuid(db.getSession(), "ABCD").get();
assertThat(result.getId()).isNotNull();
@@ -101,6 +100,7 @@ public class SnapshotDaoTest {
assertThat(result.getPeriodDate()).isEqualTo(1500000000001L);
assertThat(result.getBuildDate()).isEqualTo(1500000000006L);
assertThat(result.getCreatedAt()).isEqualTo(1403042400000L);
+ assertThat(result.getRevision()).isEqualTo("sha1");
assertThat(underTest.selectByUuid(db.getSession(), "DOES_NOT_EXIST").isPresent()).isFalse();
}
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotTesting.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotTesting.java
index 32f945887b4..1f65b38e2b2 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotTesting.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotTesting.java
@@ -35,6 +35,7 @@ public class SnapshotTesting {
.setStatus(SnapshotDto.STATUS_PROCESSED)
.setCreatedAt(System.currentTimeMillis())
.setBuildDate(System.currentTimeMillis())
+ .setRevision(randomAlphanumeric(50))
.setLast(true);
}