diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2018-04-24 15:27:56 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-05-09 20:20:46 +0200 |
commit | fa4019b992510560be8c6d1b51bc2dc2f6b41546 (patch) | |
tree | 815cf6138b9e0b3a419c27cfe98e691080264af3 /sonar-scanner-protocol | |
parent | 09b3d167fa8f399e18a37d56e7c8cbb61f68f97f (diff) | |
download | sonarqube-fa4019b992510560be8c6d1b51bc2dc2f6b41546.tar.gz sonarqube-fa4019b992510560be8c6d1b51bc2dc2f6b41546.zip |
SONAR-10638 Create Java API for analyzers to report significant code
Diffstat (limited to 'sonar-scanner-protocol')
4 files changed, 30 insertions, 2 deletions
diff --git a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/FileStructure.java b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/FileStructure.java index 019e64d169d..44ae856a6c2 100644 --- a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/FileStructure.java +++ b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/FileStructure.java @@ -42,7 +42,8 @@ public class FileStructure { COVERAGES("coverages-", Domain.PB), TESTS("tests-", Domain.PB), COVERAGE_DETAILS("coverage-details-", Domain.PB), - SOURCE("source-", ".txt"); + SOURCE("source-", ".txt"), + SGNIFICANT_CODE("sgnificant-code-", Domain.PB); private static final String PB = ".pb"; private final String filePrefix; @@ -82,7 +83,7 @@ public class FileStructure { public File contextProperties() { return new File(dir, "context-props.pb"); } - + public File root() { return dir; } diff --git a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java index ebb6fe925e2..7df46f355cc 100644 --- a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java +++ b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java @@ -73,6 +73,12 @@ public class ScannerReportWriter { return file; } + public File writeComponentSignificantCode(int componentRef, Iterable<ScannerReport.LineSgnificantCode> lineSignificantCode) { + File file = fileStructure.fileFor(FileStructure.Domain.SGNIFICANT_CODE, componentRef); + Protobuf.writeStream(lineSignificantCode, file, false); + return file; + } + public void appendComponentIssue(int componentRef, ScannerReport.Issue issue) { File file = fileStructure.fileFor(FileStructure.Domain.ISSUES, componentRef); try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file, true))) { diff --git a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto index 922adca6f57..66930fb3a69 100644 --- a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto +++ b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto @@ -263,6 +263,12 @@ message TextRange { int32 end_offset = 4; } +message LineSgnificantCode { + int32 line = 1; + int32 start_offset = 2; + int32 end_offset = 3; +} + message Symbol { TextRange declaration = 1; repeated TextRange reference = 2; diff --git a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java index f4ee4dc3ed3..6d0223be28d 100644 --- a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java +++ b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportWriterTest.java @@ -284,6 +284,21 @@ public class ScannerReportWriterTest { } @Test + public void write_line_significant_code() { + // no data yet + assertThat(underTest.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, 1)).isFalse(); + + underTest.writeComponentSignificantCode(1, asList( + ScannerReport.LineSgnificantCode.newBuilder() + .setLine(1) + .setStartOffset(2) + .setEndOffset(3) + .build())); + + assertThat(underTest.hasComponentData(FileStructure.Domain.SGNIFICANT_CODE, 1)).isTrue(); + } + + @Test public void write_coverage() { // no data yet assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGES, 1)).isFalse(); |