Search in sources :

Example 1 with ExternalIssue

use of org.sonar.api.batch.sensor.issue.ExternalIssue in project sonarqube by SonarSource.

the class ExternalIssueImporterTest method import_issue_with_complete_primary_location.

@Test
public void import_issue_with_complete_primary_location() {
    ReportParser.TextRange input = new ReportParser.TextRange();
    input.startLine = 1;
    input.startColumn = 4;
    input.endLine = 2;
    input.endColumn = 3;
    runOn(newIssue(input));
    assertThat(context.allExternalIssues()).hasSize(1);
    ExternalIssue output = context.allExternalIssues().iterator().next();
    assertSameRange(input, output.primaryLocation().textRange());
}
Also used : ExternalIssue(org.sonar.api.batch.sensor.issue.ExternalIssue) TextRange(org.sonar.api.batch.fs.TextRange) Test(org.junit.Test)

Example 2 with ExternalIssue

use of org.sonar.api.batch.sensor.issue.ExternalIssue in project sonarqube by SonarSource.

the class DefaultSensorStorageTest method should_save_external_issue.

@Test
public void should_save_external_issue() {
    InputFile file = new TestInputFileBuilder("foo", "src/Foo.php").build();
    DefaultExternalIssue externalIssue = new DefaultExternalIssue(project).at(new DefaultIssueLocation().on(file));
    underTest.store(externalIssue);
    ArgumentCaptor<ExternalIssue> argumentCaptor = ArgumentCaptor.forClass(ExternalIssue.class);
    verify(moduleIssues).initAndAddExternalIssue(argumentCaptor.capture());
    assertThat(argumentCaptor.getValue()).isEqualTo(externalIssue);
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) DefaultExternalIssue(org.sonar.api.batch.sensor.issue.internal.DefaultExternalIssue) ExternalIssue(org.sonar.api.batch.sensor.issue.ExternalIssue) DefaultIssueLocation(org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation) DefaultExternalIssue(org.sonar.api.batch.sensor.issue.internal.DefaultExternalIssue) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Test(org.junit.Test)

Example 3 with ExternalIssue

use of org.sonar.api.batch.sensor.issue.ExternalIssue in project sonarqube by SonarSource.

the class IssuePublisher method createReportExternalIssue.

private static ScannerReport.ExternalIssue createReportExternalIssue(ExternalIssue issue, int componentRef) {
    // primary location of an external issue must have a message
    String primaryMessage = issue.primaryLocation().message();
    Severity severity = Severity.valueOf(issue.severity().name());
    IssueType issueType = IssueType.valueOf(issue.type().name());
    ScannerReport.ExternalIssue.Builder builder = ScannerReport.ExternalIssue.newBuilder();
    ScannerReport.IssueLocation.Builder locationBuilder = IssueLocation.newBuilder();
    ScannerReport.TextRange.Builder textRangeBuilder = ScannerReport.TextRange.newBuilder();
    // non-null fields
    builder.setSeverity(severity);
    builder.setType(issueType);
    builder.setEngineId(issue.engineId());
    builder.setRuleId(issue.ruleId());
    builder.setMsg(primaryMessage);
    locationBuilder.setMsg(primaryMessage);
    locationBuilder.setComponentRef(componentRef);
    TextRange primaryTextRange = issue.primaryLocation().textRange();
    if (primaryTextRange != null) {
        builder.setTextRange(toProtobufTextRange(textRangeBuilder, primaryTextRange));
    }
    Long effort = issue.remediationEffort();
    if (effort != null) {
        builder.setEffort(effort);
    }
    applyFlows(builder::addFlow, locationBuilder, textRangeBuilder, issue.flows());
    return builder.build();
}
Also used : ExternalIssue(org.sonar.api.batch.sensor.issue.ExternalIssue) IssueType(org.sonar.scanner.protocol.output.ScannerReport.IssueType) Severity(org.sonar.scanner.protocol.Constants.Severity) TextRange(org.sonar.api.batch.fs.TextRange) IssueLocation(org.sonar.scanner.protocol.output.ScannerReport.IssueLocation)

Example 4 with ExternalIssue

use of org.sonar.api.batch.sensor.issue.ExternalIssue in project sonarqube by SonarSource.

the class ExternalIssueImporterTest method import_issue_with_minimal_info.

@Test
public void import_issue_with_minimal_info() {
    ReportParser.Report report = new ReportParser.Report();
    ReportParser.Issue input = new ReportParser.Issue();
    input.engineId = "findbugs";
    input.ruleId = "123";
    input.severity = "CRITICAL";
    input.type = "BUG";
    input.primaryLocation = new ReportParser.Location();
    input.primaryLocation.filePath = sourceFile.getProjectRelativePath();
    input.primaryLocation.message = randomAlphabetic(5);
    report.issues = new ReportParser.Issue[] { input };
    ExternalIssueImporter underTest = new ExternalIssueImporter(this.context, report);
    underTest.execute();
    assertThat(context.allExternalIssues()).hasSize(1);
    ExternalIssue output = context.allExternalIssues().iterator().next();
    assertThat(output.engineId()).isEqualTo(input.engineId);
    assertThat(output.ruleId()).isEqualTo(input.ruleId);
    assertThat(output.severity()).isEqualTo(Severity.valueOf(input.severity));
    assertThat(output.remediationEffort()).isNull();
    assertThat(logs.logs(LoggerLevel.INFO)).contains("Imported 1 issue in 1 file");
}
Also used : ExternalIssue(org.sonar.api.batch.sensor.issue.ExternalIssue) ExternalIssue(org.sonar.api.batch.sensor.issue.ExternalIssue) Test(org.junit.Test)

Aggregations

ExternalIssue (org.sonar.api.batch.sensor.issue.ExternalIssue)4 Test (org.junit.Test)3 TextRange (org.sonar.api.batch.fs.TextRange)2 InputFile (org.sonar.api.batch.fs.InputFile)1 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)1 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 DefaultExternalIssue (org.sonar.api.batch.sensor.issue.internal.DefaultExternalIssue)1 DefaultIssueLocation (org.sonar.api.batch.sensor.issue.internal.DefaultIssueLocation)1 Severity (org.sonar.scanner.protocol.Constants.Severity)1 IssueLocation (org.sonar.scanner.protocol.output.ScannerReport.IssueLocation)1 IssueType (org.sonar.scanner.protocol.output.ScannerReport.IssueType)1