summaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-12-04 23:24:13 +0100
committersimonbrandhof <simon.brandhof@gmail.com>2011-12-04 23:24:33 +0100
commitee09f485818f4808fa7aff7c02969c972931a180 (patch)
tree1f2f1ddcc33e1256cd3140182fb76fc867246ed6 /sonar-batch/src
parent524677d6bdb4b9810583c7f2fe8b20de0d070ffe (diff)
downloadsonarqube-ee09f485818f4808fa7aff7c02969c972931a180.tar.gz
sonarqube-ee09f485818f4808fa7aff7c02969c972931a180.zip
SONAR-1974 inject manual violations into batch
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java63
1 files changed, 27 insertions, 36 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
index 94becc59ec7..3adbd331509 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
@@ -19,15 +19,9 @@
*/
package org.sonar.batch.index;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import org.apache.commons.lang.ObjectUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
@@ -36,17 +30,9 @@ import org.sonar.api.batch.Event;
import org.sonar.api.batch.SonarIndex;
import org.sonar.api.database.model.ResourceModel;
import org.sonar.api.design.Dependency;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.MeasuresFilter;
-import org.sonar.api.measures.MeasuresFilters;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.measures.MetricFinder;
+import org.sonar.api.measures.*;
import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.ProjectLink;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
-import org.sonar.api.resources.Scopes;
+import org.sonar.api.resources.*;
import org.sonar.api.rules.ActiveRule;
import org.sonar.api.rules.Violation;
import org.sonar.api.utils.SonarException;
@@ -56,9 +42,7 @@ import org.sonar.batch.ProjectTree;
import org.sonar.batch.ResourceFilters;
import org.sonar.batch.ViolationFilters;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
+import java.util.*;
public class DefaultIndex extends SonarIndex {
@@ -315,9 +299,9 @@ public class DefaultIndex extends SonarIndex {
List<Violation> filteredViolations = Lists.newArrayList();
ViolationQuery.SwitchMode mode = violationQuery.getSwitchMode();
for (Violation violation : bucket.getViolations()) {
- if (mode== ViolationQuery.SwitchMode.BOTH ||
- (mode== ViolationQuery.SwitchMode.OFF && violation.isSwitchedOff()) ||
- (mode== ViolationQuery.SwitchMode.ON && !violation.isSwitchedOff())) {
+ if (mode == ViolationQuery.SwitchMode.BOTH ||
+ (mode == ViolationQuery.SwitchMode.OFF && violation.isSwitchedOff()) ||
+ (mode == ViolationQuery.SwitchMode.ON && !violation.isSwitchedOff())) {
filteredViolations.add(violation);
}
}
@@ -341,19 +325,26 @@ public class DefaultIndex extends SonarIndex {
if (bucket != null && !bucket.isExcluded()) {
boolean isIgnored = !force && violationFilters != null && violationFilters.isIgnored(violation);
if (!isIgnored) {
- ActiveRule activeRule = profile.getActiveRule(violation.getRule());
- if (activeRule == null) {
- if (currentProject.getReuseExistingRulesConfig()) {
- violation.setSeverity(violation.getRule().getSeverity());
- doAddViolation(violation, bucket);
- } else {
- LoggerFactory.getLogger(getClass()).debug("Rule is not activated, ignoring violation {}", violation);
- }
+ // TODO this code is not the responsibility of this index. It should be moved somewhere else.
- } else {
- violation.setSeverity(activeRule.getSeverity());
+ if (violation.isManual()) {
doAddViolation(violation, bucket);
+ } else {
+ ActiveRule activeRule = profile.getActiveRule(violation.getRule());
+ if (activeRule == null) {
+ if (currentProject.getReuseExistingRulesConfig()) {
+ violation.setSeverity(violation.getRule().getSeverity());
+ doAddViolation(violation, bucket);
+
+ } else {
+ LoggerFactory.getLogger(getClass()).debug("Rule is not activated, ignoring violation {}", violation);
+ }
+
+ } else {
+ violation.setSeverity(activeRule.getSeverity());
+ doAddViolation(violation, bucket);
+ }
}
}
}
@@ -400,7 +391,7 @@ public class DefaultIndex extends SonarIndex {
Event event = new Event(name, description, category);
event.setDate(date);
event.setCreatedAt(new Date());
-
+
persistence.saveEvent(resource, event);
return null;
}