aboutsummaryrefslogtreecommitdiffstats
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
parent4a7eae13c556369592da2ed726e4c8546b61a17a (diff)
downloadsonarqube-72d3b0a889574cea355b61f7395b38a55071da33.tar.gz
sonarqube-72d3b0a889574cea355b61f7395b38a55071da33.zip
SONAR-1937 violations tab : display violation age in days to current date
-rw-r--r--plugins/sonar-core-gwt/src/main/java/org/sonar/plugins/core/violationsviewer/client/ViolationsPanel.java32
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java1
-rw-r--r--sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java1
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java12
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb10
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java13
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java1
7 files changed, 33 insertions, 37 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) {
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
index 921195a9046..19d118db5ca 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/MeasurePersister.java
@@ -94,6 +94,7 @@ public final class MeasurePersister {
return measure.getId() == null &&
metric.isOptimizedBestValue() == Boolean.TRUE &&
metric.getBestValue() != null &&
+ measure.getValue() != null &
NumberUtils.compare(metric.getBestValue(), measure.getValue()) == 0 &&
measure.getAlertStatus() == null &&
measure.getDescription() == null &&
diff --git a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java
index d5fff51f259..bf0194820e3 100644
--- a/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java
+++ b/sonar-gwt-api/src/main/java/org/sonar/wsclient/gwt/unmarshallers/ViolationUnmarshaller.java
@@ -31,7 +31,6 @@ public class ViolationUnmarshaller extends AbstractUnmarshaller<Violation> {
violation.setLine(JsonUtils.getInteger(json, "line"));
violation.setSeverity(JsonUtils.getString(json, "priority"));
violation.setCreatedAt(JsonUtils.getDate(json, "createdAt"));
- violation.setAge(JsonUtils.getInteger(json, "age"));
JSONObject rule = (JSONObject) json.get("rule");
if (rule != null) {
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
index 09d826610ca..4c812dcc659 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/CoreMetrics.java
@@ -375,27 +375,27 @@ public final class CoreMetrics {
public static final String NEW_VIOLATIONS_KEY = "new_violations";
public static final Metric NEW_VIOLATIONS = new Metric(NEW_VIOLATIONS_KEY, "New Violations", "New Violations", Metric.ValueType.INT,
- Metric.DIRECTION_WORST, true, DOMAIN_RULES);
+ Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true);
public static final String NEW_BLOCKER_VIOLATIONS_KEY = "new_blocker_violations";
public static final Metric NEW_BLOCKER_VIOLATIONS = new Metric(NEW_BLOCKER_VIOLATIONS_KEY, "New Blocker violations", "New Blocker violations",
- Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES);
+ Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true);
public static final String NEW_CRITICAL_VIOLATIONS_KEY = "new_critical_violations";
public static final Metric NEW_CRITICAL_VIOLATIONS = new Metric(NEW_CRITICAL_VIOLATIONS_KEY, "New Critical violations", "New Critical violations",
- Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES);
+ Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true);
public static final String NEW_MAJOR_VIOLATIONS_KEY = "new_major_violations";
public static final Metric NEW_MAJOR_VIOLATIONS = new Metric(NEW_MAJOR_VIOLATIONS_KEY, "New Major violations", "New Major violations",
- Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES);
+ Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true);
public static final String NEW_MINOR_VIOLATIONS_KEY = "new_minor_violations";
public static final Metric NEW_MINOR_VIOLATIONS = new Metric(NEW_MINOR_VIOLATIONS_KEY, "New Minor violations", "New Minor violations",
- Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES);
+ Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true);
public static final String NEW_INFO_VIOLATIONS_KEY = "new_info_violations";
public static final Metric NEW_INFO_VIOLATIONS = new Metric(NEW_INFO_VIOLATIONS_KEY, "New Info violations", "New Info violations",
- Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES);
+ Metric.ValueType.INT, Metric.DIRECTION_WORST, true, DOMAIN_RULES).setHidden(true);
/* Design */
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb
index 3b4e73b4de7..64a2517af13 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb
@@ -23,14 +23,6 @@ class RuleFailure < ActiveRecord::Base
belongs_to :rule
belongs_to :snapshot
- def age_in_days
- if created_at
- ((snapshot.created_at - created_at)/(60 * 60 * 24)).to_i
- else
- nil
- end
- end
-
def to_hash_json
json = {}
json['message'] = message
@@ -38,7 +30,6 @@ class RuleFailure < ActiveRecord::Base
json['priority'] = Sonar::RulePriority.to_s(failure_level).upcase
if created_at
json['createdAt'] = format_datetime(created_at)
- json['age'] = age_in_days
end
json['rule'] = {
:key => rule.key,
@@ -61,7 +52,6 @@ class RuleFailure < ActiveRecord::Base
xml.priority(Sonar::RulePriority.to_s(failure_level))
if created_at
xml.createdAt(format_datetime(created_at))
- xml.age(age_in_days)
end
xml.rule do
xml.key(rule.key)
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java
index c984d15a3bf..ff0c3f22ce9 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Violation.java
@@ -33,7 +33,6 @@ public class Violation extends Model {
private String resourceScope = null;
private String resourceQualifier = null;
private Date createdAt = null;
- private Integer age = null;
public String getMessage() {
return message;
@@ -137,18 +136,6 @@ public class Violation extends Model {
/**
* @since 2.5
*/
- public Integer getAge() {
- return age;
- }
-
- public Violation setAge(Integer age) {
- this.age = age;
- return this;
- }
-
- /**
- * @since 2.5
- */
public Date getCreatedAt() {
return createdAt;
}
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java
index c0c5aa538cc..258e5938570 100644
--- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java
+++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ViolationUnmarshaller.java
@@ -31,7 +31,6 @@ public class ViolationUnmarshaller extends AbstractUnmarshaller<Violation> {
violation.setLine(JsonUtils.getInteger(json, "line"));
violation.setSeverity(JsonUtils.getString(json, "priority"));
violation.setCreatedAt(JsonUtils.getDateTime(json, "createdAt"));
- violation.setAge(JsonUtils.getInteger(json, "age"));
JSONObject rule = (JSONObject) json.get("rule");
if (rule != null) {