]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11950 add SnapshotDto#revision
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 6 May 2019 14:43:28 +0000 (16:43 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 22 May 2019 18:21:16 +0000 (20:21 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/component/SnapshotDto.java
server/sonar-db-dao/src/main/resources/org/sonar/db/component/SnapshotMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/component/SnapshotTesting.java

index 7cdbdba7c519645a4cc3841dd5792ea5979fcbcc..058c7ce71dc126b5a518e26e025a10160e1935ce 100644 (file)
@@ -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) {
index 7c760b5d5df022ad14db6b9bfce3e3514ef92add..b4a648e2828d78abcff3ddd613647de7ba748b5a 100644 (file)
@@ -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">
       build_string,
       period1_mode,
       period1_param,
-      period1_date
+      period1_date,
+      revision
     )
     values (
       #{uuid, jdbcType=VARCHAR},
       #{buildString, jdbcType=VARCHAR},
       #{periodMode, jdbcType=VARCHAR},
       #{periodParam, jdbcType=VARCHAR},
-      #{periodDate, jdbcType=BIGINT}
+      #{periodDate, jdbcType=BIGINT},
+      #{revision, jdbcType=VARCHAR}
     )
   </insert>
 </mapper>
index 62592fb6d8248e2dc53d9e0fd915d9d0bc699860..bd601aa277be626116a708fee938d7709bd9a97c 100644 (file)
@@ -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();
   }
index 32f945887b4f186a329f83fb130614b196cddfa1..1f65b38e2b2c933deb062002f3633a7bf8abd789 100644 (file)
@@ -35,6 +35,7 @@ public class SnapshotTesting {
       .setStatus(SnapshotDto.STATUS_PROCESSED)
       .setCreatedAt(System.currentTimeMillis())
       .setBuildDate(System.currentTimeMillis())
+      .setRevision(randomAlphanumeric(50))
       .setLast(true);
   }