diff options
2 files changed, 14 insertions, 18 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java index baf826fbe12..1b5d56d458e 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java @@ -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) { diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ViolationsDecoratorTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ViolationsDecoratorTest.java index 40e9383557e..e848be2a39d 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ViolationsDecoratorTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ViolationsDecoratorTest.java @@ -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 } |