int periodIndex = pastSnapshot.getIndex();
snapshot.setPeriodMode(periodIndex, pastSnapshot.getMode());
snapshot.setPeriodModeParameter(periodIndex, pastSnapshot.getModeParameter());
- snapshot.setPeriodDate(periodIndex, dateToLong(pastSnapshot.getDate()));
+ snapshot.setPeriodDateMs(periodIndex, dateToLong(pastSnapshot.getDate()));
}
}
ResourceModel persistedProject = databaseSession.getSingleResult(ResourceModel.class, "key", projectKey, "enabled", true);
if (persistedProject != null) {
Snapshot lastSnapshot = databaseSession.getSingleResult(Snapshot.class, "resourceId", persistedProject.getId(), "last", true);
- boolean analysisBeforeLastSnapshot = lastSnapshot != null && analysisDate.getTime() <= lastSnapshot.getCreatedAt();
+ boolean analysisBeforeLastSnapshot = lastSnapshot != null && analysisDate.getTime() <= lastSnapshot.getCreatedAtMs();
if (analysisBeforeLastSnapshot) {
throw new IllegalArgumentException(
"'sonar.projectDate' property cannot be older than the date of the last known quality snapshot on this project. Value: '" +
settings.getString(CoreProperties.PROJECT_DATE_PROPERTY) + "'. " +
- "Latest quality snapshot: '" + formatDateTime(longToDate(lastSnapshot.getCreatedAt()))
+ "Latest quality snapshot: '" + formatDateTime(longToDate(lastSnapshot.getCreatedAtMs()))
+ "'. This property may only be used to rebuild the past in a chronological order.");
}
}
}
public Date getDate() {
- return projectSnapshot != null ? longToDate(projectSnapshot.getCreatedAt()) : null;
+ return projectSnapshot != null ? longToDate(projectSnapshot.getCreatedAtMs()) : null;
}
public PastSnapshot setMode(String mode) {
}
PastSnapshot findFromDays(Snapshot projectSnapshot, int days) {
- Date targetDate = DateUtils.addDays(longToDate(projectSnapshot.getCreatedAt()), -days);
+ Date targetDate = DateUtils.addDays(longToDate(projectSnapshot.getCreatedAtMs()), -days);
String hql = "from " + Snapshot.class.getSimpleName() + " where resourceId=:resourceId AND status=:status AND createdAt<:date AND qualifier<>:lib order by createdAt asc";
List<Snapshot> snapshots = session.createQuery(hql)
- .setParameter("date", projectSnapshot.getCreatedAt())
+ .setParameter("date", projectSnapshot.getCreatedAtMs())
.setParameter("resourceId", projectSnapshot.getResourceId())
.setParameter("status", Snapshot.STATUS_PROCESSED)
.setParameter("lib", Qualifiers.LIBRARY)
long bestDistance = Long.MAX_VALUE;
Snapshot nearest = null;
for (Snapshot snapshot : snapshots) {
- long distance = distance(longToDate(snapshot.getCreatedAt()), targetDate);
+ long distance = distance(longToDate(snapshot.getCreatedAtMs()), targetDate);
if (distance <= bestDistance) {
bestDistance = distance;
nearest = snapshot;
String hql = "from " + Snapshot.class.getSimpleName()
+ " where createdAt<:date AND resourceId=:resourceId AND status=:status and last=:last and qualifier<>:lib order by createdAt desc";
List<Snapshot> snapshots = session.createQuery(hql)
- .setParameter("date", projectSnapshot.getCreatedAt())
+ .setParameter("date", projectSnapshot.getCreatedAtMs())
.setParameter("resourceId", projectSnapshot.getResourceId())
.setParameter("status", Snapshot.STATUS_PROCESSED)
.setParameter("last", true)
return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
}
Snapshot snapshot = snapshots.get(0);
- Date targetDate = longToDate(snapshot.getCreatedAt());
+ Date targetDate = longToDate(snapshot.getCreatedAtMs());
SimpleDateFormat format = new SimpleDateFormat(DateUtils.DATE_FORMAT);
return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, targetDate, snapshot).setModeParameter(format.format(targetDate));
}
Event previousVersionEvent = events.get(0);
Snapshot snapshot = session.getSingleResult(Snapshot.class, "id", previousVersionEvent.getSnapshot().getId());
- return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, longToDate(snapshot.getCreatedAt()), snapshot).setModeParameter(snapshot.getVersion());
+ return new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, longToDate(snapshot.getCreatedAtMs()), snapshot).setModeParameter(snapshot.getVersion());
}
}
result = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION);
} else {
Snapshot snapshot = snapshots.get(0);
- Date targetDate = longToDate(snapshot.getCreatedAt());
+ Date targetDate = longToDate(snapshot.getCreatedAtMs());
result = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, targetDate, snapshot).setModeParameter(version);
}
return result;
if (projectId != null) {
snapshot = new Snapshot();
snapshot.setResourceId(projectId.intValue());
- snapshot.setCreatedAt(dateToLong(projectTree.getRootProject().getAnalysisDate()));
- snapshot.setBuildDate(System.currentTimeMillis());
+ snapshot.setCreatedAtMs(dateToLong(projectTree.getRootProject().getAnalysisDate()));
+ snapshot.setBuildDateMs(System.currentTimeMillis());
snapshot.setVersion(projectTree.getRootProject().getAnalysisVersion());
}
return snapshot;
PastSnapshot pastSnapshot = projectPastSnapshot.clonePastSnapshot();
modulePastSnapshots.add(pastSnapshot);
// When no snapshot is found, date of the period is null
- periods.add(new Period(pastSnapshot.getIndex(), snapshot != null ? longToDate(snapshot.getCreatedAt()) : null));
+ periods.add(new Period(pastSnapshot.getIndex(), snapshot != null ? longToDate(snapshot.getCreatedAtMs()) : null));
log(pastSnapshot);
}
}
Snapshot snapshot = new Snapshot(model, parentSnapshot);
snapshot.setVersion(project.getAnalysisVersion());
- snapshot.setCreatedAt(dateToLong(project.getAnalysisDate()));
- snapshot.setBuildDate(System.currentTimeMillis());
+ snapshot.setCreatedAtMs(dateToLong(project.getAnalysisDate()));
+ snapshot.setBuildDateMs(System.currentTimeMillis());
snapshot = session.save(snapshot);
session.commit();
Snapshot snapshot = findLibrarySnapshot(model.getId(), library.getVersion());
if (snapshot == null) {
snapshot = new Snapshot(model, null);
- snapshot.setCreatedAt(dateToLong(analysisDate));
- snapshot.setBuildDate(System.currentTimeMillis());
+ snapshot.setCreatedAtMs(dateToLong(analysisDate));
+ snapshot.setBuildDateMs(System.currentTimeMillis());
snapshot.setVersion(library.getVersion());
snapshot.setStatus(Snapshot.STATUS_PROCESSED);
}
Snapshot snapshot = new Snapshot(model, parentSnapshot);
- snapshot.setBuildDate(System.currentTimeMillis());
+ snapshot.setBuildDateMs(System.currentTimeMillis());
snapshot = session.save(snapshot);
session.commit();
return snapshot;
private Snapshot newSnapshot(int id, String date) throws ParseException {
Snapshot snapshot = new Snapshot();
snapshot.setId(id);
- snapshot.setCreatedAt(dateFormat.parse(date).getTime());
+ snapshot.setCreatedAtMs(dateFormat.parse(date).getTime());
return snapshot;
}
}
public void should_find_by_previous_analysis() throws ParseException {
final Date date = DateUtils.parseDate("2010-05-18");
Snapshot snapshot = new Snapshot();
- snapshot.setCreatedAt(date.getTime());
+ snapshot.setCreatedAtMs(date.getTime());
when(finderByPreviousAnalysis.findByPreviousAnalysis(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, date, snapshot));
PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS);
final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
final Date date = format.parse("2010-05-18");
Snapshot snapshot = new Snapshot();
- snapshot.setCreatedAt(date.getTime());
+ snapshot.setCreatedAtMs(date.getTime());
when(finderByPreviousVersion.findByPreviousVersion(null)).thenReturn(new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, date, snapshot));
PastSnapshot variationSnapshot = finder.find(null, 2, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION);
@Test
public void test_some_setters_and_getters() {
- Snapshot snapshot = new Snapshot().setQualifier(Qualifiers.FILE).setCreatedAt(System.currentTimeMillis());
+ Snapshot snapshot = new Snapshot().setQualifier(Qualifiers.FILE).setCreatedAtMs(System.currentTimeMillis());
snapshot.setId(10);
PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(),
snapshot)
@Test
public void testToStringForVersion() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(), new Snapshot().setCreatedAt(System.currentTimeMillis())).setModeParameter("2.3");
+ PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis())).setModeParameter("2.3");
assertThat(pastSnapshot.toString()).startsWith("Compare to version 2.3");
}
@Test
public void testToStringForNumberOfDaysWithSnapshot() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DAYS, new Date(), new Snapshot().setCreatedAt(System.currentTimeMillis())).setModeParameter("30");
+ PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DAYS, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis())).setModeParameter("30");
assertThat(pastSnapshot.toString()).startsWith("Compare over 30 days (");
}
@Test
public void testToStringForDateWithSnapshot() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DATE, new Date(), new Snapshot().setCreatedAt(System.currentTimeMillis()));
+ PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_DATE, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis()));
assertThat(pastSnapshot.toString()).startsWith("Compare to date ");
}
@Test
public void testToStringForPreviousAnalysis() {
- PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot().setCreatedAt(System.currentTimeMillis()));
+ PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, new Date(), new Snapshot().setCreatedAtMs(System.currentTimeMillis()));
assertThat(pastSnapshot.toString()).startsWith("Compare to previous analysis ");
}
public final void setSnapshot(Snapshot snapshot) {
this.snapshot = snapshot;
if (snapshot != null) {
- this.date = (snapshot.getCreatedAt() == null ? null : new Date(snapshot.getCreatedAt()));
+ this.date = (snapshot.getCreatedAtMs() == null ? null : new Date(snapshot.getCreatedAtMs()));
this.resourceId = snapshot.getResourceId();
}
}
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
+
import java.io.Serializable;
import java.util.Date;
+import static org.sonar.api.utils.DateUtils.dateToLong;
+import static org.sonar.api.utils.DateUtils.longToDate;
+
/**
* A class to map a snapshot with its hibernate model
*/
} else {
this.parentId = parent.getId();
this.rootId = (parent.getRootId() == null ? parent.getId() : parent.getRootId());
- this.createdAt = parent.getCreatedAt();
+ this.createdAt = parent.getCreatedAtMs();
this.depth = parent.getDepth() + 1;
this.path = new StringBuilder()
.append(parent.getPath())
*
* @since 2.14
*/
- public Long getBuildDate() {
+ public Date getBuildDate() {
+ return longToDate(buildDate);
+ }
+
+ public Long getBuildDateMs() {
return buildDate;
}
*
* @since 2.14
*/
- public Snapshot setBuildDate(Long d) {
+ public Snapshot setBuildDate(Date date) {
+ this.buildDate = dateToLong(date);
+ return this;
+ }
+
+ public Snapshot setBuildDateMs(Long d) {
this.buildDate = d;
return this;
}
- public Long getCreatedAt() {
+ public Date getCreatedAt() {
+ return longToDate(createdAt);
+ }
+
+ public Long getCreatedAtMs() {
return createdAt;
}
- public Snapshot setCreatedAt(Long createdAt) {
+ public Snapshot setCreatedAt(Date createdAt) {
+ this.createdAt = dateToLong(createdAt);
+ return this;
+ }
+
+ public Snapshot setCreatedAtMs(Long createdAt) {
this.createdAt = createdAt;
return this;
}
return this;
}
- public Long getPeriod1Date() {
+ public Date getPeriod1Date() {
+ return longToDate(period1Date);
+ }
+
+ public Long getPeriod1DateMs() {
return period1Date;
}
*
* @since 2.5
*/
- public Snapshot setPeriod1Date(Long period1Date) {
+ public Snapshot setPeriod1Date(Date period1Date) {
+ this.period1Date = dateToLong(period1Date);
+ return this;
+ }
+
+ public Snapshot setPeriod1DateMs(Long period1Date) {
this.period1Date = period1Date;
return this;
}
- public Long getPeriod2Date() {
+ public Date getPeriod2Date() {
+ return longToDate(period2Date);
+ }
+
+ public Long getPeriod2DateMs() {
return period2Date;
}
*
* @since 2.5
*/
- public Snapshot setPeriod2Date(Long period2Date) {
+ public Snapshot setPeriod2Date(Date period2Date) {
+ this.period2Date = dateToLong(period2Date);
+ return this;
+ }
+
+ public Snapshot setPeriod2DateMs(Long period2Date) {
this.period2Date = period2Date;
return this;
}
- public Long getPeriod3Date() {
+ public Date getPeriod3Date() {
+ return longToDate(period3Date);
+ }
+
+ public Long getPeriod3DateMs() {
return period3Date;
}
*
* @since 2.5
*/
- public Snapshot setPeriod3Date(Long period3Date) {
+ public Snapshot setPeriod3Date(Date period3Date) {
+ this.period3Date = dateToLong(period3Date);
+ return this;
+ }
+
+ public Snapshot setPeriod3DateMs(Long period3Date) {
this.period3Date = period3Date;
return this;
}
- public Long getPeriod4Date() {
+ public Date getPeriod4Date() {
+ return longToDate(period4Date);
+ }
+
+ public Long getPeriod4DateMs() {
return period4Date;
}
*
* @since 2.5
*/
- public Snapshot setPeriod4Date(Long period4Date) {
+ public Snapshot setPeriod4Date(Date period4Date) {
+ this.period4Date = dateToLong(period4Date);
+ return this;
+ }
+
+ public Snapshot setPeriod4DateMs(Long period4Date) {
this.period4Date = period4Date;
return this;
}
- public Long getPeriod5Date() {
+ public Date getPeriod5Date() {
+ return longToDate(period5Date);
+ }
+
+ public Long getPeriod5DateMs() {
return period5Date;
}
*
* @since 2.5
*/
- public Snapshot setPeriod5Date(Long period5Date) {
+ public Snapshot setPeriod5Date(Date period5Date) {
+ this.period5Date = dateToLong(period5Date);
+ return this;
+ }
+
+ public Snapshot setPeriod5DateMs(Long period5Date) {
this.period5Date = period5Date;
return this;
}
*
* @since 2.5
*/
- public Snapshot setPeriodDate(int periodIndex, Long date) {
+ public Snapshot setPeriodDateMs(int periodIndex, Long date) {
switch (periodIndex) {
case 1:
period1Date = date;
Snapshot other = (Snapshot) obj;
return new EqualsBuilder()
.append(resourceId, other.getResourceId())
- .append(createdAt, other.getCreatedAt())
+ .append(createdAt, other.getCreatedAtMs())
.isEquals();
}
@Test
public void testGetDate() {
Snapshot snapshot = new Snapshot();
- assertNull(snapshot.getCreatedAt());
+ assertNull(snapshot.getCreatedAtMs());
Long now = System.currentTimeMillis();
- snapshot.setCreatedAt(now);
- assertEquals(now, snapshot.getCreatedAt());
+ snapshot.setCreatedAtMs(now);
+ assertEquals(now, snapshot.getCreatedAtMs());
}
@Test