aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-core-plugin
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-12-10 12:54:25 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-12-10 12:54:25 +0000
commit9be370d0f7cd108c40be4e6aa00bb5a55b39416d (patch)
treeedaf40d160a2009f24b6fba96b0545c046e36b3a /plugins/sonar-core-plugin
parent5acd5df8c512088a26b591c90866e4f3d085d6a7 (diff)
downloadsonarqube-9be370d0f7cd108c40be4e6aa00bb5a55b39416d.tar.gz
sonarqube-9be370d0f7cd108c40be4e6aa00bb5a55b39416d.zip
fix bug in SONAR-1729
Diffstat (limited to 'plugins/sonar-core-plugin')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/ViolationsDecorator.java30
-rw-r--r--plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/ViolationsDecoratorTest.java2
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
}