summaryrefslogtreecommitdiffstats
path: root/plugins/sonar-core-gwt
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-12-08 13:23:18 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-12-08 13:23:18 +0000
commit72d3b0a889574cea355b61f7395b38a55071da33 (patch)
treeccf1d4e3fb47c30aa0addce09913d5017833b559 /plugins/sonar-core-gwt
parent4a7eae13c556369592da2ed726e4c8546b61a17a (diff)
downloadsonarqube-72d3b0a889574cea355b61f7395b38a55071da33.tar.gz
sonarqube-72d3b0a889574cea355b61f7395b38a55071da33.zip
SONAR-1937 violations tab : display violation age in days to current date
Diffstat (limited to 'plugins/sonar-core-gwt')
-rw-r--r--plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java32
1 files changed, 26 insertions, 6 deletions
diff --git a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java
index 14cf189a9f0..b5122536668 100644
--- a/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java
+++ b/plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java
@@ -29,15 +29,13 @@ import org.sonar.wsclient.services.Resource;
import org.sonar.wsclient.services.Violation;
import org.sonar.wsclient.services.ViolationQuery;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
public class ViolationsPanel extends SourcePanel {
private boolean expand = false;
private List<Violation> violations;
private Map<Integer, List<Violation>> filteredViolationsByLine = new HashMap<Integer, List<Violation>>();
+ private final static Date now = new Date();
public ViolationsPanel(Resource resource, String filter) {
super(resource);
@@ -140,8 +138,12 @@ public class ViolationsPanel extends SourcePanel {
@Override
public String getColumn4() {
String age = "";
- if (violation.getAge()!=null && violation.getAge()>0) {
- age = " <span class='note'>(" + violation.getAge() + " days)</span>";
+ if (violation.getCreatedAt() != null) {
+ if (sameDay(now, violation.getCreatedAt())) {
+ age = " <span class='note'>(today)</span>";
+ } else {
+ age = " <span class='note'>(" + diffInDays(violation.getCreatedAt(), now) + " days)</span>";
+ }
}
return "<div class=\"warn\">" + Icons.forPriority(violation.getPriority()).getHTML() + "</img> "
+ " <a href=\"" + Links.urlForRule(violation.getRuleKey(), false)
@@ -150,6 +152,24 @@ public class ViolationsPanel extends SourcePanel {
+ Utils.escapeHtml(violation.getRuleName()) + "</b></a> : "
+ Utils.escapeHtml(violation.getMessage()) + age + "</div>";
}
+
+ @SuppressWarnings("deprecation")
+ static boolean sameDay(Date d1, Date d2) {
+ return d1.getDate() == d2.getDate() && d1.getMonth() == d2.getMonth() && d1.getYear() == d2.getYear();
+ }
+
+ @SuppressWarnings(value = "deprecation")
+ static int diffInDays(Date d1, Date d2) {
+ int difference = 0;
+ int endDateOffset = -(d1.getTimezoneOffset() * 60 * 1000);
+ long endDateInstant = d1.getTime() + endDateOffset;
+ int startDateOffset = -(d2.getTimezoneOffset() * 60 * 1000);
+ long startDateInstant = d2.getTime() + startDateOffset;
+ double differenceDouble = (double) Math.abs(endDateInstant - startDateInstant) / (1000.0 * 60 * 60 * 24);
+ differenceDouble = Math.max(1.0D, differenceDouble);
+ difference = (int) differenceDouble;
+ return difference;
+ }
}
private boolean hasViolations(int lineIndex) {