diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2018-08-10 11:12:01 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2018-09-19 10:51:38 +0200 |
commit | 269c963c54bd2234bc52ec3a30ba73ebd30b44ed (patch) | |
tree | 7f5c665a962844d3a086f02344a6e9d6dd70a7d2 /sonar-scanner-protocol | |
parent | 85389bab1cf38732a4436e18b58073385b181fab (diff) | |
download | sonarqube-269c963c54bd2234bc52ec3a30ba73ebd30b44ed.tar.gz sonarqube-269c963c54bd2234bc52ec3a30ba73ebd30b44ed.zip |
SONAR-11135 SONAR-11136 Load changed lines from SCM plugins and write in the scanner report
Diffstat (limited to 'sonar-scanner-protocol')
4 files changed, 29 insertions, 1 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 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 @@ -137,6 +137,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(); |