@Test
  public void shouldPassToChainIfRuleDoesNotMatch() {
    String rule = "rule";
    RuleKey ruleKey = mock(RuleKey.class);
    when(ruleKey.toString()).thenReturn(rule);
    when(issue.ruleKey()).thenReturn(ruleKey);

    IssuePattern matching = mock(IssuePattern.class);
    WildcardPattern rulePattern = mock(WildcardPattern.class);
    when(matching.getRulePattern()).thenReturn(rulePattern);
    when(rulePattern.match(rule)).thenReturn(false);
    when(exclusionPatternInitializer.getMulticriteriaPatterns())
        .thenReturn(ImmutableList.of(matching));

    assertThat(ignoreFilter.accept(issue, chain)).isTrue();
    verify(chain).accept(issue);
  }
Example #2
0
 @VisibleForTesting
 final void initPatterns() {
   Builder<WildcardPattern> builder = ImmutableList.builder();
   for (String pattern :
       settings.getStringArray(CoreProperties.PROJECT_COVERAGE_EXCLUSIONS_PROPERTY)) {
     builder.add(WildcardPattern.create(pattern));
   }
   resourcePatterns = builder.build();
   log("Excluded sources for coverage: ", resourcePatterns);
 }
 public PatternFilter(File workDir, String pattern) {
   String absolutePathPattern = workDir.getAbsolutePath();
   if (!absolutePathPattern.endsWith("\\")) {
     // only if workDir is not
     // a folder on another drive (on windows systems)
     absolutePathPattern += "/";
   }
   absolutePathPattern += pattern;
   absolutePathPattern = convertSlash(absolutePathPattern);
   this.pattern = WildcardPattern.create(absolutePathPattern);
 }
  @Test
  public void shouldAcceptIssueIfFullyMatched() {
    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(true);
    when(exclusionPatternInitializer.getMulticriteriaPatterns())
        .thenReturn(ImmutableList.of(matching));
    when(exclusionPatternInitializer.getPathForComponent(componentKey)).thenReturn(path);

    assertThat(ignoreFilter.accept(issue, chain)).isTrue();
    verifyZeroInteractions(chain);
  }
 @Override
 public boolean matchFilePattern(String antPattern) {
   String patternWithoutFileSuffix = StringUtils.substringBeforeLast(antPattern, ".");
   WildcardPattern matcher = WildcardPattern.create(patternWithoutFileSuffix, ".");
   return matcher.match(getKey());
 }
 public boolean accept(File paramFile) {
   String absolutePath = paramFile.getAbsolutePath();
   final String path = absolutePath;
   return pattern.match(convertSlash(path));
 }
Example #7
0
 public static WildcardPattern[] createPatterns(String patterns) {
   return WildcardPattern.create(StringUtils.split(StringUtils.replace(patterns, ".", "/"), ','));
 }