Search in sources :

Example 11 with TrackedIssue

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

the class ConsoleReportTest method createIssue.

private TrackedIssue createIssue(boolean isNew, @Nullable String severity) {
    TrackedIssue issue = new TrackedIssue();
    issue.setNew(isNew);
    issue.setSeverity(severity);
    return issue;
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue)

Example 12 with TrackedIssue

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

the class JSONReportTest method should_exclude_resolved_issues.

@Test
public void should_exclude_resolved_issues() throws Exception {
    RuleKey ruleKey = RuleKey.of("squid", "AvoidCycles");
    TrackedIssue issue = new TrackedIssue();
    issue.setKey("200");
    issue.setComponentKey("struts:src/main/java/org/apache/struts/Action.java");
    issue.setRuleKey(ruleKey);
    issue.setStatus(Issue.STATUS_CLOSED);
    issue.setResolution(Issue.RESOLUTION_FIXED);
    issue.setCreationDate(SIMPLE_DATE_FORMAT.parse("2013-04-24"));
    issue.setNew(false);
    when(issueCache.all()).thenReturn(Collections.singleton(issue));
    StringWriter writer = new StringWriter();
    jsonReport.writeJson(writer);
    assertThatJson(writer.toString()).isEqualTo(IOUtils.toString(this.getClass().getResource(this.getClass().getSimpleName() + "/report-without-resolved-issues.json")));
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) StringWriter(java.io.StringWriter) RuleKey(org.sonar.api.rule.RuleKey) Test(org.junit.Test)

Example 13 with TrackedIssue

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

the class JSONReportTest method should_write_json.

@Test
public void should_write_json() throws Exception {
    TrackedIssue issue = new TrackedIssue();
    issue.setKey("200");
    issue.setComponentKey("struts:src/main/java/org/apache/struts/Action.java");
    issue.setRuleKey(RuleKey.of("squid", "AvoidCycles"));
    issue.setMessage("There are 2 cycles");
    issue.setSeverity("MINOR");
    issue.setStatus(Issue.STATUS_OPEN);
    issue.setResolution(null);
    issue.setStartLine(1);
    issue.setEndLine(2);
    issue.setStartLineOffset(3);
    issue.setEndLineOffset(4);
    issue.setGap(3.14);
    issue.setAssignee("simon");
    issue.setCreationDate(SIMPLE_DATE_FORMAT.parse("2013-04-24"));
    issue.setNew(false);
    when(issueCache.all()).thenReturn(Collections.singleton(issue));
    ScannerInput.User user = ScannerInput.User.newBuilder().setLogin("simon").setName("Simon").build();
    when(userRepository.load(Collections.singleton("simon"))).thenReturn(Collections.singleton(user));
    StringWriter writer = new StringWriter();
    jsonReport.writeJson(writer);
    assertThatJson(writer.toString()).isEqualTo(IOUtils.toString(this.getClass().getResource(this.getClass().getSimpleName() + "/report.json")));
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) ScannerInput(org.sonar.scanner.protocol.input.ScannerInput) StringWriter(java.io.StringWriter) Test(org.junit.Test)

Example 14 with TrackedIssue

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

the class TaskResult method scanTaskCompleted.

@Override
public void scanTaskCompleted(ProjectScanContainer container) {
    LOG.info("Store analysis results in memory for later assertions in medium test");
    for (TrackedIssue issue : container.getComponentByType(IssueCache.class).all()) {
        issues.add(issue);
    }
    ReportPublisher reportPublisher = container.getComponentByType(ReportPublisher.class);
    reader = new ScannerReportReader(reportPublisher.getReportDir());
    if (!container.getComponentByType(AnalysisMode.class).isIssues()) {
        Metadata readMetadata = getReportReader().readMetadata();
        int rootComponentRef = readMetadata.getRootComponentRef();
        storeReportComponents(rootComponentRef, null, readMetadata.getBranch());
    }
    storeFs(container);
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) ReportPublisher(org.sonar.scanner.report.ReportPublisher) ScannerReportReader(org.sonar.scanner.protocol.output.ScannerReportReader) Metadata(org.sonar.scanner.protocol.output.ScannerReport.Metadata) IssueCache(org.sonar.scanner.issue.IssueCache)

Example 15 with TrackedIssue

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

the class IssuesReportBuilder method processIssues.

private void processIssues(IssuesReport issuesReport, Iterable<TrackedIssue> issues) {
    for (TrackedIssue issue : issues) {
        Rule rule = findRule(issue);
        RulePriority severity = RulePriority.valueOf(issue.severity());
        InputComponent resource = inputComponentStore.getByKey(issue.componentKey());
        if (!validate(issue, rule, resource)) {
            continue;
        }
        if (issue.resolution() != null) {
            issuesReport.addResolvedIssueOnResource(resource, rule, severity);
        } else {
            issuesReport.addIssueOnResource(resource, issue, rule, severity);
        }
    }
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) InputComponent(org.sonar.api.batch.fs.InputComponent) Rule(org.sonar.api.batch.rule.Rule) RulePriority(org.sonar.api.rules.RulePriority)

Aggregations

TrackedIssue (org.sonar.scanner.issue.tracking.TrackedIssue)25 Test (org.junit.Test)12 Date (java.util.Date)3 RuleKey (org.sonar.api.rule.RuleKey)3 AbstractCachesTest (org.sonar.scanner.index.AbstractCachesTest)3 File (java.io.File)2 StringWriter (java.io.StringWriter)2 InputComponent (org.sonar.api.batch.fs.InputComponent)2 Rule (org.sonar.api.batch.rule.Rule)2 Issue (org.sonar.api.issue.Issue)2 TaskResult (org.sonar.scanner.mediumtest.TaskResult)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Before (org.junit.Before)1 InputPath (org.sonar.api.batch.fs.InputPath)1 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 PostJobIssue (org.sonar.api.batch.postjob.issue.PostJobIssue)1 RulePriority (org.sonar.api.rules.RulePriority)1 IssueListener (org.sonar.batch.bootstrapper.IssueListener)1 DefaultIssue (org.sonar.core.issue.DefaultIssue)1 IssueCache (org.sonar.scanner.issue.IssueCache)1