aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src
diff options
context:
space:
mode:
authorDavid Gageot <david@gageot.net>2012-07-05 23:35:22 +0200
committerDavid Gageot <david@gageot.net>2012-07-06 11:06:39 +0200
commit956068aea4fec3b9fcfed8fc8f34cc581dfd95f7 (patch)
tree4ae814d932acf25c38309ea3d78e42dbc718b1f5 /sonar-batch/src
parent330d9c810d18daa2bff3354f1e6915dbce94eb34 (diff)
downloadsonarqube-956068aea4fec3b9fcfed8fc8f34cc581dfd95f7.tar.gz
sonarqube-956068aea4fec3b9fcfed8fc8f34cc581dfd95f7.zip
Fix violations
Diffstat (limited to 'sonar-batch/src')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java59
1 files changed, 32 insertions, 27 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 783bffb6ad9..807f3e17504 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
@@ -299,22 +299,28 @@ public class DefaultIndex extends SonarIndex {
if (resource == null) {
throw new IllegalArgumentException("A resource must be set on the ViolationQuery in order to search for violations.");
}
+
Bucket bucket = buckets.get(resource);
if (bucket == null) {
return Collections.emptyList();
}
+
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 (isFiltered(violation, mode)) {
filteredViolations.add(violation);
}
}
return filteredViolations;
}
+ private static boolean isFiltered(Violation violation, ViolationQuery.SwitchMode mode) {
+ return (mode == ViolationQuery.SwitchMode.BOTH
+ || (mode == ViolationQuery.SwitchMode.OFF && violation.isSwitchedOff())
+ || (mode == ViolationQuery.SwitchMode.ON && !violation.isSwitchedOff()));
+ }
+
@Override
public void addViolation(Violation violation, boolean force) {
Resource resource = violation.getResource();
@@ -330,32 +336,31 @@ public class DefaultIndex extends SonarIndex {
}
Bucket bucket = checkIndexed(resource);
- if (bucket != null && !bucket.isExcluded()) {
- boolean isIgnored = !force && violationFilters != null && violationFilters.isIgnored(violation);
- if (!isIgnored) {
-
- // TODO this code is not the responsibility of this index. It should be moved somewhere else.
-
- 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);
- }
- }
+ if (bucket == null || bucket.isExcluded()) {
+ return;
+ }
+
+ boolean isIgnored = !force && violationFilters != null && violationFilters.isIgnored(violation);
+ if (!isIgnored) {
+ addViolation(violation, bucket);
+ }
+ }
+
+ private void addViolation(Violation violation, Bucket bucket) {
+ // TODO this code is not the responsibility of this index. It should be moved somewhere else.
+ if (!violation.isManual()) {
+ ActiveRule activeRule = profile.getActiveRule(violation.getRule());
+ if (activeRule != null) {
+ violation.setSeverity(activeRule.getSeverity());
+ } else if (currentProject.getReuseExistingRulesConfig()) {
+ violation.setSeverity(violation.getRule().getSeverity());
+ } else {
+ LoggerFactory.getLogger(getClass()).debug("Rule is not activated, ignoring violation {}", violation);
+ return;
}
}
+
+ doAddViolation(violation, bucket);
}
private void doAddViolation(Violation violation, Bucket bucket) {