diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-06-19 17:59:49 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-06-19 18:01:24 +0200 |
commit | a2c2ef437744a6ce19dcd2886bf6123832ee1f54 (patch) | |
tree | a6ca94287328df6004234b88dbb33f39823774b6 /sonar-batch | |
parent | 6b861f130b304f2efdc6359cd1602e2299e9c352 (diff) | |
download | sonarqube-a2c2ef437744a6ce19dcd2886bf6123832ee1f54.tar.gz sonarqube-a2c2ef437744a6ce19dcd2886bf6123832ee1f54.zip |
SONAR-5389 Reintroduce Issue filters
Diffstat (limited to 'sonar-batch')
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java | 7 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java | 15 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java | 19 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java | 6 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java (renamed from sonar-batch/src/main/java/org/sonar/batch/scan2/Phase2Executor.java) | 6 | ||||
-rw-r--r-- | sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java | 1 | ||||
-rw-r--r-- | sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/XooMediumTest.java | 14 | ||||
-rw-r--r-- | sonar-batch/src/test/resources/org/sonar/batch/medium/simple-project/sonar-project.properties | 7 | ||||
-rw-r--r-- | sonar-batch/src/test/resources/org/sonar/batch/medium/simple-project/sources/Fake.java | 1 |
9 files changed, 48 insertions, 28 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java index b43f98f6d27..a6987f2368e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java @@ -19,7 +19,7 @@ */ package org.sonar.batch.issue; -import org.sonar.api.BatchExtension; +import org.sonar.api.BatchComponent; import org.sonar.api.issue.batch.IssueFilter; import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.rules.Violation; @@ -27,14 +27,15 @@ import org.sonar.batch.ViolationFilters; import javax.annotation.Nullable; -public class IssueFilters implements BatchExtension { +public class IssueFilters implements BatchComponent { private final ViolationFilters deprecatedFilters; private final DeprecatedViolations deprecatedViolations; private final org.sonar.api.issue.IssueFilter[] exclusionFilters; private final IssueFilter[] filters; - public IssueFilters(@Nullable ViolationFilters deprecatedFilters, @Nullable DeprecatedViolations deprecatedViolations, org.sonar.api.issue.IssueFilter[] exclusionFilters, IssueFilter[] filters) { + public IssueFilters(@Nullable ViolationFilters deprecatedFilters, @Nullable DeprecatedViolations deprecatedViolations, org.sonar.api.issue.IssueFilter[] exclusionFilters, + IssueFilter[] filters) { this.deprecatedFilters = deprecatedFilters; this.deprecatedViolations = deprecatedViolations; this.exclusionFilters = exclusionFilters; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java b/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java index b4231b5c252..eb76d3a269d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/AnalyzerContextAdaptor.java @@ -19,8 +19,6 @@ */ package org.sonar.batch.scan; -import org.sonar.api.batch.measure.Metric; - import org.sonar.api.batch.SensorContext; import org.sonar.api.batch.analyzer.AnalyzerContext; import org.sonar.api.batch.analyzer.issue.AnalyzerIssue; @@ -31,16 +29,19 @@ import org.sonar.api.batch.analyzer.measure.AnalyzerMeasureBuilder; import org.sonar.api.batch.analyzer.measure.internal.DefaultAnalyzerMeasureBuilder; import org.sonar.api.batch.fs.FileSystem; import org.sonar.api.batch.fs.InputFile; +import org.sonar.api.batch.measure.Metric; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.component.ResourcePerspectives; import org.sonar.api.config.Settings; import org.sonar.api.issue.Issuable; +import org.sonar.api.issue.internal.DefaultIssue; import org.sonar.api.measures.Measure; import org.sonar.api.measures.MetricFinder; import org.sonar.api.resources.File; import org.sonar.api.resources.Project; import org.sonar.api.resources.Resource; import org.sonar.api.rule.RuleKey; +import org.sonar.core.issue.DefaultIssueBuilder; import java.io.Serializable; @@ -194,12 +195,18 @@ public class AnalyzerContextAdaptor implements AnalyzerContext { r = project; } Issuable issuable = perspectives.as(Issuable.class, r); - issuable.addIssue(issuable.newIssueBuilder() + issuable.addIssue(toDefaultIssue(project.getKey(), r.getKey(), issue)); + } + + public static DefaultIssue toDefaultIssue(String projectKey, String componentKey, AnalyzerIssue issue) { + return new DefaultIssueBuilder() + .componentKey(componentKey) + .projectKey(projectKey) .ruleKey(RuleKey.of(issue.ruleKey().repository(), issue.ruleKey().rule())) .effortToFix(issue.effortToFix()) .line(issue.line()) .message(issue.message()) - .build()); + .build(); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java index d9f03c17e50..cb46ec2204c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/DefaultAnalyzerContext.java @@ -34,6 +34,8 @@ import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.measure.Metric; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.config.Settings; +import org.sonar.batch.issue.IssueFilters; +import org.sonar.batch.scan.AnalyzerContextAdaptor; import org.sonar.core.component.ComponentKeys; import java.io.Serializable; @@ -42,19 +44,21 @@ public class DefaultAnalyzerContext implements AnalyzerContext { private final AnalyzerMeasureCache measureCache; private final AnalyzerIssueCache issueCache; - private ProjectDefinition def; - private Settings settings; - private FileSystem fs; - private ActiveRules activeRules; + private final ProjectDefinition def; + private final Settings settings; + private final FileSystem fs; + private final ActiveRules activeRules; + private final IssueFilters issueFilters; public DefaultAnalyzerContext(ProjectDefinition def, AnalyzerMeasureCache measureCache, AnalyzerIssueCache issueCache, - Settings settings, FileSystem fs, ActiveRules activeRules) { + Settings settings, FileSystem fs, ActiveRules activeRules, IssueFilters issueFilters) { this.def = def; this.measureCache = measureCache; this.issueCache = issueCache; this.settings = settings; this.fs = fs; this.activeRules = activeRules; + this.issueFilters = issueFilters; } @Override @@ -120,7 +124,8 @@ public class DefaultAnalyzerContext implements AnalyzerContext { resourceKey = def.getKey(); } - issueCache.put(resourceKey, (DefaultAnalyzerIssue) issue); + if (issueFilters.accept(AnalyzerContextAdaptor.toDefaultIssue(def.getKey(), resourceKey, issue), null)) { + issueCache.put(resourceKey, (DefaultAnalyzerIssue) issue); + } } - } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java index fc6c0e85b3b..3ec356536ad 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanContainer.java @@ -78,8 +78,8 @@ public class ModuleScanContainer extends ComponentContainer { ModuleSettings.class, EventBus.class, - Phase2Executor.class, - Phase2Executor.getPhaseClasses(), + ModuleScanExecutor.class, + ModuleScanExecutor.getPhaseClasses(), moduleDefinition.getContainerExtensions(), AnalyzersExecutor.class, @@ -133,7 +133,7 @@ public class ModuleScanContainer extends ComponentContainer { @Override protected void doAfterStart() { - getComponentByType(Phase2Executor.class).execute(moduleDefinition); + getComponentByType(ModuleScanExecutor.class).execute(moduleDefinition); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/Phase2Executor.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java index 0b6f2071df9..55423ee2eb5 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan2/Phase2Executor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/ModuleScanExecutor.java @@ -33,9 +33,9 @@ import org.sonar.batch.scan.filesystem.FileSystemLogger; import java.util.Collection; -public final class Phase2Executor { +public final class ModuleScanExecutor { - public static final Logger LOGGER = LoggerFactory.getLogger(Phase2Executor.class); + public static final Logger LOGGER = LoggerFactory.getLogger(ModuleScanExecutor.class); private final AnalyzersExecutor analyzersExecutor; private final AnalyzerContext analyzerContext; @@ -44,7 +44,7 @@ public final class Phase2Executor { private final QProfileVerifier profileVerifier; private final IssueExclusionsLoader issueExclusionsLoader; - public Phase2Executor(AnalyzersExecutor analyzersExecutor, + public ModuleScanExecutor(AnalyzersExecutor analyzersExecutor, AnalyzerContext analyzerContext, FileSystemLogger fsLogger, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier, IssueExclusionsLoader issueExclusionsLoader) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java index 8dad42fd7e6..28c5df4f765 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan2/ProjectScanContainer.java @@ -106,6 +106,7 @@ public class ProjectScanContainer extends ComponentContainer { protected void doAfterStart() { ProjectReactor tree = getComponentByType(ProjectReactor.class); scanRecursively(tree.getRoot()); + getComponentByType(ScanTaskObservers.class).notifyEndOfScanTask(); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/XooMediumTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/XooMediumTest.java index 73c2b563639..0b3cc9d77ef 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/XooMediumTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/xoo/XooMediumTest.java @@ -66,6 +66,20 @@ public class XooMediumTest { } @Test + public void testIssueExclusion() throws Exception { + File projectDir = new File(XooMediumTest.class.getResource("/org/sonar/batch/mediumtest/xoo/sample").toURI()); + + TaskResult result = tester + .newScanTask(new File(projectDir, "sonar-project.properties")) + .property("sonar.issue.ignore.allfile", "1") + .property("sonar.issue.ignore.allfile.1.fileRegexp", "object") + .start(); + + assertThat(result.measures()).hasSize(13); + assertThat(result.issues()).hasSize(19); + } + + @Test public void mediumTest() throws IOException { File baseDir = temp.newFolder(); diff --git a/sonar-batch/src/test/resources/org/sonar/batch/medium/simple-project/sonar-project.properties b/sonar-batch/src/test/resources/org/sonar/batch/medium/simple-project/sonar-project.properties deleted file mode 100644 index 69ccd8d1411..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/medium/simple-project/sonar-project.properties +++ /dev/null @@ -1,7 +0,0 @@ -sonar.projectKey=com.foo.project -sonar.projectName=Foo Project -sonar.projectVersion=1.0-SNAPSHOT -sonar.projectDescription=Description of Foo Project - -sonar.sources=sources -sonar.libraries=libs/*.txt diff --git a/sonar-batch/src/test/resources/org/sonar/batch/medium/simple-project/sources/Fake.java b/sonar-batch/src/test/resources/org/sonar/batch/medium/simple-project/sources/Fake.java deleted file mode 100644 index b2e6462a3f9..00000000000 --- a/sonar-batch/src/test/resources/org/sonar/batch/medium/simple-project/sources/Fake.java +++ /dev/null @@ -1 +0,0 @@ -Fake |