}
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) {
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
}