import java.util.Date;
import static org.sonar.api.utils.DateUtils.formatDateTime;
-import static org.sonar.api.utils.DateUtils.longToDate;
/**
* Used by views !!
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.getCreatedAtMs()))
+ "Latest quality snapshot: '" + formatDateTime(lastSnapshot.getCreatedAt())
+ "'. This property may only be used to rebuild the past in a chronological order.");
}
}
import org.sonar.batch.components.PastSnapshot;
import javax.annotation.CheckForNull;
-
import java.util.Date;
import java.util.List;
-import static org.sonar.api.utils.DateUtils.longToDate;
-
public class PastSnapshotFinderByDays implements BatchExtension {
private DatabaseSession session;
}
public PastSnapshot findFromDays(Snapshot projectSnapshot, int days) {
- Date targetDate = DateUtils.addDays(longToDate(projectSnapshot.getCreatedAtMs()), -days);
+ Date targetDate = DateUtils.addDays(projectSnapshot.getCreatedAt(), -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.getCreatedAtMs())
long bestDistance = Long.MAX_VALUE;
Snapshot nearest = null;
for (Snapshot snapshot : snapshots) {
- long distance = distance(longToDate(snapshot.getCreatedAtMs()), targetDate);
+ long distance = distance(snapshot.getCreatedAt(), targetDate);
if (distance <= bestDistance) {
bestDistance = distance;
nearest = snapshot;
package org.sonar.core.issue.db;
-import javax.annotation.CheckForNull;
-import javax.annotation.Nullable;
-
import java.util.Date;
-import static org.sonar.api.utils.DateUtils.dateToLong;
-import static org.sonar.api.utils.DateUtils.longToDate;
-
public class BatchIssueDto {
private String kee;
return this;
}
- @CheckForNull
public Date getCreationDate() {
- return longToDate(creationDate);
+ return new Date(creationDate);
}
- public BatchIssueDto setCreationDate(@Nullable Date creationDate) {
- this.creationDate = dateToLong(creationDate);
+ public BatchIssueDto setCreationDate(Date creationDate) {
+ this.creationDate = creationDate.getTime();
return this;
}
public class SemaphoreDaoTest extends AbstractDaoTestCase {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
private SemaphoreDao dao;
private System2 system;
dao = new SemaphoreDao(getMyBatis(), system);
}
- @Rule
- public ExpectedException thrown = ExpectedException.none();
+ @Test
+ public void should_fail_to_acquire_if_null_semaphore_name() {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Semaphore name must not be empty");
+
+ SemaphoreDao dao = new SemaphoreDao(getMyBatis(), system);
+ dao.acquire(null, 5000);
+ }
@Test
public void should_fail_to_acquire_if_blank_semaphore_name() {
thrown.expectMessage("Semaphore name must not be empty");
SemaphoreDao dao = new SemaphoreDao(getMyBatis(), system);
- dao.acquire(null, 5000);
+ dao.acquire("", 5000);
}
@Test
assertThat(selectSemaphore("foo")).isNull();
}
+ @Test
+ public void fail_to_update_null_semaphore() throws Exception {
+ thrown.expect(IllegalArgumentException.class);
+ thrown.expectMessage("Semaphore must not be null");
+
+ dao.update(null);
+ }
+
@Test
public void create_and_acquire_semaphore_when_maxage_is_zeo() throws Exception {
Semaphores.Semaphore lock = dao.acquire("foo", 0);