From 9126c6532f44340999e5c018063510c79378cf08 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Mon, 3 Feb 2014 16:31:20 +0100 Subject: [PATCH] SONAR-4767 Display date of snapshot used for comparison when selecting "Delta over X days" --- .../TimeMachineConfigurationPersister.java | 2 +- .../resources/org/sonar/l10n/core.properties | 4 +- .../shared.xml | 34 +++++++++-- ...veConfigurationInSnapshotsTable-result.xml | 34 +++++++++-- .../sonar/batch/components/PastSnapshot.java | 2 +- .../batch/components/PastSnapshotTest.java | 2 +- .../org/sonar/core/timemachine/Periods.java | 8 ++- .../sonar/core/timemachine/PeriodsTest.java | 58 +++++++++++-------- .../WEB-INF/app/helpers/dashboard_helper.rb | 4 +- .../app/views/dashboard/_header.html.erb | 2 +- .../app/views/drilldown/issues.html.erb | 2 +- 11 files changed, 110 insertions(+), 42 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java index 06cfab1131a..3d848fe849f 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersister.java @@ -71,6 +71,6 @@ public final class TimeMachineConfigurationPersister implements Decorator { int periodIndex = pastSnapshot.getIndex(); snapshot.setPeriodMode(periodIndex, pastSnapshot.getMode()); snapshot.setPeriodModeParameter(periodIndex, pastSnapshot.getModeParameter()); - snapshot.setPeriodDate(periodIndex, pastSnapshot.getTargetDate()); + snapshot.setPeriodDate(periodIndex, pastSnapshot.getDate()); } } 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 284b3618443..699a4c6bf0d 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 @@ -216,7 +216,7 @@ new_window=New window no_data=No data no_lines_match_your_filter_criteria=No lines match your filter criteria. no_results=No results -over_x_days=over {0} days +over_x_days=over {0} days ({1}) over_x_days.short={0} days page_size=Page size paging_first=First @@ -243,7 +243,7 @@ since_version_detailed=since version {0} ({1}) since_version_detailed.short={0} ({1}) since_previous_version=since previous version since_previous_version.short=\u0394 version -since_previous_version_detailed=since previous version ({0}) +since_previous_version_detailed=since previous version ({0} - {1}) since_previous_version_detailed.short=\u0394 version ({0}) time_changes=Time changes diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shared.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shared.xml index bf1990b4615..a4286611e65 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shared.xml +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shared.xml @@ -1,16 +1,42 @@ - - - + + + - \ No newline at end of file + diff --git a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shouldSaveConfigurationInSnapshotsTable-result.xml b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shouldSaveConfigurationInSnapshotsTable-result.xml index 784bfad7eee..63545d72ec0 100644 --- a/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shouldSaveConfigurationInSnapshotsTable-result.xml +++ b/plugins/sonar-core-plugin/src/test/resources/org/sonar/plugins/core/timemachine/TimeMachineConfigurationPersisterTest/shouldSaveConfigurationInSnapshotsTable-result.xml @@ -1,16 +1,42 @@ - - - + + + - \ No newline at end of file + diff --git a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java index eb70abbbc0e..51bd4d2f50f 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java +++ b/sonar-batch/src/main/java/org/sonar/batch/components/PastSnapshot.java @@ -112,7 +112,7 @@ public class PastSnapshot { if (StringUtils.equals(mode, CoreProperties.TIMEMACHINE_MODE_VERSION)) { String label = String.format("Compare to version %s", modeParameter); if (getTargetDate() != null) { - label += String.format(" (%s)", DateUtils.formatDate(getTargetDate())); + label += String.format(" (%s)", DateUtils.formatDate(getDate())); } return label; } diff --git a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java index 8591a47ab8d..1972cdc0188 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/components/PastSnapshotTest.java @@ -57,7 +57,7 @@ public class PastSnapshotTest { @Test public void testToStringForVersion() { - PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date()).setModeParameter("2.3"); + PastSnapshot pastSnapshot = new PastSnapshot(CoreProperties.TIMEMACHINE_MODE_VERSION, new Date(), new Snapshot().setCreatedAt(new Date())).setModeParameter("2.3"); assertThat(pastSnapshot.toString()).startsWith("Compare to version 2.3"); } diff --git a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java index a41d3c55797..f4f8be6d18a 100644 --- a/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java +++ b/sonar-core/src/main/java/org/sonar/core/timemachine/Periods.java @@ -22,6 +22,7 @@ package org.sonar.core.timemachine; import org.apache.commons.lang.StringUtils; import org.sonar.api.BatchExtension; import org.sonar.api.CoreProperties; +import org.sonar.api.ServerComponent; import org.sonar.api.config.Settings; import org.sonar.api.database.model.Snapshot; import org.sonar.api.i18n.I18n; @@ -31,7 +32,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; -public class Periods implements BatchExtension { +public class Periods implements BatchExtension, ServerComponent { private final Settings settings; private final I18n i18n; @@ -76,7 +77,7 @@ public class Periods implements BatchExtension { private String label(String mode, String param, String date, boolean shortLabel) { String label; if (CoreProperties.TIMEMACHINE_MODE_DAYS.equals(mode)) { - label = label("over_x_days", shortLabel, param); + label = label("over_x_days", shortLabel, param, date); } else if (CoreProperties.TIMEMACHINE_MODE_VERSION.equals(mode)) { label = label("since_version", shortLabel, param); if (date != null) { @@ -91,6 +92,9 @@ public class Periods implements BatchExtension { label = label("since_previous_version", shortLabel); if (param != null) { label = label("since_previous_version_detailed", shortLabel, param); + if (date != null) { + label = label("since_previous_version_detailed", shortLabel, param, date); + } } } else if (CoreProperties.TIMEMACHINE_MODE_DATE.equals(mode)) { label = label("since_x", shortLabel, date); diff --git a/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java b/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java index bcc23aa83ae..b70b56f2719 100644 --- a/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/timemachine/PeriodsTest.java @@ -21,7 +21,6 @@ package org.sonar.core.timemachine; import org.junit.Before; import org.junit.Test; -import org.mockito.Mockito; import org.sonar.api.CoreProperties; import org.sonar.api.config.Settings; import org.sonar.api.database.model.Snapshot; @@ -30,9 +29,11 @@ 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; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Matchers.isNull; +import static org.mockito.Mockito.*; public class PeriodsTest { @@ -61,12 +62,13 @@ public class PeriodsTest { @Test public void label_of_duration_in_days() { + Date date = new Date(); when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_DAYS); - when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(date); when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); periods.label(snapshot, periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("over_x_days"), Mockito.isNull(String.class), Mockito.eq(param)); + verify(i18n).message(any(Locale.class), eq("over_x_days"), isNull(String.class), eq(param), anyString()); } @Test @@ -76,7 +78,7 @@ public class PeriodsTest { when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); periods.abbreviation(snapshot, periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("over_x_days.short"), Mockito.isNull(String.class), Mockito.eq(param)); + verify(i18n).message(any(Locale.class), eq("over_x_days.short"), isNull(String.class), eq(param), anyString()); } @Test @@ -86,7 +88,7 @@ public class PeriodsTest { when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); periods.label(snapshot, periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_version_detailed"), Mockito.isNull(String.class), Mockito.eq(param), Mockito.anyString()); + verify(i18n).message(any(Locale.class), eq("since_version_detailed"), isNull(String.class), eq(param), anyString()); } @Test @@ -96,7 +98,7 @@ public class PeriodsTest { when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); periods.abbreviation(snapshot, periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_version_detailed.short"), Mockito.isNull(String.class), Mockito.eq(param), Mockito.anyString()); + verify(i18n).message(any(Locale.class), eq("since_version_detailed.short"), isNull(String.class), eq(param), anyString()); } @Test @@ -105,7 +107,7 @@ public class PeriodsTest { when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); periods.label(snapshot, periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_analysis_detailed"), Mockito.isNull(String.class), Mockito.anyString()); + verify(i18n).message(any(Locale.class), eq("since_previous_analysis_detailed"), isNull(String.class), anyString()); } @Test @@ -115,7 +117,7 @@ public class PeriodsTest { when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); periods.label(snapshot, periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_analysis"), Mockito.isNull(String.class)); + verify(i18n).message(any(Locale.class), eq("since_previous_analysis"), isNull(String.class)); } @Test @@ -124,7 +126,7 @@ public class PeriodsTest { when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); periods.abbreviation(snapshot, periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_analysis_detailed.short"), Mockito.isNull(String.class), Mockito.anyString()); + verify(i18n).message(any(Locale.class), eq("since_previous_analysis_detailed.short"), isNull(String.class), anyString()); } @Test @@ -134,7 +136,7 @@ public class PeriodsTest { when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); periods.abbreviation(snapshot, periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_analysis.short"), Mockito.isNull(String.class)); + verify(i18n).message(any(Locale.class), eq("since_previous_analysis.short"), isNull(String.class)); } @Test @@ -143,7 +145,17 @@ public class PeriodsTest { when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); periods.label(snapshot, periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_version_detailed"), Mockito.isNull(String.class), Mockito.eq(param)); + verify(i18n).message(any(Locale.class), eq("since_previous_version_detailed"), isNull(String.class), eq(param)); + } + + @Test + public void label_of_previous_version_with_param_and_date() { + when(snapshot.getPeriodMode(periodIndex)).thenReturn(CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); + when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(param); + when(snapshot.getPeriodDate(periodIndex)).thenReturn(new Date()); + + periods.label(snapshot, periodIndex); + verify(i18n).message(any(Locale.class), eq("since_previous_version_detailed"), isNull(String.class), eq(param), anyString()); } @Test @@ -152,7 +164,7 @@ public class PeriodsTest { when(snapshot.getPeriodModeParameter(periodIndex)).thenReturn(null); periods.label(snapshot, periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_version"), Mockito.isNull(String.class)); + verify(i18n).message(any(Locale.class), eq("since_previous_version"), isNull(String.class)); } @Test @@ -162,7 +174,7 @@ public class PeriodsTest { periods.label(snapshot, periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_x"), Mockito.isNull(String.class), Mockito.anyString()); + verify(i18n).message(any(Locale.class), eq("since_x"), isNull(String.class), anyString()); } @Test(expected = IllegalArgumentException.class) @@ -179,7 +191,7 @@ public class PeriodsTest { settings.setProperty(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + periodIndex, days); periods.label(periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("over_x_days"), Mockito.isNull(String.class), Mockito.eq(days)); + verify(i18n).message(any(Locale.class), eq("over_x_days"), isNull(String.class), eq(days), anyString()); } @Test @@ -189,7 +201,7 @@ public class PeriodsTest { settings.setProperty(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + periodIndex, version); periods.label(periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_version"), Mockito.isNull(String.class), Mockito.eq(version)); + verify(i18n).message(any(Locale.class), eq("since_version"), isNull(String.class), eq(version)); } @Test @@ -198,7 +210,7 @@ public class PeriodsTest { settings.setProperty(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + periodIndex, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_ANALYSIS); periods.label(periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_analysis"), Mockito.isNull(String.class)); + verify(i18n).message(any(Locale.class), eq("since_previous_analysis"), isNull(String.class)); } @Test @@ -207,7 +219,7 @@ public class PeriodsTest { settings.setProperty(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + periodIndex, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); periods.label(periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_version"), Mockito.isNull(String.class)); + verify(i18n).message(any(Locale.class), eq("since_previous_version"), isNull(String.class)); } @Test @@ -216,7 +228,7 @@ public class PeriodsTest { settings.setProperty(CoreProperties.TIMEMACHINE_PERIOD_PREFIX + periodIndex, CoreProperties.TIMEMACHINE_MODE_PREVIOUS_VERSION); periods.abbreviation(periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_previous_version.short"), Mockito.isNull(String.class)); + verify(i18n).message(any(Locale.class), eq("since_previous_version.short"), isNull(String.class)); } @Test @@ -226,7 +238,7 @@ public class PeriodsTest { periods.label(periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_x"), Mockito.isNull(String.class), Mockito.anyString()); + verify(i18n).message(any(Locale.class), eq("since_x"), isNull(String.class), anyString()); } @Test @@ -236,7 +248,7 @@ public class PeriodsTest { periods.abbreviation(periodIndex); - verify(i18n).message(Mockito.any(Locale.class), Mockito.eq("since_x.short"), Mockito.isNull(String.class), Mockito.anyString()); + verify(i18n).message(any(Locale.class), eq("since_x.short"), isNull(String.class), anyString()); } @Test(expected = IllegalArgumentException.class) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb index 63003db912a..69f2810a846 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/dashboard_helper.rb @@ -91,7 +91,7 @@ module DashboardHelper label = message('added_since_version', :params => mode_param.to_s) elsif mode=='previous_analysis' if !date.nil? - label = message('added_since_previous_analysis_detailed', :params => date.strftime("%Y %b. %d").to_s) + label = message('added_since_previous_analysis_detailed', :params => date.strftime('%Y %b. %d').to_s) else label = message('added_since_previous_analysis') end @@ -102,7 +102,7 @@ module DashboardHelper label = message('added_since_previous_version') end elsif mode=='date' - label = message('added_since', :params => date.strftime("%Y %b %d").to_s) + label = message('added_since', :params => date.strftime('%Y %b %d').to_s) end if label selected=(params[:period]==index.to_s ? 'selected' : '') diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb index e8191011ade..727399245eb 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/dashboard/_header.html.erb @@ -22,7 +22,7 @@ <% if period_options %>
- <%= dropdown_tag "period", period_options, {:width => '230px'}, {:id => 'select-comparison', :onchange => 'submit()'} -%> + <%= dropdown_tag 'period', period_options, {:width => '250px'}, {:id => 'select-comparison', :onchange => 'submit()'} -%>
<% end %> <% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/issues.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/issues.html.erb index fdedba0dbc6..91a40199c46 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/issues.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/drilldown/issues.html.erb @@ -12,7 +12,7 @@ <% period_options = period_select_option_tags(@snapshot, 'small') %> <% if period_options %>
- <%= dropdown_tag 'period', period_options, {:width => '230px'}, {:id => 'select-comparison', :onchange => 'submit()'} -%> + <%= dropdown_tag 'period', period_options, {:width => '250px'}, {:id => 'select-comparison', :onchange => 'submit()'} -%>
<% end %> <% end %> -- 2.39.5