From 499ee54abf8c0d673be77d76c119f41e52e4de84 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 24 Jun 2014 10:39:26 +0200 Subject: [PATCH] SONAR-5007 add link to Q profile changelog in the events widget --- .../org/sonar/plugins/core/widgets/events.html.erb | 2 +- .../org/sonar/batch/rule/QProfileEventsDecorator.java | 10 +++++++++- .../sonar/batch/rule/QProfileEventsDecoratorTest.java | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb index e1cf3f78383..1ee56e96fcf 100644 --- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb +++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/events.html.erb @@ -65,7 +65,7 @@ diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java index 3774f9f1b5e..cfbed1da0e6 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/rule/QProfileEventsDecorator.java @@ -20,6 +20,7 @@ package org.sonar.batch.rule; import com.google.common.collect.ImmutableSortedMap; +import org.apache.commons.lang.time.DateUtils; import org.sonar.api.batch.Decorator; import org.sonar.api.batch.DecoratorContext; import org.sonar.api.batch.DependsUpon; @@ -40,6 +41,7 @@ import org.sonar.core.UtcDateUtils; import javax.annotation.CheckForNull; +import java.util.Date; import java.util.List; import java.util.Map; @@ -107,9 +109,15 @@ public class QProfileEventsDecorator implements Decorator { Event event = new Event(); event.setName(String.format("Changes in %s", profileLabel(profile))); event.setCategory(Event.CATEGORY_PROFILE); + Date from = previousProfile.getRulesUpdatedAt(); + + // strictly greater than previous date + // This hack must be done because date precision is millisecond in db/es and date format is select only + from = DateUtils.addSeconds(from, 1); + String data = KeyValueFormat.format(ImmutableSortedMap.of( "key", profile.getKey(), - "from", UtcDateUtils.formatDateTime(previousProfile.getRulesUpdatedAt()), + "from", UtcDateUtils.formatDateTime(from), "to", UtcDateUtils.formatDateTime(profile.getRulesUpdatedAt()))); event.setData(data); persistenceManager.saveEvent(context.getResource(), event); diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileEventsDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileEventsDecoratorTest.java index c1afcb1e2ee..3d7f46fde69 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileEventsDecoratorTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/rule/QProfileEventsDecoratorTest.java @@ -122,7 +122,8 @@ public class QProfileEventsDecoratorTest { Event event = (Event) item; return event.getCategory().equals(Event.CATEGORY_PROFILE) && "Changes in 'Java One' (Java)".equals(event.getName()) && - "from=2014-01-15T12:00:00+0000;key=J1;to=2014-02-20T12:00:00+0000".equals(event.getData()); + // "from" is one second more ! + "from=2014-01-15T12:00:01+0000;key=J1;to=2014-02-20T12:00:00+0000".equals(event.getData()); } })); } -- 2.39.5