]> source.dussan.org Git - sonarqube.git/commitdiff
fix bug in SONAR-1729
authorsimonbrandhof <simon.brandhof@gmail.com>
Fri, 10 Dec 2010 12:54:25 +0000 (12:54 +0000)
committersimonbrandhof <simon.brandhof@gmail.com>
Fri, 10 Dec 2010 12:54:25 +0000 (12:54 +0000)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ViolationsDecoratorTest.java

index baf826fbe12f6c8e192da33dd6bae0ad14159f1b..1b5d56d458e1491b94213e7b0f30cd9f30d33516 100644 (file)
@@ -104,25 +104,21 @@ public class ViolationsDecorator implements Decorator {
   }
 
   private void saveViolationsByRule(DecoratorContext context) {
-    // See SONAR-1729
-    // Extrapolation : assume that the measure with key [metric "violations", rule] does not exist when the measure "violations" does not exist as well.
-    if (context.getMeasure(CoreMetrics.VIOLATIONS) == null) {
-      Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.rules(CoreMetrics.VIOLATIONS));
-      for (Measure childMeasure : children) {
-        RuleMeasure childRuleMeasure = (RuleMeasure) childMeasure;
-        Rule rule = childRuleMeasure.getRule();
-        if (rule != null && MeasureUtils.hasValue(childRuleMeasure)) {
-          rules.add(rule, childRuleMeasure.getValue().intValue());
-          ruleToSeverity.put(childRuleMeasure.getRule(), childRuleMeasure.getRulePriority());
-        }
-      }
-      for (Multiset.Entry<Rule> entry : rules.entrySet()) {
-        Rule rule = entry.getElement();
-        RuleMeasure measure = RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule, (double) entry.getCount());
-        measure.setRulePriority(ruleToSeverity.get(rule));
-        context.saveMeasure(measure);
+    Collection<Measure> children = context.getChildrenMeasures(MeasuresFilters.rules(CoreMetrics.VIOLATIONS));
+    for (Measure childMeasure : children) {
+      RuleMeasure childRuleMeasure = (RuleMeasure) childMeasure;
+      Rule rule = childRuleMeasure.getRule();
+      if (rule != null && MeasureUtils.hasValue(childRuleMeasure)) {
+        rules.add(rule, childRuleMeasure.getValue().intValue());
+        ruleToSeverity.put(childRuleMeasure.getRule(), childRuleMeasure.getRulePriority());
       }
     }
+    for (Multiset.Entry<Rule> entry : rules.entrySet()) {
+      Rule rule = entry.getElement();
+      RuleMeasure measure = RuleMeasure.createForRule(CoreMetrics.VIOLATIONS, rule, (double) entry.getCount());
+      measure.setRulePriority(ruleToSeverity.get(rule));
+      context.saveMeasure(measure);
+    }
   }
 
   private void saveTotalViolations(DecoratorContext context) {
index 40e9383557e6e5c8425ddb72db46ab1dd089f123..e848be2a39d2a4d7f87c2fd01f6da2b2dbf6d57a 100644 (file)
@@ -84,7 +84,7 @@ public class ViolationsDecoratorTest {
 
     decorator.decorate(resource, context);
 
-    verify(context, never()).saveMeasure(argThat(new IsMeasure(CoreMetrics.VIOLATIONS)));// not changed
+    verify(context, never()).saveMeasure(argThat(new IsMeasure(CoreMetrics.VIOLATIONS, 4.0)));// not changed
     verify(context, never()).saveMeasure(argThat(new IsMeasure(CoreMetrics.MAJOR_VIOLATIONS)));// not changed
     verify(context, times(1)).saveMeasure(argThat(new IsMeasure(CoreMetrics.CRITICAL_VIOLATIONS)));// did not exist
   }