Period 1 is renamed 'Leak Period' and set to 'since previous version' Period 2 is now set to 'since previous analyis' Period 3 is now set to 'over 30 days'tags/5.3-RC1
@@ -50,6 +50,12 @@ import org.sonar.server.computation.component.TypeAwareVisitorAdapter; | |||
import org.sonar.server.computation.period.Period; | |||
import org.sonar.server.computation.period.PeriodsHolderImpl; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_DATE; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_DAYS; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_PREVIOUS_VERSION; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_VERSION; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_PERIOD_PREFIX; | |||
import static org.sonar.db.component.SnapshotDto.STATUS_PROCESSED; | |||
import static org.sonar.db.component.SnapshotQuery.SORT_FIELD.BY_DATE; | |||
import static org.sonar.db.component.SnapshotQuery.SORT_ORDER.ASC; | |||
@@ -162,7 +168,7 @@ public class LoadPeriodsStep implements ComputationStep { | |||
} | |||
Period period = resolve(index, propertyValue); | |||
if (period == null && StringUtils.isNotBlank(propertyValue)) { | |||
LOG.debug("Property " + CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index + " is not valid: " + propertyValue); | |||
LOG.debug("Property " + TIMEMACHINE_PERIOD_PREFIX + index + " is not valid: " + propertyValue); | |||
} | |||
return period; | |||
} | |||
@@ -177,10 +183,10 @@ public class LoadPeriodsStep implements ComputationStep { | |||
if (date != null) { | |||
return findByDate(index, date); | |||
} | |||
if (StringUtils.equals(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, property)) { | |||
if (StringUtils.equals(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, property)) { | |||
return findByPreviousAnalysis(index); | |||
} | |||
if (StringUtils.equals(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, property)) { | |||
if (StringUtils.equals(TIMEMACHINE_MODE_PREVIOUS_VERSION, property)) { | |||
return findByPreviousVersion(index); | |||
} | |||
return findByVersion(index, property); | |||
@@ -192,7 +198,7 @@ public class LoadPeriodsStep implements ComputationStep { | |||
return null; | |||
} | |||
LOG.debug("Compare to date {} (analysis of {})", formatDate(date.getTime()), formatDate(snapshot.getCreatedAt())); | |||
return new Period(index, CoreProperties.TIMEMACHINE_MODE_DATE, DateUtils.formatDate(date), snapshot.getCreatedAt(), snapshot.getId()); | |||
return new Period(index, TIMEMACHINE_MODE_DATE, DateUtils.formatDate(date), snapshot.getCreatedAt(), snapshot.getId()); | |||
} | |||
@CheckForNull | |||
@@ -204,7 +210,7 @@ public class LoadPeriodsStep implements ComputationStep { | |||
return null; | |||
} | |||
LOG.debug("Compare over {} days ({}, analysis of {})", String.valueOf(days), formatDate(targetDate), formatDate(snapshot.getCreatedAt())); | |||
return new Period(index, CoreProperties.TIMEMACHINE_MODE_DAYS, String.valueOf(days), snapshot.getCreatedAt(), snapshot.getId()); | |||
return new Period(index, TIMEMACHINE_MODE_DAYS, String.valueOf(days), snapshot.getCreatedAt(), snapshot.getId()); | |||
} | |||
@CheckForNull | |||
@@ -214,7 +220,7 @@ public class LoadPeriodsStep implements ComputationStep { | |||
return null; | |||
} | |||
LOG.debug("Compare to previous analysis ({})", formatDate(snapshot.getCreatedAt())); | |||
return new Period(index, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, formatDate(snapshot.getCreatedAt()), snapshot.getCreatedAt(), snapshot.getId()); | |||
return new Period(index, TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, formatDate(snapshot.getCreatedAt()), snapshot.getCreatedAt(), snapshot.getId()); | |||
} | |||
@CheckForNull | |||
@@ -229,7 +235,7 @@ public class LoadPeriodsStep implements ComputationStep { | |||
} | |||
SnapshotDto snapshotDto = snapshotDtos.get(0); | |||
LOG.debug("Compare to previous version ({})", formatDate(snapshotDto.getCreatedAt())); | |||
return new Period(index, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, snapshotDto.getVersion(), snapshotDto.getCreatedAt(), snapshotDto.getId()); | |||
return new Period(index, TIMEMACHINE_MODE_PREVIOUS_VERSION, snapshotDto.getVersion(), snapshotDto.getCreatedAt(), snapshotDto.getId()); | |||
} | |||
@CheckForNull | |||
@@ -239,7 +245,7 @@ public class LoadPeriodsStep implements ComputationStep { | |||
return null; | |||
} | |||
LOG.debug("Compare to first analysis ({})", formatDate(snapshotDto.getCreatedAt())); | |||
return new Period(index, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, null, snapshotDto.getCreatedAt(), snapshotDto.getId()); | |||
return new Period(index, TIMEMACHINE_MODE_PREVIOUS_VERSION, null, snapshotDto.getCreatedAt(), snapshotDto.getId()); | |||
} | |||
@CheckForNull | |||
@@ -249,7 +255,7 @@ public class LoadPeriodsStep implements ComputationStep { | |||
return null; | |||
} | |||
LOG.debug("Compare to version ({}) ({})", version, formatDate(snapshot.getCreatedAt())); | |||
return new Period(index, CoreProperties.TIMEMACHINE_MODE_VERSION, version, snapshot.getCreatedAt(), snapshot.getId()); | |||
return new Period(index, TIMEMACHINE_MODE_VERSION, version, snapshot.getCreatedAt(), snapshot.getId()); | |||
} | |||
@CheckForNull | |||
@@ -295,10 +301,10 @@ public class LoadPeriodsStep implements ComputationStep { | |||
} | |||
private static String getPropertyValue(@Nullable String qualifier, Settings settings, int index) { | |||
String value = settings.getString(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index); | |||
String value = settings.getString(TIMEMACHINE_PERIOD_PREFIX + index); | |||
// For periods 4 and 5 we're also searching for a property prefixed by the qualifier | |||
if (index > 3 && Strings.isNullOrEmpty(value)) { | |||
value = settings.getString(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + index + "." + qualifier); | |||
value = settings.getString(TIMEMACHINE_PERIOD_PREFIX + index + "." + qualifier); | |||
} | |||
return value; | |||
} |
@@ -41,8 +41,8 @@ import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verifyNoMoreInteractions; | |||
import static org.mockito.Mockito.verifyZeroInteractions; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.api.CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS; | |||
import static org.sonar.api.issue.Issue.RESOLUTION_FIXED; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS; | |||
public class NewDebtAggregatorTest { | |||
@@ -25,7 +25,6 @@ import java.util.Date; | |||
import java.util.List; | |||
import javax.annotation.Nullable; | |||
import org.junit.Test; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.utils.Duration; | |||
import org.sonar.core.issue.DefaultIssue; | |||
import org.sonar.core.issue.FieldDiffs; | |||
@@ -33,6 +32,7 @@ import org.sonar.db.issue.IssueChangeDto; | |||
import org.sonar.server.computation.period.Period; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_PREVIOUS_VERSION; | |||
public class NewDebtCalculatorTest { | |||
@@ -44,7 +44,7 @@ public class NewDebtCalculatorTest { | |||
private static final Duration TEN_DAYS = Duration.create(10 * HOURS_IN_DAY * 60 * 60L); | |||
private static final long PERIOD_DATE = 150000000L; | |||
private static final long SNAPSHOT_ID = 1000L; | |||
private static final Period PERIOD = new Period(1, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, null, PERIOD_DATE, SNAPSHOT_ID); | |||
private static final Period PERIOD = new Period(1, TIMEMACHINE_MODE_PREVIOUS_VERSION, null, PERIOD_DATE, SNAPSHOT_ID); | |||
DefaultIssue issue = new DefaultIssue(); | |||
NewDebtCalculator underTest = new NewDebtCalculator(); |
@@ -23,9 +23,9 @@ package org.sonar.server.computation.period; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.CoreProperties; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_VERSION; | |||
public class PeriodTest { | |||
@@ -39,9 +39,9 @@ public class PeriodTest { | |||
@Test | |||
public void test_some_setters_and_getters() { | |||
Period period = new Period(1, CoreProperties.TIMEMACHINE_MODE_VERSION, SOME_MODE_PARAM, SOME_SNAPSHOT_DATE, SOME_SNAPSHOT_ID); | |||
Period period = new Period(1, TIMEMACHINE_MODE_VERSION, SOME_MODE_PARAM, SOME_SNAPSHOT_DATE, SOME_SNAPSHOT_ID); | |||
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION); | |||
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_VERSION); | |||
assertThat(period.getModeParameter()).isEqualTo(SOME_MODE_PARAM); | |||
assertThat(period.getIndex()).isEqualTo(1); | |||
assertThat(period.getSnapshotDate()).isEqualTo(SOME_SNAPSHOT_DATE); | |||
@@ -74,7 +74,7 @@ public class PeriodTest { | |||
@Test | |||
public void verify_to_string() { | |||
assertThat(new Period(1, CoreProperties.TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, 10L).toString()) | |||
assertThat(new Period(1, TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, 10L).toString()) | |||
.isEqualTo("Period{index=1, mode=version, modeParameter=2.3, snapshotDate=1420034400000, snapshotId=10}"); | |||
} | |||
} |
@@ -30,7 +30,6 @@ import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.experimental.categories.Category; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.config.Settings; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.api.utils.log.LogTester; | |||
@@ -49,6 +48,11 @@ import org.sonar.test.DbTests; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_DATE; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_DAYS; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_PREVIOUS_VERSION; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_VERSION; | |||
@Category(DbTests.class) | |||
@RunWith(DataProviderRunner.class) | |||
@@ -126,7 +130,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
assertThat(periods).hasSize(1); | |||
Period period = periods.get(0); | |||
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE); | |||
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_DATE); | |||
assertThat(period.getModeParameter()).isEqualTo(textDate); | |||
assertThat(period.getSnapshotDate()).isEqualTo(1227358680000L); | |||
assertThat(period.getSnapshotId()).isEqualTo(1003L); | |||
@@ -187,7 +191,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
Period period = periods.get(0); | |||
// Return analysis from given date 2008-11-22 | |||
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE); | |||
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_DATE); | |||
assertThat(period.getModeParameter()).isEqualTo(textDate); | |||
assertThat(period.getSnapshotDate()).isEqualTo(1227358680000L); | |||
assertThat(period.getSnapshotId()).isEqualTo(1003L); | |||
@@ -212,7 +216,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
// Analysis form 2008-11-29 | |||
Period period = periods.get(0); | |||
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE); | |||
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_DATE); | |||
assertThat(period.getModeParameter()).isEqualTo(date); | |||
assertThat(period.getSnapshotDate()).isEqualTo(1227934800000L); | |||
assertThat(period.getSnapshotId()).isEqualTo(1004L); | |||
@@ -247,7 +251,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
// return analysis from 2008-11-20 | |||
Period period = periods.get(0); | |||
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DAYS); | |||
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_DAYS); | |||
assertThat(period.getModeParameter()).isEqualTo("10"); | |||
assertThat(period.getSnapshotDate()).isEqualTo(1227157200000L); | |||
assertThat(period.getSnapshotId()).isEqualTo(1002L); | |||
@@ -284,7 +288,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
// return analysis from 2008-11-29 | |||
Period period = periods.get(0); | |||
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); | |||
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); | |||
assertThat(period.getModeParameter()).isNotNull(); | |||
assertThat(period.getSnapshotDate()).isEqualTo(1227934800000L); | |||
assertThat(period.getSnapshotId()).isEqualTo(1004L); | |||
@@ -320,7 +324,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
// Analysis form 2008-11-12 | |||
Period period = periods.get(0); | |||
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); | |||
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_VERSION); | |||
assertThat(period.getModeParameter()).isEqualTo("1.0"); | |||
assertThat(period.getSnapshotDate()).isEqualTo(1226494680000L); | |||
assertThat(period.getSnapshotId()).isEqualTo(1001L); | |||
@@ -356,7 +360,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
// Analysis form 2008-11-11 | |||
Period period = periods.get(0); | |||
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); | |||
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_VERSION); | |||
assertThat(period.getModeParameter()).isEqualTo("0.9"); | |||
assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L); | |||
assertThat(period.getSnapshotId()).isEqualTo(1000L); | |||
@@ -388,7 +392,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
assertThat(periods).hasSize(1); | |||
Period period = periods.get(0); | |||
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); | |||
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_VERSION); | |||
assertThat(period.getModeParameter()).isNull(); | |||
assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L); | |||
assertThat(period.getSnapshotId()).isEqualTo(1000L); | |||
@@ -407,7 +411,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
assertThat(periods).hasSize(1); | |||
Period period = periods.get(0); | |||
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); | |||
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_VERSION); | |||
assertThat(period.getModeParameter()).isNull(); | |||
assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L); | |||
assertThat(period.getSnapshotId()).isEqualTo(1000L); | |||
@@ -440,7 +444,7 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
// Analysis form 2008-11-11 | |||
Period period = periods.get(0); | |||
assertThat(period.getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION); | |||
assertThat(period.getMode()).isEqualTo(TIMEMACHINE_MODE_VERSION); | |||
assertThat(period.getModeParameter()).isEqualTo("0.9"); | |||
assertThat(period.getSnapshotDate()).isEqualTo(1226379600000L); | |||
assertThat(period.getSnapshotId()).isEqualTo(1000L); | |||
@@ -477,27 +481,27 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
underTest.execute(); | |||
List<Period> periods = periodsHolder.getPeriods(); | |||
assertThat(periods).extracting("mode").containsExactly(CoreProperties.TIMEMACHINE_MODE_DATE, CoreProperties.TIMEMACHINE_MODE_DAYS, | |||
CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION, | |||
CoreProperties.TIMEMACHINE_MODE_VERSION); | |||
assertThat(periods).extracting("mode").containsExactly(TIMEMACHINE_MODE_DATE, TIMEMACHINE_MODE_DAYS, | |||
TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, TIMEMACHINE_MODE_PREVIOUS_VERSION, | |||
TIMEMACHINE_MODE_VERSION); | |||
assertThat(periods.get(0).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE); | |||
assertThat(periods.get(0).getMode()).isEqualTo(TIMEMACHINE_MODE_DATE); | |||
assertThat(periods.get(0).getIndex()).isEqualTo(1); | |||
assertThat(periods.get(0).getSnapshotDate()).isEqualTo(1227358680000L); | |||
assertThat(periods.get(1).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DAYS); | |||
assertThat(periods.get(1).getMode()).isEqualTo(TIMEMACHINE_MODE_DAYS); | |||
assertThat(periods.get(1).getIndex()).isEqualTo(2); | |||
assertThat(periods.get(1).getSnapshotDate()).isEqualTo(1227157200000L); | |||
assertThat(periods.get(2).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); | |||
assertThat(periods.get(2).getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); | |||
assertThat(periods.get(2).getIndex()).isEqualTo(3); | |||
assertThat(periods.get(2).getSnapshotDate()).isEqualTo(1227934800000L); | |||
assertThat(periods.get(3).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); | |||
assertThat(periods.get(3).getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_VERSION); | |||
assertThat(periods.get(3).getIndex()).isEqualTo(4); | |||
assertThat(periods.get(3).getSnapshotDate()).isEqualTo(1226494680000L); | |||
assertThat(periods.get(4).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION); | |||
assertThat(periods.get(4).getMode()).isEqualTo(TIMEMACHINE_MODE_VERSION); | |||
assertThat(periods.get(4).getIndex()).isEqualTo(5); | |||
assertThat(periods.get(4).getSnapshotDate()).isEqualTo(1226379600000L); | |||
} | |||
@@ -518,22 +522,22 @@ public class LoadPeriodsStepTest extends BaseStepTest { | |||
List<Period> periods = periodsHolder.getPeriods(); | |||
assertThat(periods).extracting("mode").containsExactly( | |||
CoreProperties.TIMEMACHINE_MODE_DATE, CoreProperties.TIMEMACHINE_MODE_DAYS, | |||
CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, CoreProperties.TIMEMACHINE_MODE_VERSION); | |||
TIMEMACHINE_MODE_DATE, TIMEMACHINE_MODE_DAYS, | |||
TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, TIMEMACHINE_MODE_VERSION); | |||
assertThat(periods.get(0).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE); | |||
assertThat(periods.get(0).getMode()).isEqualTo(TIMEMACHINE_MODE_DATE); | |||
assertThat(periods.get(0).getIndex()).isEqualTo(1); | |||
assertThat(periods.get(0).getSnapshotDate()).isEqualTo(1227358680000L); | |||
assertThat(periods.get(1).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DAYS); | |||
assertThat(periods.get(1).getMode()).isEqualTo(TIMEMACHINE_MODE_DAYS); | |||
assertThat(periods.get(1).getIndex()).isEqualTo(2); | |||
assertThat(periods.get(1).getSnapshotDate()).isEqualTo(1227157200000L); | |||
assertThat(periods.get(2).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); | |||
assertThat(periods.get(2).getMode()).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); | |||
assertThat(periods.get(2).getIndex()).isEqualTo(3); | |||
assertThat(periods.get(2).getSnapshotDate()).isEqualTo(1227934800000L); | |||
assertThat(periods.get(3).getMode()).isEqualTo(CoreProperties.TIMEMACHINE_MODE_VERSION); | |||
assertThat(periods.get(3).getMode()).isEqualTo(TIMEMACHINE_MODE_VERSION); | |||
assertThat(periods.get(3).getIndex()).isEqualTo(5); | |||
assertThat(periods.get(3).getSnapshotDate()).isEqualTo(1226379600000L); | |||
} |
@@ -26,22 +26,21 @@ import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.experimental.categories.Category; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.utils.DateUtils; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.component.SnapshotQuery; | |||
import org.sonar.db.component.ComponentTesting; | |||
import org.sonar.db.component.SnapshotTesting; | |||
import org.sonar.server.computation.analysis.MutableAnalysisMetadataHolderRule; | |||
import org.sonar.server.computation.batch.TreeRootHolderRule; | |||
import org.sonar.server.computation.component.Component; | |||
import org.sonar.server.computation.component.DbIdsRepositoryImpl; | |||
import org.sonar.server.computation.component.ReportComponent; | |||
import org.sonar.server.computation.component.FileAttributes; | |||
import org.sonar.server.computation.component.ReportComponent; | |||
import org.sonar.server.computation.period.Period; | |||
import org.sonar.server.computation.period.PeriodsHolderRule; | |||
import org.sonar.test.DbTests; | |||
@@ -49,6 +48,8 @@ import org.sonar.test.DbTests; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_DATE; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS; | |||
@Category(DbTests.class) | |||
public class ReportPersistSnapshotsStepTest extends BaseStepTest { | |||
@@ -285,7 +286,7 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { | |||
SnapshotDto snapshotDto = SnapshotTesting.newSnapshotForProject(projectDto).setCreatedAt(DateUtils.parseDateQuietly("2015-01-01").getTime()); | |||
dbClient.snapshotDao().insert(dbTester.getSession(), snapshotDto); | |||
dbTester.getSession().commit(); | |||
periodsHolder.setPeriods(new Period(1, CoreProperties.TIMEMACHINE_MODE_DATE, "2015-01-01", analysisDate, 123L)); | |||
periodsHolder.setPeriods(new Period(1, TIMEMACHINE_MODE_DATE, "2015-01-01", analysisDate, 123L)); | |||
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build(); | |||
treeRootHolder.setRoot(project); | |||
@@ -294,14 +295,14 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { | |||
underTest.execute(); | |||
SnapshotDto projectSnapshot = getUnprocessedSnapshot(projectDto.getId()); | |||
assertThat(projectSnapshot.getPeriodMode(1)).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE); | |||
assertThat(projectSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_DATE); | |||
assertThat(projectSnapshot.getPeriodDate(1)).isEqualTo(analysisDate); | |||
assertThat(projectSnapshot.getPeriodModeParameter(1)).isNotNull(); | |||
} | |||
@Test | |||
public void only_persist_snapshots_with_periods_on_project_and_module() { | |||
periodsHolder.setPeriods(new Period(1, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, null, analysisDate, 123L)); | |||
periodsHolder.setPeriods(new Period(1, TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, null, analysisDate, 123L)); | |||
ComponentDto projectDto = ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY).setName("Project"); | |||
dbClient.componentDao().insert(dbTester.getSession(), projectDto); | |||
@@ -339,10 +340,10 @@ public class ReportPersistSnapshotsStepTest extends BaseStepTest { | |||
underTest.execute(); | |||
SnapshotDto newProjectSnapshot = getUnprocessedSnapshot(projectDto.getId()); | |||
assertThat(newProjectSnapshot.getPeriodMode(1)).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); | |||
assertThat(newProjectSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); | |||
SnapshotDto newModuleSnapshot = getUnprocessedSnapshot(moduleDto.getId()); | |||
assertThat(newModuleSnapshot.getPeriodMode(1)).isEqualTo(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); | |||
assertThat(newModuleSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); | |||
SnapshotDto newDirectorySnapshot = getUnprocessedSnapshot(directoryDto.getId()); | |||
assertThat(newDirectorySnapshot.getPeriodMode(1)).isNull(); |
@@ -26,7 +26,6 @@ import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.experimental.categories.Category; | |||
import org.sonar.api.CoreProperties; | |||
import org.sonar.api.utils.DateUtils; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.db.DbClient; | |||
@@ -47,6 +46,7 @@ import static java.lang.String.valueOf; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_DATE; | |||
import static org.sonar.db.component.ComponentTesting.newProjectCopy; | |||
import static org.sonar.db.component.ComponentTesting.newProjectDto; | |||
import static org.sonar.db.component.ComponentTesting.newSubView; | |||
@@ -192,17 +192,17 @@ public class ViewsPersistSnapshotsStepTest extends BaseStepTest { | |||
dbIdsRepository.setComponentId(view, viewDto.getId()); | |||
dbIdsRepository.setComponentId(subView, subViewDto.getId()); | |||
periodsHolder.setPeriods(new Period(1, CoreProperties.TIMEMACHINE_MODE_DATE, "2015-01-01", analysisDate, 123L)); | |||
periodsHolder.setPeriods(new Period(1, TIMEMACHINE_MODE_DATE, "2015-01-01", analysisDate, 123L)); | |||
underTest.execute(); | |||
SnapshotDto viewSnapshot = getUnprocessedSnapshot(viewDto.getId()); | |||
assertThat(viewSnapshot.getPeriodMode(1)).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE); | |||
assertThat(viewSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_DATE); | |||
assertThat(viewSnapshot.getPeriodDate(1)).isEqualTo(analysisDate); | |||
assertThat(viewSnapshot.getPeriodModeParameter(1)).isNotNull(); | |||
SnapshotDto subViewSnapshot = getUnprocessedSnapshot(subViewDto.getId()); | |||
assertThat(subViewSnapshot.getPeriodMode(1)).isEqualTo(CoreProperties.TIMEMACHINE_MODE_DATE); | |||
assertThat(subViewSnapshot.getPeriodMode(1)).isEqualTo(TIMEMACHINE_MODE_DATE); | |||
assertThat(subViewSnapshot.getPeriodDate(1)).isEqualTo(analysisDate); | |||
assertThat(subViewSnapshot.getPeriodModeParameter(1)).isNotNull(); | |||
} |
@@ -30,6 +30,20 @@ import org.sonar.api.resources.Qualifiers; | |||
public class CorePropertyDefinitions { | |||
/* Time machine periods */ | |||
public static final String TIMEMACHINE_PERIOD_PREFIX = "sonar.timemachine.period"; | |||
public static final String TIMEMACHINE_MODE_PREVIOUS_ANALYSIS = "previous_analysis"; | |||
public static final String TIMEMACHINE_MODE_DATE = "date"; | |||
public static final String TIMEMACHINE_MODE_VERSION = "version"; | |||
public static final String TIMEMACHINE_MODE_DAYS = "days"; | |||
public static final String TIMEMACHINE_MODE_PREVIOUS_VERSION = "previous_version"; | |||
private static final String TIMEMACHINE_DEFAULT_PERIOD_1 = TIMEMACHINE_MODE_PREVIOUS_VERSION; | |||
private static final String TIMEMACHINE_DEFAULT_PERIOD_2 = TIMEMACHINE_MODE_PREVIOUS_ANALYSIS; | |||
private static final String TIMEMACHINE_DEFAULT_PERIOD_3 = "30"; | |||
private static final String TIMEMACHINE_DEFAULT_PERIOD_4 = ""; | |||
private static final String TIMEMACHINE_DEFAULT_PERIOD_5 = ""; | |||
private CorePropertyDefinitions() { | |||
// only static stuff | |||
} | |||
@@ -211,8 +225,8 @@ public class CorePropertyDefinitions { | |||
.hidden() | |||
.build(), | |||
PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 1) | |||
.name("Period 1") | |||
PropertyDefinition.builder(TIMEMACHINE_PERIOD_PREFIX + 1) | |||
.name("Leak Period") | |||
.description("Period used to compare measures and track new issues. Values are : <ul class='bullet'><li>Number of days before " + | |||
"analysis, for example 5.</li><li>A custom date. Format is yyyy-MM-dd, for example 2010-12-25</li><li>'previous_analysis' to " + | |||
"compare to previous analysis</li><li>'previous_version' to compare to the previous version in the project history</li>" + | |||
@@ -220,28 +234,28 @@ public class CorePropertyDefinitions { | |||
"<p>When specifying a number of days or a date, the snapshot selected for comparison is " + | |||
" the first one available inside the corresponding time range. </p>" + | |||
"<p>Changing this property only takes effect after subsequent project inspections.<p/>") | |||
.defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_1) | |||
.defaultValue(TIMEMACHINE_DEFAULT_PERIOD_1) | |||
.category(CoreProperties.CATEGORY_GENERAL) | |||
.subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) | |||
.build(), | |||
PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 2) | |||
PropertyDefinition.builder(TIMEMACHINE_PERIOD_PREFIX + 2) | |||
.name("Period 2") | |||
.description("See the property 'Period 1'") | |||
.defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_2) | |||
.description("See the property 'Leak Period'") | |||
.defaultValue(TIMEMACHINE_DEFAULT_PERIOD_2) | |||
.category(CoreProperties.CATEGORY_GENERAL) | |||
.subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) | |||
.build(), | |||
PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 3) | |||
PropertyDefinition.builder(TIMEMACHINE_PERIOD_PREFIX + 3) | |||
.name("Period 3") | |||
.description("See the property 'Period 1'") | |||
.defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_3) | |||
.description("See the property 'Leak Period'") | |||
.defaultValue(TIMEMACHINE_DEFAULT_PERIOD_3) | |||
.category(CoreProperties.CATEGORY_GENERAL) | |||
.subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) | |||
.build(), | |||
PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 4) | |||
PropertyDefinition.builder(TIMEMACHINE_PERIOD_PREFIX + 4) | |||
.name("Period 4") | |||
.description("Period used to compare measures and track new issues. This property is specific to the project. Values are : " + | |||
"<ul class='bullet'><li>Number of days before analysis, for example 5.</li><li>A custom date. Format is yyyy-MM-dd, " + | |||
@@ -249,16 +263,16 @@ public class CorePropertyDefinitions { | |||
"<li>'previous_version' to compare to the previous version in the project history</li><li>A version, for example '1.2' or 'BASELINE'</li></ul>" + | |||
"<p>When specifying a number of days or a date, the snapshot selected for comparison is the first one available inside the corresponding time range. </p>" + | |||
"<p>Changing this property only takes effect after subsequent project inspections.<p/>") | |||
.defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_4) | |||
.defaultValue(TIMEMACHINE_DEFAULT_PERIOD_4) | |||
.onlyOnQualifiers(Qualifiers.PROJECT) | |||
.category(CoreProperties.CATEGORY_GENERAL) | |||
.subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) | |||
.build(), | |||
PropertyDefinition.builder(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + 5) | |||
PropertyDefinition.builder(TIMEMACHINE_PERIOD_PREFIX + 5) | |||
.name("Period 5") | |||
.description("See the property 'Period 4'") | |||
.defaultValue(CoreProperties.TIMEMACHINE_DEFAULT_PERIOD_5) | |||
.defaultValue(TIMEMACHINE_DEFAULT_PERIOD_5) | |||
.onlyOnQualifiers(Qualifiers.PROJECT) | |||
.category(CoreProperties.CATEGORY_GENERAL) | |||
.subCategory(CoreProperties.SUBCATEGORY_DIFFERENTIAL_VIEWS) |
@@ -30,12 +30,12 @@ import org.sonar.api.i18n.I18n; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static java.util.Locale.ENGLISH; | |||
import static org.apache.commons.lang.StringUtils.isNotBlank; | |||
import static org.sonar.api.CoreProperties.TIMEMACHINE_MODE_DATE; | |||
import static org.sonar.api.CoreProperties.TIMEMACHINE_MODE_DAYS; | |||
import static org.sonar.api.CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS; | |||
import static org.sonar.api.CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION; | |||
import static org.sonar.api.CoreProperties.TIMEMACHINE_MODE_VERSION; | |||
import static org.sonar.api.CoreProperties.TIMEMACHINE_PERIOD_PREFIX; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_DATE; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_DAYS; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_PREVIOUS_VERSION; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_VERSION; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_PERIOD_PREFIX; | |||
public class Periods { | |||
@@ -34,13 +34,13 @@ import static org.mockito.Mockito.eq; | |||
import static org.mockito.Mockito.isNull; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
import static org.sonar.api.CoreProperties.TIMEMACHINE_MODE_DATE; | |||
import static org.sonar.api.CoreProperties.TIMEMACHINE_MODE_DAYS; | |||
import static org.sonar.api.CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS; | |||
import static org.sonar.api.CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION; | |||
import static org.sonar.api.CoreProperties.TIMEMACHINE_MODE_VERSION; | |||
import static org.sonar.api.CoreProperties.TIMEMACHINE_PERIOD_PREFIX; | |||
import static org.sonar.api.utils.DateUtils.parseDate; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_DATE; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_DAYS; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_PREVIOUS_VERSION; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_MODE_VERSION; | |||
import static org.sonar.core.config.CorePropertyDefinitions.TIMEMACHINE_PERIOD_PREFIX; | |||
public class PeriodsTest { | |||
@@ -316,19 +316,6 @@ public interface CoreProperties { | |||
String GOOGLE_ANALYTICS_PLUGIN = "google-analytics"; | |||
String GOOGLE_ANALYTICS_ACCOUNT_PROPERTY = "sonar.google-analytics.account"; | |||
/* Time machine periods */ | |||
String TIMEMACHINE_PERIOD_PREFIX = "sonar.timemachine.period"; | |||
String TIMEMACHINE_MODE_PREVIOUS_ANALYSIS = "previous_analysis"; | |||
String TIMEMACHINE_MODE_DATE = "date"; | |||
String TIMEMACHINE_MODE_VERSION = "version"; | |||
String TIMEMACHINE_MODE_DAYS = "days"; | |||
String TIMEMACHINE_MODE_PREVIOUS_VERSION = "previous_version"; | |||
String TIMEMACHINE_DEFAULT_PERIOD_1 = TIMEMACHINE_MODE_PREVIOUS_ANALYSIS; | |||
String TIMEMACHINE_DEFAULT_PERIOD_2 = "30"; | |||
String TIMEMACHINE_DEFAULT_PERIOD_3 = TIMEMACHINE_MODE_PREVIOUS_VERSION; | |||
String TIMEMACHINE_DEFAULT_PERIOD_4 = ""; | |||
String TIMEMACHINE_DEFAULT_PERIOD_5 = ""; | |||
/** | |||
* @since 2.11 | |||
*/ |