@Immutable
public class Period {
- private final int index;
private final String mode;
@CheckForNull
private final String modeParameter;
private final long snapshotDate;
private final String analysisUuid;
- /**
- * @deprecated replaced by {@link #Period(String, String, long, String)}
- */
- @Deprecated
- public Period(int index, String mode, @Nullable String modeParameter, long snapshotDate, String analysisUuid) {
- if (!isValidPeriodIndex(index)) {
- throw new IllegalArgumentException(String.format("Period index (%s) must be > 0 and < 6", index));
- }
- this.index = index;
- this.mode = requireNonNull(mode);
- this.modeParameter = modeParameter;
- this.snapshotDate = snapshotDate;
- this.analysisUuid = analysisUuid;
- }
-
public Period(String mode, @Nullable String modeParameter, long snapshotDate, String analysisUuid) {
- this.index = 1;
this.mode = requireNonNull(mode);
this.modeParameter = modeParameter;
this.snapshotDate = snapshotDate;
this.analysisUuid = analysisUuid;
}
- public static boolean isValidPeriodIndex(int i) {
- return i > 0 && i < 6;
- }
-
- /**
- * Index of periods is 1-based. It goes from 1 to 5.
- * @deprecated only leak period can now be defined
- */
- @Deprecated
- public int getIndex() {
- return index;
- }
-
public String getMode() {
return mode;
}
return false;
}
Period period = (Period) o;
- return index == period.index
- && snapshotDate == period.snapshotDate
+ return snapshotDate == period.snapshotDate
&& Objects.equals(analysisUuid, period.analysisUuid)
&& mode.equals(period.mode)
&& Objects.equals(modeParameter, period.modeParameter);
@Override
public int hashCode() {
- return hash(index, mode, modeParameter, snapshotDate, analysisUuid);
+ return hash(mode, modeParameter, snapshotDate, analysisUuid);
}
@Override
public String toString() {
return toStringHelper(this)
- .add("index", index)
.add("mode", mode)
.add("modeParameter", modeParameter)
.add("snapshotDate", snapshotDate)
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.period;
-
-import com.google.common.base.Predicate;
-import javax.annotation.Nonnull;
-
-public final class PeriodPredicates {
- private PeriodPredicates() {
- // prevents instantiation
- }
-
- /**
- * Since Periods 4 and 5 can be customized per project and/or per view/subview, aggregating variation on these periods
- * for NEW_* metrics will only generate garbage data which will make no sense. These Periods should be ignored
- * when processing views/subviews.
- */
- public static Predicate<Period> viewsRestrictedPeriods() {
- return ViewsSupportedPeriods.INSTANCE;
- }
-
- private enum ViewsSupportedPeriods implements Predicate<Period> {
- INSTANCE;
-
- @Override
- public boolean apply(@Nonnull Period input) {
- return input.getIndex() < 4;
- }
- }
-}
public class NewEffortAggregatorTest {
- private static final Period PERIOD = new Period(1, TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, null, 1_500_000_000L, "U1");
+ private static final Period PERIOD = new Period(TIMEMACHINE_MODE_PREVIOUS_ANALYSIS, null, 1_500_000_000L, "U1");
private static final Component FILE = ReportComponent.builder(Component.Type.FILE, 1).setUuid("FILE").build();
private static final Component PROJECT = ReportComponent.builder(Component.Type.PROJECT, 2).addChildren(FILE).build();
private static final Duration TEN_DAYS = Duration.create(10 * HOURS_IN_DAY * 60 * 60L);
private static final long PERIOD_DATE = 150000000L;
private static final String ANALYSIS_UUID = "u1";
- private static final Period PERIOD = new Period(1, TIMEMACHINE_MODE_PREVIOUS_VERSION, null, PERIOD_DATE, ANALYSIS_UUID);
+ private static final Period PERIOD = new Period(TIMEMACHINE_MODE_PREVIOUS_VERSION, null, PERIOD_DATE, ANALYSIS_UUID);
DefaultIssue issue = new DefaultIssue();
NewEffortCalculator underTest = new NewEffortCalculator();
+++ /dev/null
-/*
- * SonarQube
- * Copyright (C) 2009-2016 SonarSource SA
- * mailto:contact AT sonarsource DOT com
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.server.computation.task.projectanalysis.period;
-
-import org.junit.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class PeriodPredicatesTest {
-
- @Test(expected = NullPointerException.class)
- public void viewsRestrictedPeriods_throws_NPE_if_Period_is_null() {
- PeriodPredicates.viewsRestrictedPeriods().apply(null);
- }
-
- @Test
- public void viewsRestrictedPeriods() {
- assertThat(PeriodPredicates.viewsRestrictedPeriods().apply(createPeriod(1))).isTrue();
- assertThat(PeriodPredicates.viewsRestrictedPeriods().apply(createPeriod(2))).isTrue();
- assertThat(PeriodPredicates.viewsRestrictedPeriods().apply(createPeriod(3))).isTrue();
- assertThat(PeriodPredicates.viewsRestrictedPeriods().apply(createPeriod(4))).isFalse();
- assertThat(PeriodPredicates.viewsRestrictedPeriods().apply(createPeriod(5))).isFalse();
- }
-
- private Period createPeriod(int index) {
- return new Period(index, "don't care", null, 1l, "U1");
- }
-}
public class PeriodTest {
- private static final String SOME_MODE = "mode";
private static final String SOME_MODE_PARAM = "mode_para";
private static final long SOME_SNAPSHOT_DATE = 1000l;
private static final String SOME_ANALYSIS_UUID = "U1";
@Test
public void test_some_setters_and_getters() {
- Period period = new Period(1, TIMEMACHINE_MODE_VERSION, SOME_MODE_PARAM, SOME_SNAPSHOT_DATE, SOME_ANALYSIS_UUID);
+ Period period = new Period(TIMEMACHINE_MODE_VERSION, SOME_MODE_PARAM, SOME_SNAPSHOT_DATE, SOME_ANALYSIS_UUID);
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);
assertThat(period.getAnalysisUuid()).isEqualTo(SOME_ANALYSIS_UUID);
}
- @Test
- public void constructor_throws_IAE_if_index_is_0() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Period index (0) must be > 0 and < 6");
-
- new Period(0, SOME_MODE, SOME_MODE_PARAM, SOME_SNAPSHOT_DATE, SOME_ANALYSIS_UUID);
- }
-
- @Test
- public void constructor_throws_IAE_if_index_is_6() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Period index (6) must be > 0 and < 6");
-
- new Period(6, SOME_MODE, SOME_MODE_PARAM, SOME_SNAPSHOT_DATE, SOME_ANALYSIS_UUID);
- }
-
- @Test
- public void constructor_throws_IAE_if_index_is_less_then_1() {
- expectedException.expect(IllegalArgumentException.class);
- expectedException.expectMessage("Period index (-156) must be > 0 and < 6");
-
- new Period(-156, SOME_MODE, SOME_MODE_PARAM, SOME_SNAPSHOT_DATE, SOME_ANALYSIS_UUID);
- }
-
@Test
public void verify_to_string() {
- assertThat(new Period(1, TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, "U10").toString())
- .isEqualTo("Period{index=1, mode=version, modeParameter=2.3, snapshotDate=1420034400000, analysisUuid=U10}");
+ assertThat(new Period(TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, "U10").toString())
+ .isEqualTo("Period{mode=version, modeParameter=2.3, snapshotDate=1420034400000, analysisUuid=U10}");
}
@Test
public void equals_is_done_on_all_fields() {
- Period period = new Period(1, TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, "U10");
+ Period period = new Period(TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, "U10");
- assertThat(period).isEqualTo(new Period(1, TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, "U10"));
+ assertThat(period).isEqualTo(new Period(TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, "U10"));
assertThat(period).isNotEqualTo(null);
assertThat(period).isNotEqualTo("sdsd");
- assertThat(period).isNotEqualTo(new Period(2, TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, "U10"));
- assertThat(period).isNotEqualTo(new Period(1, TIMEMACHINE_MODE_DAYS, "2.3", 1420034400000L, "U10"));
- assertThat(period).isNotEqualTo(new Period(1, TIMEMACHINE_MODE_VERSION, "2.4", 1420034400000L, "U10"));
- assertThat(period).isNotEqualTo(new Period(1, TIMEMACHINE_MODE_VERSION, "2.3", 555L, "U10"));
- assertThat(period).isNotEqualTo(new Period(1, TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, "9632554"));
+ assertThat(period).isNotEqualTo(new Period(TIMEMACHINE_MODE_DAYS, "2.3", 1420034400000L, "U10"));
+ assertThat(period).isNotEqualTo(new Period(TIMEMACHINE_MODE_VERSION, "2.4", 1420034400000L, "U10"));
+ assertThat(period).isNotEqualTo(new Period(TIMEMACHINE_MODE_VERSION, "2.3", 555L, "U10"));
+ assertThat(period).isNotEqualTo(new Period(TIMEMACHINE_MODE_VERSION, "2.3", 1420034400000L, "9632554"));
}
}
}
private static Period createPeriod() {
- return new Period(1, 1 + "mode", null, 1000L, "U1");
+ return new Period(1 + "mode", null, 1000L, "U1");
}
}
.thenReturn(metricMsg);
Date date = new Date();
- Period period = new Period(periodIndex, SOME_MODE, null, date.getTime(), SOME_ANALYSIS_UUID);
+ Period period = new Period(SOME_MODE, null, date.getTime(), SOME_ANALYSIS_UUID);
periodsHolder.setPeriod(period);
when(periods.label(period.getMode(), period.getModeParameter(), date)).thenReturn(periodLabel);
when(i18n.message(Locale.ENGLISH, "variation", "variation")).thenReturn(variationMsg);
Date date = new Date();
- Period period = new Period(periodIndex, SOME_MODE, null, date.getTime(), SOME_ANALYSIS_UUID);
+ Period period = new Period(SOME_MODE, null, date.getTime(), SOME_ANALYSIS_UUID);
periodsHolder.setPeriod(period);
when(periods.label(period.getMode(), period.getModeParameter(), date)).thenReturn(periodLabel);
import org.sonar.server.computation.task.projectanalysis.measure.MeasureRepositoryRule;
import org.sonar.server.computation.task.projectanalysis.measure.MeasureToMeasureDto;
import org.sonar.server.computation.task.projectanalysis.metric.MetricRepositoryRule;
-import org.sonar.server.computation.task.projectanalysis.period.Period;
import org.sonar.server.computation.task.step.ComputationStep;
import static org.assertj.core.api.Assertions.assertThat;
return componentDto;
}
- private static Period createPeriod() {
- return new Period(1, "mode" + 1, null, 1, "1");
- }
-
private List<Map<String, Object>> selectSnapshots() {
return dbTester
.select(
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d));
session.commit();
- periodsHolder.setPeriod(newPeriod(1, period1ProjectSnapshot));
+ periodsHolder.setPeriod(newPeriod(period1ProjectSnapshot));
treeRootHolder.setRoot(PROJECT);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), directoryDto.uuid(), period1Snapshot.getUuid(), 10d));
session.commit();
- periodsHolder.setPeriod(newPeriod(1, period1Snapshot));
+ periodsHolder.setPeriod(newPeriod(period1Snapshot));
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid(directoryDto.uuid()).build();
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).addChildren(directory).build();
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), directoryDto.uuid(), period1Snapshot.getUuid(), 10d));
session.commit();
- periodsHolder.setPeriod(newPeriod(1, period1Snapshot));
+ periodsHolder.setPeriod(newPeriod(period1Snapshot));
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid(directoryDto.uuid()).build();
Component project = ReportComponent.builder(Component.Type.PROJECT, 1).setUuid(PROJECT_UUID).addChildren(directory).build();
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, currentProjectSnapshot.getUuid(), 60d));
session.commit();
- periodsHolder.setPeriod(newPeriod(1, past1ProjectSnapshot));
+ periodsHolder.setPeriod(newPeriod(past1ProjectSnapshot));
// Directory has just been added => no snapshot
Component directory = ReportComponent.builder(Component.Type.DIRECTORY, 2).setUuid("DIRECTORY").build();
newMeasureDto(BUILD_BREAKER_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 1d));
session.commit();
- periodsHolder.setPeriod(newPeriod(1, period1ProjectSnapshot));
+ periodsHolder.setPeriod(newPeriod(period1ProjectSnapshot));
treeRootHolder.setRoot(PROJECT);
newMeasureDto(ISSUES_METRIC.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d));
session.commit();
- periodsHolder.setPeriod(newPeriod(1, period1ProjectSnapshot));
+ periodsHolder.setPeriod(newPeriod(period1ProjectSnapshot));
treeRootHolder.setRoot(PROJECT);
dbClient.snapshotDao().insert(session, period1ProjectSnapshot);
dbClient.measureDao().insert(session, newMeasureDto(NEW_DEBT.getId(), PROJECT_UUID, period1ProjectSnapshot.getUuid(), 60d));
session.commit();
- periodsHolder.setPeriod(newPeriod(1, period1ProjectSnapshot));
+ periodsHolder.setPeriod(newPeriod(period1ProjectSnapshot));
treeRootHolder.setRoot(PROJECT);
addRawMeasure(PROJECT, NEW_DEBT, newMeasureBuilder().setVariation(10d).createNoValue());
.setValue(value);
}
- private static Period newPeriod(int index, SnapshotDto snapshotDto) {
- return new Period(index, "mode", null, snapshotDto.getCreatedAt(), snapshotDto.getUuid());
+ private static Period newPeriod(SnapshotDto snapshotDto) {
+ return new Period("mode", null, snapshotDto.getCreatedAt(), snapshotDto.getUuid());
}
private void addRawMeasure(Component component, Metric metric, Measure measure) {
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 60d));
session.commit();
- periodsHolder.setPeriod(newPeriod(1, period1ViewSnapshot));
+ periodsHolder.setPeriod(newPeriod(period1ViewSnapshot));
treeRootHolder.setRoot(VIEW);
dbClient.measureDao().insert(session, newMeasureDto(ISSUES_METRIC.getId(), subviewDto.uuid(), period1Snapshot.getUuid(), 10d));
session.commit();
- periodsHolder.setPeriod(newPeriod(1, period1Snapshot));
+ periodsHolder.setPeriod(newPeriod(period1Snapshot));
Component subview = ViewsComponent.builder(Component.Type.SUBVIEW, 2).setUuid(subviewDto.uuid()).build();
Component view = ViewsComponent.builder(Component.Type.VIEW, 1).setUuid(VIEW_UUID).addChildren(subview).build();
newMeasureDto(BUILD_BREAKER_METRIC.getId(), VIEW_UUID, period1ViewSnapshot.getUuid(), 1d));
session.commit();
- periodsHolder.setPeriod(newPeriod(1, period1ViewSnapshot));
+ periodsHolder.setPeriod(newPeriod(period1ViewSnapshot));
treeRootHolder.setRoot(VIEW);
.setValue(value);
}
- private static Period newPeriod(int index, SnapshotDto snapshotDto) {
- return new Period(index, "mode", null, snapshotDto.getCreatedAt(), snapshotDto.getUuid());
+ private static Period newPeriod(SnapshotDto snapshotDto) {
+ return new Period("mode", null, snapshotDto.getCreatedAt(), snapshotDto.getUuid());
}
private void addRawMeasure(Component component, Metric metric, Measure measure) {