diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2012-12-05 15:23:52 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2012-12-05 15:24:25 +0100 |
commit | 8e264cd428bc6ebcc987340f0521858dd41e1056 (patch) | |
tree | 7599d302bb143ae6baa5f682cf958d10f763d9d4 /plugins | |
parent | 6ff0e33afd08707df5fe9d6717c9db6526ce4b93 (diff) | |
download | sonarqube-8e264cd428bc6ebcc987340f0521858dd41e1056.tar.gz sonarqube-8e264cd428bc6ebcc987340f0521858dd41e1056.zip |
Periods is now used to display label periods for global settings and for snapshot periods
Diffstat (limited to 'plugins')
6 files changed, 16 insertions, 236 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java index 1cbc4f387fc..baedbbfb19c 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/CorePlugin.java @@ -27,6 +27,7 @@ import org.sonar.api.PropertyType; import org.sonar.api.SonarPlugin; import org.sonar.api.checks.NoSonarFilter; import org.sonar.api.resources.Java; +import org.sonar.core.timemachine.Periods; import org.sonar.plugins.core.batch.ExcludedResourceFilter; import org.sonar.plugins.core.batch.IndexProjectPostJob; import org.sonar.plugins.core.batch.MavenInitializer; @@ -76,7 +77,6 @@ import org.sonar.plugins.core.timemachine.NewCoverageFileAnalyzer; import org.sonar.plugins.core.timemachine.NewItCoverageFileAnalyzer; import org.sonar.plugins.core.timemachine.NewOverallCoverageFileAnalyzer; import org.sonar.plugins.core.timemachine.NewViolationsDecorator; -import org.sonar.plugins.core.timemachine.Periods; import org.sonar.plugins.core.timemachine.ReferenceAnalysis; import org.sonar.plugins.core.timemachine.TendencyDecorator; import org.sonar.plugins.core.timemachine.TimeMachineConfigurationPersister; @@ -92,11 +92,11 @@ import org.sonar.plugins.core.widgets.CoverageWidget; import org.sonar.plugins.core.widgets.CustomMeasuresWidget; import org.sonar.plugins.core.widgets.DescriptionWidget; import org.sonar.plugins.core.widgets.EventsWidget; -import org.sonar.plugins.core.widgets.MeasureFilterListWidget; import org.sonar.plugins.core.widgets.HotspotMetricWidget; import org.sonar.plugins.core.widgets.HotspotMostViolatedResourcesWidget; import org.sonar.plugins.core.widgets.HotspotMostViolatedRulesWidget; import org.sonar.plugins.core.widgets.ItCoverageWidget; +import org.sonar.plugins.core.widgets.MeasureFilterListWidget; import org.sonar.plugins.core.widgets.MeasureFilterTreemapWidget; import org.sonar.plugins.core.widgets.RulesWidget; import org.sonar.plugins.core.widgets.SizeWidget; diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java index 17f87796d66..63e0efc328f 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java @@ -26,6 +26,7 @@ import org.sonar.api.batch.DecoratorBarriers; import org.sonar.api.batch.DecoratorContext; import org.sonar.api.batch.DependedUpon; import org.sonar.api.batch.DependsUpon; +import org.sonar.api.database.model.Snapshot; import org.sonar.api.i18n.I18n; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; @@ -35,19 +36,21 @@ import org.sonar.api.profiles.RulesProfile; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.resources.ResourceUtils; -import org.sonar.plugins.core.timemachine.Periods; +import org.sonar.core.timemachine.Periods; import java.util.List; import java.util.Locale; public class CheckAlertThresholds implements Decorator { + private final Snapshot snapshot; private final RulesProfile profile; private final Periods periods; private final I18n i18n; - public CheckAlertThresholds(RulesProfile profile, Periods periods, I18n i18n) { + public CheckAlertThresholds(Snapshot snapshot, RulesProfile profile, Periods periods, I18n i18n) { + this.snapshot = snapshot; this.profile = profile; this.periods = periods; this.i18n = i18n; @@ -147,7 +150,7 @@ public class CheckAlertThresholds implements Decorator { .append(level.equals(Metric.Level.ERROR) ? alert.getValueError() : alert.getValueWarning()); if (alertPeriod != null){ - stringBuilder.append(" ").append(periods.getLabel(alertPeriod)); + stringBuilder.append(" ").append(periods.label(snapshot, alertPeriod)); } return stringBuilder.toString(); diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/Periods.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/Periods.java deleted file mode 100644 index 74d47c624e6..00000000000 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/Periods.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.core.timemachine; - -import org.sonar.api.BatchExtension; -import org.sonar.api.CoreProperties; -import org.sonar.api.database.model.Snapshot; -import org.sonar.api.i18n.I18n; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; - -public class Periods implements BatchExtension { - - private final Snapshot snapshot; - private final I18n i18n; - - public Periods(Snapshot snapshot, I18n i18n) { - this.snapshot = snapshot; - this.i18n = i18n; - } - - public String getLabel(int periodIndex) { - String mode = snapshot.getPeriodMode(periodIndex); - String param = snapshot.getPeriodModeParameter(periodIndex); - Date date = snapshot.getPeriodDate(periodIndex); - - String label = ""; - if (mode.equals(CoreProperties.TIMEMACHINE_MODE_DAYS)) { - label = message("over_x_days", param); - } else if (mode.equals(CoreProperties.TIMEMACHINE_MODE_VERSION)) { - label = message("since_version", param); - if (date != null) { - label = message("since_version_detailed", param, convertDate(date)); - } - } else if (mode.equals(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS)) { - label = message("since_previous_analysis"); - if (date != null) { - label = message("since_previous_analysis_detailed", convertDate(date)); - } - } else if (mode.equals(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION)) { - label = message("since_previous_version"); - if (param != null) { - label = message("since_previous_version_detailed", param); - } - } else if (mode.equals(CoreProperties.TIMEMACHINE_MODE_DATE)) { - label = message("since_x", convertDate(date)); - } else { - throw new IllegalStateException("This mode is not supported : " + mode); - } - return label; - } - - private String message(String key, Object... parameters) { - return i18n.message(getLocale(), key, null, parameters); - } - - private String convertDate(Date date){ - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy MMM dd"); - return dateFormat.format(date); - } - - private Locale getLocale() { - return Locale.ENGLISH; - } - -} diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties index 5ed67de4d59..349b5346f3c 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/l10n/core.properties @@ -174,11 +174,6 @@ created_by=Created by deactivate_all=Deactivate all default_severity=Default severity default_sort_on=Default sort on -delta_since_previous_analysis=Δ since previous analysis -delta_since_previous_version=Δ since previous version -delta_over_x_days=Δ over {0} days -delta_since=Δ since {0} -delta_since_version=Δ since version {0} disable_treemap=Disable treemap enable_treemap=Enable treemap equals=Equals diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java index 0d1d5295b3b..13af0bd4450 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java @@ -25,6 +25,7 @@ import org.junit.Test; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; import org.sonar.api.batch.DecoratorContext; +import org.sonar.api.database.model.Snapshot; import org.sonar.api.i18n.I18n; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; @@ -35,7 +36,7 @@ import org.sonar.api.resources.Project; import org.sonar.api.resources.Qualifiers; import org.sonar.api.resources.Resource; import org.sonar.api.test.IsMeasure; -import org.sonar.plugins.core.timemachine.Periods; +import org.sonar.core.timemachine.Periods; import java.util.ArrayList; import java.util.Arrays; @@ -54,10 +55,13 @@ public class CheckAlertThresholdsTest { private CheckAlertThresholds decorator; private DecoratorContext context; private RulesProfile profile; + private Measure measureClasses; private Measure measureCoverage; private Measure measureComplexity; + private Resource project; + private Snapshot snapshot; private Periods periods; private I18n i18n; @@ -76,8 +80,9 @@ public class CheckAlertThresholdsTest { when(context.getMeasure(CoreMetrics.COVERAGE)).thenReturn(measureCoverage); when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(measureComplexity); + snapshot = mock(Snapshot.class); profile = mock(RulesProfile.class); - decorator = new CheckAlertThresholds(profile, periods, i18n); + decorator = new CheckAlertThresholds(snapshot, profile, periods, i18n); project = mock(Resource.class); when(project.getQualifier()).thenReturn(Qualifiers.PROJECT); } @@ -257,7 +262,7 @@ public class CheckAlertThresholdsTest { measureClasses.setVariation1(40d); when(i18n.message(Mockito.any(Locale.class), Mockito.eq("metric.classes.name"), Mockito.isNull(String.class))).thenReturn("Classes"); - when(periods.getLabel(1)).thenReturn("since someday"); + when(periods.label(snapshot, 1)).thenReturn("since someday"); when(profile.getAlerts()).thenReturn(Arrays.asList( new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "30", 1) // generates warning because classes increases of 40, which is greater than 30 diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PeriodsTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PeriodsTest.java deleted file mode 100644 index b8a3f04905a..00000000000 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/timemachine/PeriodsTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2008-2012 SonarSource - * mailto:contact AT sonarsource DOT com - * - * Sonar 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. - * - * Sonar 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 Sonar; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - */ -package org.sonar.plugins.core.timemachine; - -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.sonar.api.CoreProperties; -import org.sonar.api.database.model.Snapshot; -import org.sonar.api.i18n.I18n; - -import java.util.Date; -import java.util.Locale; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -public class PeriodsTest { - - private Periods periods; - - private Snapshot snapshot; - private I18n i18n; - - private int periodIndex; - private String param; - - @Before - public void before() { - periodIndex = 1; - param = "10"; - - snapshot = mock(Snapshot.class); - i18n = mock(I18n.class); - - when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); - - periods = new Periods(snapshot, i18n); - } - - @Test - public void shouldReturnLabelInModeDays() { - when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_DAYS); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); - when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); - - periods.getLabel(periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("over_x_days"), Mockito.isNull(String.class), Mockito.eq(param)); - } - - @Test - public void shouldReturnLabelInModeVersion() { - when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_VERSION); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); - when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); - - periods.getLabel(periodIndex); - - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_version_detailed"), Mockito.isNull(String.class), Mockito.eq(param), Mockito.anyString()); - } - - @Test - public void shouldReturnLabelInModePreviousAnalysisWithDateNotNull() { - when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_VERSION); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); - when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); - - periods.getLabel(periodIndex); - - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_version_detailed"), Mockito.isNull(String.class), Mockito.eq(param), Mockito.anyString()); - } - - @Test - public void shouldReturnLabelInModePreviousAnalysisWithNullDate() { - when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_VERSION); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(null); - when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); - - periods.getLabel(periodIndex); - - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_version"), Mockito.isNull(String.class), Mockito.eq(param)); - } - - @Test - public void shouldReturnLabelInModePreviousVersionWithParamNotNull() { - when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); - when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); - - periods.getLabel(periodIndex); - - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_version_detailed"), Mockito.isNull(String.class), Mockito.eq(param)); - } - - @Test - public void shouldReturnLabelInModePreviousVersionWithParamNull() { - when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); - when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(null); - - periods.getLabel(periodIndex); - - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_version"), Mockito.isNull(String.class)); - } - - @Test - public void shouldReturnLabelInModeDate() { - when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_DATE); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); - - periods.getLabel(periodIndex); - - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_x"), Mockito.isNull(String.class), Mockito.anyString()); - } - - @Test(expected = IllegalStateException.class) - public void shouldNotSupportUnknownMode() { - when(snapshot.getPeriodMode(periodIndex)).thenReturn("Unknown mode"); - - periods.getLabel(periodIndex); - } -} |