*/
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;
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;
*/
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;
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;
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();
}
}
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;
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
resourceKey = def.getKey();
}
- issueCache.put(resourceKey, (DefaultAnalyzerIssue) issue);
+ if (issueFilters.accept(AnalyzerContextAdaptor.toDefaultIssue(def.getKey(), resourceKey, issue), null)) {
+ issueCache.put(resourceKey, (DefaultAnalyzerIssue) issue);
+ }
}
-
}
ModuleSettings.class,
EventBus.class,
- Phase2Executor.class,
- Phase2Executor.getPhaseClasses(),
+ ModuleScanExecutor.class,
+ ModuleScanExecutor.getPhaseClasses(),
moduleDefinition.getContainerExtensions(),
AnalyzersExecutor.class,
@Override
protected void doAfterStart() {
- getComponentByType(Phase2Executor.class).execute(moduleDefinition);
+ getComponentByType(ModuleScanExecutor.class).execute(moduleDefinition);
}
}
--- /dev/null
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2014 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.batch.scan2;
+
+import org.sonar.api.batch.analyzer.AnalyzerContext;
+
+import com.google.common.collect.Lists;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.sonar.api.batch.bootstrap.ProjectDefinition;
+import org.sonar.batch.issue.ignore.scanner.IssueExclusionsLoader;
+import org.sonar.batch.phases.SensorsExecutor;
+import org.sonar.batch.rule.QProfileVerifier;
+import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem;
+import org.sonar.batch.scan.filesystem.FileSystemLogger;
+
+import java.util.Collection;
+
+public final class ModuleScanExecutor {
+
+ public static final Logger LOGGER = LoggerFactory.getLogger(ModuleScanExecutor.class);
+
+ private final AnalyzersExecutor analyzersExecutor;
+ private final AnalyzerContext analyzerContext;
+ private final FileSystemLogger fsLogger;
+ private final DefaultModuleFileSystem fs;
+ private final QProfileVerifier profileVerifier;
+ private final IssueExclusionsLoader issueExclusionsLoader;
+
+ public ModuleScanExecutor(AnalyzersExecutor analyzersExecutor,
+ AnalyzerContext analyzerContext,
+ FileSystemLogger fsLogger, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier,
+ IssueExclusionsLoader issueExclusionsLoader) {
+ this.analyzersExecutor = analyzersExecutor;
+ this.analyzerContext = analyzerContext;
+ this.fsLogger = fsLogger;
+ this.fs = fs;
+ this.profileVerifier = profileVerifier;
+ this.issueExclusionsLoader = issueExclusionsLoader;
+ }
+
+ public static Collection<Class> getPhaseClasses() {
+ return Lists.<Class>newArrayList(SensorsExecutor.class);
+ }
+
+ /**
+ * Executed on each module
+ */
+ public void execute(ProjectDefinition moduleDefinition) {
+ fsLogger.log();
+
+ // Index and lock the filesystem
+ fs.index();
+
+ // Log detected languages and their profiles after FS is indexed and languages detected
+ profileVerifier.execute();
+
+ // Initialize issue exclusions
+ issueExclusionsLoader.execute();
+
+ analyzersExecutor.execute(analyzerContext);
+ }
+}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.batch.scan2;
-
-import org.sonar.api.batch.analyzer.AnalyzerContext;
-
-import com.google.common.collect.Lists;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.batch.issue.ignore.scanner.IssueExclusionsLoader;
-import org.sonar.batch.phases.SensorsExecutor;
-import org.sonar.batch.rule.QProfileVerifier;
-import org.sonar.batch.scan.filesystem.DefaultModuleFileSystem;
-import org.sonar.batch.scan.filesystem.FileSystemLogger;
-
-import java.util.Collection;
-
-public final class Phase2Executor {
-
- public static final Logger LOGGER = LoggerFactory.getLogger(Phase2Executor.class);
-
- private final AnalyzersExecutor analyzersExecutor;
- private final AnalyzerContext analyzerContext;
- private final FileSystemLogger fsLogger;
- private final DefaultModuleFileSystem fs;
- private final QProfileVerifier profileVerifier;
- private final IssueExclusionsLoader issueExclusionsLoader;
-
- public Phase2Executor(AnalyzersExecutor analyzersExecutor,
- AnalyzerContext analyzerContext,
- FileSystemLogger fsLogger, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier,
- IssueExclusionsLoader issueExclusionsLoader) {
- this.analyzersExecutor = analyzersExecutor;
- this.analyzerContext = analyzerContext;
- this.fsLogger = fsLogger;
- this.fs = fs;
- this.profileVerifier = profileVerifier;
- this.issueExclusionsLoader = issueExclusionsLoader;
- }
-
- public static Collection<Class> getPhaseClasses() {
- return Lists.<Class>newArrayList(SensorsExecutor.class);
- }
-
- /**
- * Executed on each module
- */
- public void execute(ProjectDefinition moduleDefinition) {
- fsLogger.log();
-
- // Index and lock the filesystem
- fs.index();
-
- // Log detected languages and their profiles after FS is indexed and languages detected
- profileVerifier.execute();
-
- // Initialize issue exclusions
- issueExclusionsLoader.execute();
-
- analyzersExecutor.execute(analyzerContext);
- }
-}
protected void doAfterStart() {
ProjectReactor tree = getComponentByType(ProjectReactor.class);
scanRecursively(tree.getRoot());
+
getComponentByType(ScanTaskObservers.class).notifyEndOfScanTask();
}
assertThat(result.issues()).hasSize(24);
}
+ @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 {
+++ /dev/null
-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
return this;
}
-
public DefaultIssueBuilder projectKey(String projectKey) {
this.projectKey = projectKey;
return this;
}
@Override
- public Issuable.IssueBuilder ruleKey(RuleKey ruleKey) {
+ public DefaultIssueBuilder ruleKey(RuleKey ruleKey) {
this.ruleKey = ruleKey;
return this;
}
@Override
- public Issuable.IssueBuilder line(@Nullable Integer line) {
+ public DefaultIssueBuilder line(@Nullable Integer line) {
this.line = line;
return this;
}
@Override
- public Issuable.IssueBuilder message(@Nullable String s) {
+ public DefaultIssueBuilder message(@Nullable String s) {
this.message = s;
return this;
}
@Override
- public Issuable.IssueBuilder severity(@Nullable String severity) {
+ public DefaultIssueBuilder severity(@Nullable String severity) {
this.severity = severity;
return this;
}
@Override
- public Issuable.IssueBuilder effortToFix(@Nullable Double d) {
+ public DefaultIssueBuilder effortToFix(@Nullable Double d) {
this.effortToFix = d;
return this;
}
@Override
- public Issuable.IssueBuilder reporter(@Nullable String s) {
+ public DefaultIssueBuilder reporter(@Nullable String s) {
this.reporter = s;
return this;
}
@Override
- public Issuable.IssueBuilder attribute(String key, @Nullable String value) {
+ public DefaultIssueBuilder attribute(String key, @Nullable String value) {
if (attributes == null) {
attributes = Maps.newLinkedHashMap();
}