*/
package org.sonar.server.computation.analysis;
-import java.util.Date;
import javax.annotation.CheckForNull;
import org.sonar.server.computation.snapshot.Snapshot;
/**
* @throws IllegalStateException if no analysis date has been set
*/
- Date getAnalysisDate();
+ long getAnalysisDate();
/**
* Convenience method equivalent to calling {@link #getBaseProjectSnapshot() == null}
*/
package org.sonar.server.computation.analysis;
-import java.util.Date;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonar.server.computation.snapshot.Snapshot;
import org.sonar.server.computation.util.InitializedProperty;
-import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder {
private InitializedProperty<Integer> rootComponentRef = new InitializedProperty<>();
@Override
- public MutableAnalysisMetadataHolder setAnalysisDate(Date date) {
- checkNotNull(date, "Date must not be null");
+ public MutableAnalysisMetadataHolder setAnalysisDate(long date) {
checkState(!analysisDate.isInitialized(), "Analysis date has already been set");
- this.analysisDate.setProperty(date.getTime());
+ this.analysisDate.setProperty(date);
return this;
}
@Override
- public Date getAnalysisDate() {
+ public long getAnalysisDate() {
checkState(analysisDate.isInitialized(), "Analysis date has not been set");
- return new Date(this.analysisDate.getProperty());
+ return this.analysisDate.getProperty();
}
@Override
*/
package org.sonar.server.computation.analysis;
-import java.util.Date;
import javax.annotation.Nullable;
import org.sonar.server.computation.snapshot.Snapshot;
public interface MutableAnalysisMetadataHolder extends AnalysisMetadataHolder {
/**
- * @throws NullPointerException if specified date is {@code null}
* @throws IllegalStateException if the analysis date has already been set
*/
- MutableAnalysisMetadataHolder setAnalysisDate(Date date);
+ MutableAnalysisMetadataHolder setAnalysisDate(long date);
/**
* @throws IllegalStateException if baseProjectSnapshot has already been set
package org.sonar.server.computation.issue;
import com.google.common.annotations.VisibleForTesting;
+import java.util.Date;
import javax.annotation.Nullable;
import org.sonar.api.issue.Issue;
import org.sonar.core.issue.DefaultIssue;
private final DebtCalculator debtCalculator;
public IssueLifecycle(AnalysisMetadataHolder analysisMetadataHolder, IssueWorkflow workflow, IssueUpdater updater, DebtCalculator debtCalculator) {
- this(IssueChangeContext.createScan(analysisMetadataHolder.getAnalysisDate()), workflow, updater, debtCalculator);
+ this(IssueChangeContext.createScan(new Date(analysisMetadataHolder.getAnalysisDate())), workflow, updater, debtCalculator);
}
@VisibleForTesting
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.utils.DateUtils;
* Populates the {@link org.sonar.server.computation.period.PeriodsHolder}
* <p/>
* Here is how these periods are computed :
- * - Read the 5 period properties ${@link CoreProperties#TIMEMACHINE_PERIOD_PREFIX}
+ * - Read the 5 period properties ${@link org.sonar.core.config.CorePropertyDefinitions#TIMEMACHINE_PERIOD_PREFIX}
* - Try to find the matching snapshots from the properties
* - If a snapshot is found, a new period is added to the repository
*/
}
boolean isReportType = projectOrView.getType().isReportType();
- PeriodResolver periodResolver = new PeriodResolver(session, projectDto.get().getId(), analysisMetadataHolder.getAnalysisDate().getTime(),
+ PeriodResolver periodResolver = new PeriodResolver(session, projectDto.get().getId(), analysisMetadataHolder.getAnalysisDate(),
isReportType ? projectOrView.getReportAttributes().getVersion() : null,
isReportType ? Qualifiers.PROJECT : Qualifiers.VIEW);
package org.sonar.server.computation.step;
-import java.util.Date;
import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolder;
import org.sonar.server.computation.batch.BatchReportReader;
BatchReport.Metadata reportMetadata = reportReader.readMetadata();
mutableAnalysisMetadataHolder.setRootComponentRef(reportMetadata.getRootComponentRef());
mutableAnalysisMetadataHolder.setBranch(reportMetadata.hasBranch() ? reportMetadata.getBranch() : null);
- mutableAnalysisMetadataHolder.setAnalysisDate(new Date(reportMetadata.getAnalysisDate()));
+ mutableAnalysisMetadataHolder.setAnalysisDate(reportMetadata.getAnalysisDate());
mutableAnalysisMetadataHolder.setCrossProjectDuplicationEnabled(reportMetadata.hasCrossProjectDuplicationActivated() && reportMetadata.getCrossProjectDuplicationActivated());
}
public void execute() {
final DbSession session = dbClient.openSession(false);
try {
- long analysisDate = analysisMetadataHolder.getAnalysisDate().getTime();
+ long analysisDate = analysisMetadataHolder.getAnalysisDate();
new DepthTraversalTypeAwareCrawler(new PersistEventComponentVisitor(session, analysisDate))
.visit(treeRootHolder.getRoot());
session.commit();
DbSession session = dbClient.openSession(false);
try {
new PathAwareCrawler<>(
- new PersistSnapshotsPathAwareVisitor(session, analysisMetadataHolder.getAnalysisDate().getTime(), dbIdsRepository))
- .visit(treeRootHolder.getRoot());
+ new PersistSnapshotsPathAwareVisitor(session, analysisMetadataHolder.getAnalysisDate(), dbIdsRepository))
+ .visit(treeRootHolder.getRoot());
session.commit();
} finally {
dbClient.closeSession(session);
issues.close();
}
if (newIssuesStats.hasIssues()) {
- long analysisDate = analysisMetadataHolder.getAnalysisDate().getTime();
+ long analysisDate = analysisMetadataHolder.getAnalysisDate();
sendNewIssuesNotification(newIssuesStats, project, analysisDate);
sendNewIssuesNotificationToAssignees(newIssuesStats, project, analysisDate);
}
private void validateAnalysisDate(Optional<ComponentDto> baseProject) {
if (baseProject.isPresent()) {
SnapshotDto snapshotDto = dbClient.snapshotDao().selectLastSnapshotByComponentId(session, baseProject.get().getId());
- long currentAnalysisDate = analysisMetadataHolder.getAnalysisDate().getTime();
+ long currentAnalysisDate = analysisMetadataHolder.getAnalysisDate();
Long lastAnalysisDate = snapshotDto != null ? snapshotDto.getCreatedAt() : null;
if (lastAnalysisDate != null && currentAnalysisDate <= snapshotDto.getCreatedAt()) {
validationMessages.add(String.format("Date of analysis cannot be older than the date of the last known analysis on this project. Value: \"%s\". " +
*/
package org.sonar.server.computation.analysis;
-import java.util.Date;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
.setCreatedAt(123456789L)
.build();
- static Date SOME_DATE = new Date();
+ static long SOME_DATE = 10000000L;
@Test
public void getAnalysisDate_returns_date_with_same_time_as_the_one_set_with_setAnalysisDate() throws InterruptedException {
underTest.setAnalysisDate(SOME_DATE);
- Thread.sleep(10);
-
- Date analysisDate = underTest.getAnalysisDate();
- assertThat(analysisDate.getTime()).isEqualTo(SOME_DATE.getTime());
- assertThat(analysisDate).isNotSameAs(SOME_DATE);
+ assertThat(underTest.getAnalysisDate()).isEqualTo(SOME_DATE);
}
@Test
new AnalysisMetadataHolderImpl().getAnalysisDate();
}
- @Test
- public void setAnalysisDate_throws_NPE_when_date_is_null() {
- AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
-
- expectedException.expect(NullPointerException.class);
- expectedException.expectMessage("Date must not be null");
-
- underTest.setAnalysisDate(null);
- }
-
@Test
public void setAnalysisDate_throws_ISE_when_called_twice() {
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl();
return this;
}
+ public AnalysisMetadataHolderRule setAnalysisDate(long date) {
+ checkNotNull(date, "Date must not be null");
+ this.analysisDate.setProperty(date);
+ return this;
+ }
+
@Override
- public Date getAnalysisDate() {
+ public long getAnalysisDate() {
checkState(analysisDate.isInitialized(), "Analysis date has not been set");
- return new Date(this.analysisDate.getProperty());
+ return this.analysisDate.getProperty();
}
@Override
*/
package org.sonar.server.computation.analysis;
-import java.util.Date;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.junit.rules.ExternalResource;
}
@Override
- public Date getAnalysisDate() {
+ public long getAnalysisDate() {
return delegate.getAnalysisDate();
}
- public MutableAnalysisMetadataHolderRule setAnalysisDate(Date date) {
+ public MutableAnalysisMetadataHolderRule setAnalysisDate(long date) {
delegate.setAnalysisDate(date);
return this;
}
import com.tngtech.java.junit.dataprovider.DataProvider;
import com.tngtech.java.junit.dataprovider.DataProviderRunner;
import com.tngtech.java.junit.dataprovider.UseDataProvider;
-import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
static final String REPORT_DIR_KEY_2 = "src/main/java/dir2";
static final String REPORT_FILE_KEY_2 = "src/main/java/dir2/File2.java";
- static final Date ANALYSIS_DATE = new Date();
+ static final long ANALYSIS_DATE = 123456789L;
@Rule
public DbTester dbTester = DbTester.create(System2.INSTANCE);
@Before
public void setUp() throws Exception {
- analysisMetadataHolder.setAnalysisDate(DATE_FORMAT.parse("2008-11-30"));
+ analysisMetadataHolder.setAnalysisDate(DATE_FORMAT.parse("2008-11-30").getTime());
underTest = new LoadPeriodsStep(dbClient, settingsRepository, treeRootHolder, analysisMetadataHolder, periodsHolder);
}
@Before
public void setup() {
when(system2.now()).thenReturn(1225630680000L);
- analysisMetadataHolder.setAnalysisDate(someDate);
+ analysisMetadataHolder.setAnalysisDate(someDate.getTime());
step = new PersistEventsStep(dbTester.getDbClient(), system2, treeRootHolder, analysisMetadataHolder, eventRepository, dbIdsRepository);
when(eventRepository.getEvents(any(Component.class))).thenReturn(Collections.<Event>emptyList());
}
package org.sonar.server.computation.step;
-import java.util.Date;
import java.util.List;
import org.junit.Before;
import org.junit.Rule;
public void setup() {
dbTester.truncateTables();
analysisDate = DateUtils.parseDateQuietly("2015-06-01").getTime();
- analysisMetadataHolder.setAnalysisDate(new Date(analysisDate));
+ analysisMetadataHolder.setAnalysisDate(analysisDate);
dbIdsRepository = new DbIdsRepositoryImpl();
now = DateUtils.parseDateQuietly("2015-06-02").getTime();
package org.sonar.server.computation.step;
-import java.util.Date;
import java.util.List;
import org.junit.Before;
import org.junit.Rule;
public void setup() {
dbTester.truncateTables();
analysisDate = DateUtils.parseDateQuietly("2015-06-01").getTime();
- analysisMetadataHolder.setAnalysisDate(new Date(analysisDate));
+ analysisMetadataHolder.setAnalysisDate(analysisDate);
now = DateUtils.parseDateQuietly("2015-06-02").getTime();