From 269c963c54bd2234bc52ec3a30ba73ebd30b44ed Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Fri, 10 Aug 2018 11:12:01 +0200 Subject: SONAR-11135 SONAR-11136 Load changed lines from SCM plugins and write in the scanner report --- .../sonar/scanner/protocol/output/FileStructure.java | 3 ++- .../scanner/protocol/output/ScannerReportWriter.java | 6 ++++++ .../src/main/protobuf/scanner_report.proto | 4 ++++ .../protocol/output/ScannerReportWriterTest.java | 17 +++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) (limited to 'sonar-scanner-protocol') 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 44ae856a6c2..bab729b95b0 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 @@ -43,7 +43,8 @@ public class FileStructure { TESTS("tests-", Domain.PB), COVERAGE_DETAILS("coverage-details-", Domain.PB), SOURCE("source-", ".txt"), - SGNIFICANT_CODE("sgnificant-code-", Domain.PB); + SGNIFICANT_CODE("sgnificant-code-", Domain.PB), + CHANGED_LINES("changed-lines-", Domain.PB); private static final String PB = ".pb"; private final String filePrefix; 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 7df46f355cc..1ccb6876e88 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 @@ -94,6 +94,12 @@ public class ScannerReportWriter { return file; } + public File writeComponentChangedLines(int componentRef, ScannerReport.ChangedLines changedLines) { + File file = fileStructure.fileFor(FileStructure.Domain.CHANGED_LINES, componentRef); + Protobuf.write(changedLines, file); + return file; + } + public void appendComponentExternalIssue(int componentRef, ScannerReport.ExternalIssue issue) { File file = fileStructure.fileFor(FileStructure.Domain.EXTERNAL_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 8a1e78dde6a..ac4c89980b8 100644 --- a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto +++ b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto @@ -271,6 +271,10 @@ message LineSgnificantCode { int32 end_offset = 3; } +message ChangedLines { + repeated int32 line = 1; +} + 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 6d0223be28d..ffcd97aaa8f 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 @@ -136,6 +136,23 @@ public class ScannerReportWriterTest { } } + @Test + public void write_changed_lines() { + assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGED_LINES, 1)).isFalse(); + + ScannerReport.ChangedLines changedLines = ScannerReport.ChangedLines.newBuilder() + .addLine(1) + .addLine(3) + .build(); + underTest.writeComponentChangedLines(1, changedLines); + + assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGED_LINES, 1)).isTrue(); + File file = underTest.getFileStructure().fileFor(FileStructure.Domain.CHANGED_LINES, 1); + assertThat(file).exists().isFile(); + ScannerReport.ChangedLines loadedChangedLines = Protobuf.read(file, ScannerReport.ChangedLines.parser()); + assertThat(loadedChangedLines.getLineList()).containsExactly(1, 3); + } + @Test public void write_measures() { assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isFalse(); -- cgit v1.2.3