Search in sources :

Example 16 with IssuePattern

use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.

the class EnforceIssuesFilterTest method shouldAcceptIssueIfMatchesDeprecatedRuleKey.

@Test
public void shouldAcceptIssueIfMatchesDeprecatedRuleKey() {
    RuleKey ruleKey = RuleKey.of("repo", "rule");
    DefaultActiveRules activeRules = new DefaultActiveRules(ImmutableSet.of(new NewActiveRule.Builder().setRuleKey(ruleKey).setDeprecatedKeys(singleton(RuleKey.of("repo2", "deprecated"))).build()));
    String path = "org/sonar/api/Issue.java";
    when(issue.ruleKey()).thenReturn(ruleKey);
    IssuePattern matching = new IssuePattern("org/**", "repo2:deprecated");
    when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(ImmutableList.of(matching));
    when(issue.getComponent()).thenReturn(createComponentWithPath(path));
    ignoreFilter = new EnforceIssuesFilter(exclusionPatternInitializer, analysisWarnings, activeRules);
    assertThat(ignoreFilter.accept(issue, chain)).isTrue();
    verify(analysisWarnings).addUnique("A multicriteria issue enforce uses the rule key 'repo2:deprecated' that has been changed. The pattern should be updated to 'repo:rule'");
    verifyNoInteractions(chain);
}
Also used : DefaultActiveRules(org.sonar.api.batch.rule.internal.DefaultActiveRules) NewActiveRule(org.sonar.api.batch.rule.internal.NewActiveRule) RuleKey(org.sonar.api.rule.RuleKey) IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) Test(org.junit.Test)

Example 17 with IssuePattern

use of org.sonar.scanner.issue.ignore.pattern.IssuePattern in project sonarqube by SonarSource.

the class IssueExclusionsLoaderTest method populateRuleExclusionPatterns.

@Test
public void populateRuleExclusionPatterns() {
    IssuePattern pattern1 = new IssuePattern("org/foo/Bar*.java", "*");
    IssuePattern pattern2 = new IssuePattern("org/foo/Hell?.java", "checkstyle:MagicNumber");
    when(exclusionPatternInitializer.getMulticriteriaPatterns()).thenReturn(Arrays.asList(pattern1, pattern2));
    IssueExclusionsLoader loader = new IssueExclusionsLoader(exclusionPatternInitializer, ignoreIssuesFilter, mock(AnalysisWarnings.class));
    DefaultInputFile file1 = TestInputFileBuilder.create("foo", "org/foo/Bar.java").build();
    loader.addMulticriteriaPatterns(file1);
    DefaultInputFile file2 = TestInputFileBuilder.create("foo", "org/foo/Baz.java").build();
    loader.addMulticriteriaPatterns(file2);
    DefaultInputFile file3 = TestInputFileBuilder.create("foo", "org/foo/Hello.java").build();
    loader.addMulticriteriaPatterns(file3);
    verify(ignoreIssuesFilter).addRuleExclusionPatternForComponent(file1, pattern1.getRulePattern());
    verify(ignoreIssuesFilter).addRuleExclusionPatternForComponent(file3, pattern2.getRulePattern());
    verifyNoMoreInteractions(ignoreIssuesFilter);
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) AnalysisWarnings(org.sonar.api.notifications.AnalysisWarnings) Test(org.junit.Test)

Aggregations

IssuePattern (org.sonar.scanner.issue.ignore.pattern.IssuePattern)17 Test (org.junit.Test)16 RuleKey (org.sonar.api.rule.RuleKey)6 DefaultActiveRules (org.sonar.api.batch.rule.internal.DefaultActiveRules)5 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)2 InputComponent (org.sonar.api.batch.fs.InputComponent)1 NewActiveRule (org.sonar.api.batch.rule.internal.NewActiveRule)1 AnalysisWarnings (org.sonar.api.notifications.AnalysisWarnings)1 WildcardPattern (org.sonar.api.utils.WildcardPattern)1 DefaultFilterableIssue (org.sonar.scanner.issue.DefaultFilterableIssue)1 LineRange (org.sonar.scanner.issue.ignore.pattern.LineRange)1