コード例 #1
0
  @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);
  }
コード例 #2
0
ファイル: CoverageExclusions.java プロジェクト: ihr/sonarqube
 @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);
 }
コード例 #3
0
 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);
 }
コード例 #4
0
  @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);
  }
コード例 #5
0
 @Override
 public boolean matchFilePattern(String antPattern) {
   String patternWithoutFileSuffix = StringUtils.substringBeforeLast(antPattern, ".");
   WildcardPattern matcher = WildcardPattern.create(patternWithoutFileSuffix, ".");
   return matcher.match(getKey());
 }
コード例 #6
0
 public boolean accept(File paramFile) {
   String absolutePath = paramFile.getAbsolutePath();
   final String path = absolutePath;
   return pattern.match(convertSlash(path));
 }
コード例 #7
0
ファイル: PatternUtils.java プロジェクト: Zidanela/sonar-git
 public static WildcardPattern[] createPatterns(String patterns) {
   return WildcardPattern.create(StringUtils.split(StringUtils.replace(patterns, ".", "/"), ','));
 }