Search in sources :

Example 1 with DefaultFilterableIssue

use of org.sonar.scanner.issue.DefaultFilterableIssue in project sonarqube by SonarSource.

the class DefaultFilterableIssueTest method testRoundTrip.

@Test
public void testRoundTrip() {
    rawIssue = createIssue();
    issue = new DefaultFilterableIssue(mockedProject, projectAnalysisInfo, rawIssue, componentKey);
    when(projectAnalysisInfo.analysisDate()).thenReturn(new Date(10_000));
    when(mockedProject.key()).thenReturn("projectKey");
    assertThat(issue.componentKey()).isEqualTo(componentKey);
    assertThat(issue.creationDate()).isEqualTo(new Date(10_000));
    assertThat(issue.line()).isEqualTo(30);
    assertThat(issue.projectKey()).isEqualTo("projectKey");
    assertThat(issue.effortToFix()).isEqualTo(3.0);
    assertThat(issue.severity()).isEqualTo("MAJOR");
}
Also used : Date(java.util.Date) DefaultFilterableIssue(org.sonar.scanner.issue.DefaultFilterableIssue) Test(org.junit.Test)

Example 2 with DefaultFilterableIssue

use of org.sonar.scanner.issue.DefaultFilterableIssue in project sonarqube by SonarSource.

the class DefaultFilterableIssueTest method nullValues.

@Test
public void nullValues() {
    rawIssue = createIssueWithoutFields();
    issue = new DefaultFilterableIssue(mockedProject, projectAnalysisInfo, rawIssue, componentKey);
    assertThat(issue.line()).isNull();
    assertThat(issue.effortToFix()).isNull();
}
Also used : DefaultFilterableIssue(org.sonar.scanner.issue.DefaultFilterableIssue) Test(org.junit.Test)

Example 3 with DefaultFilterableIssue

use of org.sonar.scanner.issue.DefaultFilterableIssue 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);
    }
}
Also used : InputComponent(org.sonar.api.batch.fs.InputComponent) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) IssuePattern(org.sonar.scanner.issue.ignore.pattern.IssuePattern) DefaultFilterableIssue(org.sonar.scanner.issue.DefaultFilterableIssue)

Aggregations

DefaultFilterableIssue (org.sonar.scanner.issue.DefaultFilterableIssue)3 Test (org.junit.Test)2 Date (java.util.Date)1 InputComponent (org.sonar.api.batch.fs.InputComponent)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 IssuePattern (org.sonar.scanner.issue.ignore.pattern.IssuePattern)1