use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.
the class PatternMatcherTest method shouldReturnExtraPatternForResource.
@Test
public void shouldReturnExtraPatternForResource() {
String file = "foo";
patternMatcher.addPatternToExcludeResource(file);
IssuePattern extraPattern = patternMatcher.getPatternsForComponent(file).iterator().next();
assertThat(extraPattern.matchResource(file)).isTrue();
assertThat(extraPattern.isCheckLines()).isFalse();
}
use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.
the class EnforceIssuesFilter method accept.
@Override
public boolean accept(FilterableIssue issue, IssueFilterChain chain) {
boolean atLeastOneRuleMatched = false;
boolean atLeastOnePatternFullyMatched = false;
IssuePattern matchingPattern = null;
for (IssuePattern pattern : multicriteriaPatterns) {
if (ruleMatches(pattern, issue.ruleKey())) {
atLeastOneRuleMatched = true;
InputComponent component = ((DefaultFilterableIssue) issue).getComponent();
if (component.isFile()) {
DefaultInputFile file = (DefaultInputFile) component;
if (pattern.matchFile(file.getProjectRelativePath())) {
atLeastOnePatternFullyMatched = true;
matchingPattern = pattern;
} else if (pattern.matchFile(file.getModuleRelativePath())) {
warnOnceDeprecatedIssuePattern("Specifying module-relative paths at project level in property '" + IssueInclusionPatternInitializer.CONFIG_KEY + "' is deprecated. " + "To continue matching files like '" + file.getProjectRelativePath() + "', update this property so that patterns refer to project-relative paths.");
atLeastOnePatternFullyMatched = true;
matchingPattern = pattern;
}
}
}
}
if (atLeastOneRuleMatched) {
if (atLeastOnePatternFullyMatched) {
LOG.debug("Issue '{}' enforced by pattern '{}'", issue, matchingPattern);
}
return atLeastOnePatternFullyMatched;
} else {
return chain.accept(issue);
}
}
use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.
the class EnforceIssuesFilterTest method shouldRefuseIssueIfRuleMatchesButNotPath.
@Test
public void shouldRefuseIssueIfRuleMatchesButNotPath() {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
String path = "org/sonar/api/Issue.java";
String componentKey = "org.sonar.api.Issue";
RuleKey ruleKey = RuleKey.of("repo", "rule");
when(issue.ruleKey()).thenReturn(ruleKey);
when(issue.componentKey()).thenReturn(componentKey);
IssuePattern matching = new IssuePattern("no match", "repo:rule");
when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
when(issue.getComponent()).thenReturn(createComponentWithPath(path));
ignoreFilter = new EnforceIssuesFilter(exclusionPatternInitializer, analysisWarnings, activeRules);
assertThat(ignoreFilter.accept(issue, chain)).isFalse();
verifyNoInteractions(chain, analysisWarnings);
}
use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.
the class EnforceIssuesFilterTest method shouldPassToChainIfRuleDoesNotMatch.
@Test
public void shouldPassToChainIfRuleDoesNotMatch() {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
RuleKey ruleKey = RuleKey.of("repo", "rule");
when(issue.ruleKey()).thenReturn(ruleKey);
IssuePattern matching = new IssuePattern("**", "unknown");
when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
ignoreFilter = new EnforceIssuesFilter(exclusionPatternInitializer, analysisWarnings, activeRules);
assertThat(ignoreFilter.accept(issue, chain)).isTrue();
verify(chain).accept(issue);
}
use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.
the class EnforceIssuesFilterTest method shouldRefuseIssueIfRuleMatchesAndNotFile.
@Test
public void shouldRefuseIssueIfRuleMatchesAndNotFile() throws IOException {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
String path = "org/sonar/api/Issue.java";
RuleKey ruleKey = RuleKey.of("repo", "key");
when(issue.ruleKey()).thenReturn(ruleKey);
IssuePattern matching = new IssuePattern(path, ruleKey.toString());
when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
when(issue.getComponent()).thenReturn(TestInputFileBuilder.newDefaultInputProject("foo", tempFolder.newFolder()));
ignoreFilter = new EnforceIssuesFilter(exclusionPatternInitializer, analysisWarnings, activeRules);
assertThat(ignoreFilter.accept(issue, chain)).isFalse();
verifyNoInteractions(chain, analysisWarnings);
}
Aggregations