diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-02-04 17:18:05 +0100 |
---|---|---|
committer | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2015-02-04 17:58:21 +0100 |
commit | 070c3e240aec5697ef7e715fc18bacdb14fce9ef (patch) | |
tree | fb5ab1f7c13f1d90a5acb1fc0996cae7c7bed34a /sonar-plugin-api/src | |
parent | 67d215ac9c43b048885d072e12de759855e4b80a (diff) | |
download | sonarqube-070c3e240aec5697ef7e715fc18bacdb14fce9ef.tar.gz sonarqube-070c3e240aec5697ef7e715fc18bacdb14fce9ef.zip |
SONAR-5183 - analysis unsensitive to timezones - snapshots table
Diffstat (limited to 'sonar-plugin-api/src')
5 files changed, 46 insertions, 56 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java index edafda1b3c8..406161ed758 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/Event.java @@ -23,13 +23,7 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.database.BaseIdentifiable; import org.sonar.api.database.model.Snapshot; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - +import javax.persistence.*; import java.util.Date; /** @@ -131,7 +125,7 @@ public class Event extends BaseIdentifiable { public final void setSnapshot(Snapshot snapshot) { this.snapshot = snapshot; if (snapshot != null) { - this.date = snapshot.getCreatedAt(); + this.date = (snapshot.getCreatedAt() == null ? null : new Date(snapshot.getCreatedAt())); this.resourceId = snapshot.getResourceId(); } } diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java index 0912b7d6675..347690a8a21 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java @@ -29,9 +29,6 @@ import org.sonar.api.database.DatabaseSession; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; - import java.io.Serializable; import java.util.Date; @@ -55,13 +52,11 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable @Column(name = "project_id", updatable = true, nullable = true) private Integer resourceId; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "build_date", updatable = true, nullable = true) - private Date buildDate; + private Long buildDate; - @Temporal(TemporalType.TIMESTAMP) @Column(name = "created_at", updatable = true, nullable = true) - private Date createdAt; + private Long createdAt; @Column(name = "version", updatable = true, nullable = true, length = 500) private String version; @@ -127,19 +122,19 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable private String period5Param; @Column(name = "period1_date", updatable = true, nullable = true) - private Date period1Date; + private Long period1Date; @Column(name = "period2_date", updatable = true, nullable = true) - private Date period2Date; + private Long period2Date; @Column(name = "period3_date", updatable = true, nullable = true) - private Date period3Date; + private Long period3Date; @Column(name = "period4_date", updatable = true, nullable = true) - private Date period4Date; + private Long period4Date; @Column(name = "period5_date", updatable = true, nullable = true) - private Date period5Date; + private Long period5Date; public Snapshot() { @@ -153,7 +148,7 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable if (parent == null) { path = ""; depth = 0; - this.createdAt = new Date(); + this.createdAt = System.currentTimeMillis(); } else { this.parentId = parent.getId(); @@ -188,7 +183,7 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable setResource(resource); this.status = status; this.last = last; - this.createdAt = date; + this.createdAt = date.getTime(); } /** @@ -196,7 +191,7 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable * * @since 2.14 */ - public Date getBuildDate() { + public Long getBuildDate() { return buildDate; } @@ -205,16 +200,16 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable * * @since 2.14 */ - public Snapshot setBuildDate(Date d) { + public Snapshot setBuildDate(Long d) { this.buildDate = d; return this; } - public Date getCreatedAt() { + public Long getCreatedAt() { return createdAt; } - public Snapshot setCreatedAt(Date createdAt) { + public Snapshot setCreatedAt(Long createdAt) { this.createdAt = createdAt; return this; } @@ -279,8 +274,8 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable } /** - * @since 2.14 - */ + * @since 2.14 + */ public Snapshot setPurgeStatus(Integer i) { this.purgeStatus = i; return this; @@ -487,7 +482,7 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable return this; } - public Date getPeriod1Date() { + public Long getPeriod1Date() { return period1Date; } @@ -496,12 +491,12 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable * * @since 2.5 */ - public Snapshot setPeriod1Date(Date period1Date) { + public Snapshot setPeriod1Date(Long period1Date) { this.period1Date = period1Date; return this; } - public Date getPeriod2Date() { + public Long getPeriod2Date() { return period2Date; } @@ -510,12 +505,12 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable * * @since 2.5 */ - public Snapshot setPeriod2Date(Date period2Date) { + public Snapshot setPeriod2Date(Long period2Date) { this.period2Date = period2Date; return this; } - public Date getPeriod3Date() { + public Long getPeriod3Date() { return period3Date; } @@ -524,12 +519,12 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable * * @since 2.5 */ - public Snapshot setPeriod3Date(Date period3Date) { + public Snapshot setPeriod3Date(Long period3Date) { this.period3Date = period3Date; return this; } - public Date getPeriod4Date() { + public Long getPeriod4Date() { return period4Date; } @@ -538,12 +533,12 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable * * @since 2.5 */ - public Snapshot setPeriod4Date(Date period4Date) { + public Snapshot setPeriod4Date(Long period4Date) { this.period4Date = period4Date; return this; } - public Date getPeriod5Date() { + public Long getPeriod5Date() { return period5Date; } @@ -552,7 +547,7 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable * * @since 2.5 */ - public Snapshot setPeriod5Date(Date period5Date) { + public Snapshot setPeriod5Date(Long period5Date) { this.period5Date = period5Date; return this; } @@ -652,22 +647,22 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable * * @since 2.5 */ - public Snapshot setPeriodDate(int periodIndex, Date d) { + public Snapshot setPeriodDate(int periodIndex, Long date) { switch (periodIndex) { case 1: - period1Date = d; + period1Date = date; break; case 2: - period2Date = d; + period2Date = date; break; case 3: - period3Date = d; + period3Date = date; break; case 4: - period4Date = d; + period4Date = date; break; case 5: - period5Date = d; + period5Date = date; break; default: throw new IndexOutOfBoundsException("Index of Snapshot.periodDate is between 1 and 5"); @@ -675,7 +670,7 @@ public class Snapshot extends BaseIdentifiable<Snapshot> implements Serializable return this; } - public Date getPeriodDate(int periodIndex) { + public Long getPeriodDate(int periodIndex) { switch (periodIndex) { case 1: return period1Date; diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java index 1ff7bc4ac4a..6be43c827ea 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/DateUtils.java @@ -19,8 +19,8 @@ */ package org.sonar.api.utils; +import javax.annotation.CheckForNull; import javax.annotation.Nullable; - import java.io.NotSerializableException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -60,10 +60,16 @@ public final class DateUtils { return date == null ? "" : THREAD_SAFE_DATETIME_FORMAT.format(date); } - public static Date timeToDate(@Nullable Long time) { + @CheckForNull + public static Date longToDate(@Nullable Long time) { return time == null ? null : new Date(time); } + @CheckForNull + public static Long dateToLong(@Nullable Date date) { + return date == null ? null : date.getTime(); + } + /** * @param s string in format {@link #DATE_FORMAT} * @throws SonarException when string cannot be parsed diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java index 5a0c8427a51..c102f844234 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/SnapshotTest.java @@ -21,13 +21,8 @@ package org.sonar.api.database.model; import org.junit.Test; -import java.util.Date; - import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.*; public class SnapshotTest { @@ -36,7 +31,7 @@ public class SnapshotTest { Snapshot snapshot = new Snapshot(); assertNull(snapshot.getCreatedAt()); - Date now = new Date(); + Long now = System.currentTimeMillis(); snapshot.setCreatedAt(now); assertEquals(now, snapshot.getCreatedAt()); } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java index 888ceeb4c69..7aa32f3cb20 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java @@ -109,8 +109,8 @@ public class DateUtilsTest { @Test public void time_to_date() throws Exception { Date date = new Date(); - Assertions.assertThat(DateUtils.timeToDate(date.getTime())).isEqualTo(date); - Assertions.assertThat(DateUtils.timeToDate(null)).isNull(); + Assertions.assertThat(DateUtils.longToDate(date.getTime())).isEqualTo(date); + Assertions.assertThat(DateUtils.longToDate(null)).isNull(); } /** |