diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2013-05-29 18:13:30 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2013-05-29 18:14:51 +0200 |
commit | ab1fbbbb74b0a8544cf2d837cff59116038a7dd9 (patch) | |
tree | fe0f13666544a9a57aaddb21e60afa0d52fdabc8 /sonar-batch | |
parent | 7cd778260833ff4ebeee9fbbdf84cc2fc44cf500 (diff) | |
download | sonarqube-ab1fbbbb74b0a8544cf2d837cff59116038a7dd9.tar.gz sonarqube-ab1fbbbb74b0a8544cf2d837cff59116038a7dd9.zip |
SONAR-4313 forbid violations on program units and blocks
Diffstat (limited to 'sonar-batch')
3 files changed, 8 insertions, 3 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 cef707b9799..bd5fc8979b4 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 @@ -311,6 +311,10 @@ public class DefaultIndex extends SonarIndex { throw new IllegalArgumentException("A resource must be set on the ViolationQuery in order to search for violations."); } + if (!Scopes.isHigherThanOrEquals(resource, Scopes.FILE)) { + return Collections.emptyList(); + } + Bucket bucket = buckets.get(resource); if (bucket == null) { return Collections.emptyList(); @@ -320,6 +324,7 @@ public class DefaultIndex extends SonarIndex { if (violationQuery.getSwitchMode() == ViolationQuery.SwitchMode.BOTH) { return violations; } + List<Violation> filteredViolations = Lists.newArrayList(); for (Violation violation : violations) { if (isFiltered(violation, violationQuery.getSwitchMode())) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedViolations.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedViolations.java index b0c0c39b66a..c61fe4a9ff8 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedViolations.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/DeprecatedViolations.java @@ -21,7 +21,6 @@ package org.sonar.batch.issue; import com.google.common.collect.Lists; import org.sonar.api.BatchComponent; -import org.sonar.api.issue.Issue; import org.sonar.api.resources.Resource; import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleFinder; @@ -30,11 +29,11 @@ import org.sonar.api.rules.Violation; import org.sonar.batch.index.ResourceCache; import org.sonar.core.issue.DefaultIssue; -import java.util.Collection; import java.util.List; /** * Bridge with violations, that have been deprecated in 3.6. + * * @since 3.6 */ public class DeprecatedViolations implements BatchComponent { @@ -70,7 +69,7 @@ public class DeprecatedViolations implements BatchComponent { violation.setCreatedAt(issue.creationDate()); violation.setManual(issue.reporter() != null); violation.setSeverity(RulePriority.valueOf(issue.severity())); - violation.setSwitchedOff(Issue.RESOLUTION_FALSE_POSITIVE.equals(issue.resolution())); + violation.setSwitchedOff(issue.resolution() != null); return violation; } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/DeprecatedViolationsTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/DeprecatedViolationsTest.java index bff9ae4e2d0..779e783f965 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/issue/DeprecatedViolationsTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/issue/DeprecatedViolationsTest.java @@ -60,6 +60,7 @@ public class DeprecatedViolationsTest { assertThat(violation.getRule().getRepositoryKey()).isEqualTo("squid"); assertThat(violation.getRule().getKey()).isEqualTo("AvoidCycles"); assertThat(violation.getResource()).isNotNull(); + assertThat(violation.isSwitchedOff()).isFalse(); } private DefaultIssue newIssue(RuleKey ruleKey) { |