use of org.sonar.api.utils.WildcardPattern in project sonarqube by SonarSource.
the class IgnoreIssuesFilter method hasRuleMatchFor.
private boolean hasRuleMatchFor(InputComponent component, FilterableIssue issue) {
for (WildcardPattern pattern : rulePatternByComponent.getOrDefault(component, Collections.emptyList())) {
if (pattern.match(issue.ruleKey().toString())) {
LOG.debug("Issue '{}' ignored by exclusion pattern '{}'", issue, pattern);
return true;
}
RuleKey ruleKey = issue.ruleKey();
if (activeRules.matchesDeprecatedKeys(ruleKey, pattern)) {
String msg = String.format("A multicriteria issue exclusion uses the rule key '%s' that has been changed. The pattern should be updated to '%s'", pattern, ruleKey);
analysisWarnings.addUnique(msg);
if (warnedDeprecatedRuleKeys.add(ruleKey)) {
LOG.warn(msg);
}
LOG.debug("Issue '{}' ignored by exclusion pattern '{}' matching a deprecated rule key", issue, pattern);
return true;
}
}
return false;
}
use of org.sonar.api.utils.WildcardPattern in project sonarqube by SonarSource.
the class EnforceIssuesFilterTest method shouldRefuseIssueIfRuleMatchesAndPathUnknown.
@Test
public void shouldRefuseIssueIfRuleMatchesAndPathUnknown() {
String rule = "rule";
String path = "org/sonar/api/Issue.java";
String componentKey = "org.sonar.api.Issue";
RuleKey ruleKey = mock(RuleKey.class);
when(ruleKey.toString()).thenReturn(rule);
when(issue.ruleKey()).thenReturn(ruleKey);
when(issue.componentKey()).thenReturn(componentKey);
IssuePattern matching = mock(IssuePattern.class);
WildcardPattern rulePattern = mock(WildcardPattern.class);
when(matching.getRulePattern()).thenReturn(rulePattern);
when(rulePattern.match(rule)).thenReturn(true);
WildcardPattern pathPattern = mock(WildcardPattern.class);
when(matching.getResourcePattern()).thenReturn(pathPattern);
when(pathPattern.match(path)).thenReturn(false);
when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
when(exclusionPatternInitializer.getPathForComponent(componentKey)).thenReturn(null);
assertThat(ignoreFilter.accept(issue, chain)).isFalse();
verifyZeroInteractions(chain);
}
use of org.sonar.api.utils.WildcardPattern in project sonarqube by SonarSource.
the class IgnoreIssuesFilterTest method shouldRejectIfRulePatternMatches.
@Test
public void shouldRejectIfRulePatternMatches() {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
IgnoreIssuesFilter underTest = new IgnoreIssuesFilter(activeRules, analysisWarnings);
WildcardPattern pattern = mock(WildcardPattern.class);
when(pattern.match(ruleKey.toString())).thenReturn(true);
underTest.addRuleExclusionPatternForComponent(component, pattern);
assertThat(underTest.accept(issue, chain)).isFalse();
verifyNoInteractions(analysisWarnings);
}
use of org.sonar.api.utils.WildcardPattern in project sonarqube by SonarSource.
the class IgnoreIssuesFilterTest method shouldAcceptIfRulePatternDoesNotMatch.
@Test
public void shouldAcceptIfRulePatternDoesNotMatch() {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of());
IgnoreIssuesFilter underTest = new IgnoreIssuesFilter(activeRules, analysisWarnings);
WildcardPattern pattern = mock(WildcardPattern.class);
when(pattern.match(ruleKey.toString())).thenReturn(false);
underTest.addRuleExclusionPatternForComponent(component, pattern);
assertThat(underTest.accept(issue, chain)).isFalse();
}
use of org.sonar.api.utils.WildcardPattern in project sonarqube by SonarSource.
the class IgnoreIssuesFilterTest method shouldRejectIfRulePatternMatchesDeprecatedRule.
@Test
public void shouldRejectIfRulePatternMatchesDeprecatedRule() {
DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of(new NewActiveRule.Builder().setRuleKey(ruleKey).setDeprecatedKeys(singleton(RuleKey.of("repo", "rule"))).build()));
IgnoreIssuesFilter underTest = new IgnoreIssuesFilter(activeRules, analysisWarnings);
WildcardPattern pattern = WildcardPattern.create("repo:rule");
underTest.addRuleExclusionPatternForComponent(component, pattern);
assertThat(underTest.accept(issue, chain)).isFalse();
verify(analysisWarnings).addUnique("A multicriteria issue exclusion uses the rule key 'repo:rule' that has been changed. The pattern should be updated to 'foo:bar'");
assertThat(logTester.logs()).contains("A multicriteria issue exclusion uses the rule key 'repo:rule' that has been changed. The pattern should be updated to 'foo:bar'");
}
Aggregations