diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2016-03-22 10:06:28 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2016-03-23 20:31:30 +0100 |
commit | f4354c32ebc7ac46ea261c81ed791f065e080c02 (patch) | |
tree | 8bb36abf2653e768712402b840968615a35cabcc /sonar-scanner-protocol | |
parent | f7422cae1cda99e1b81aa92695c73ef5398bc5ce (diff) | |
download | sonarqube-f4354c32ebc7ac46ea261c81ed791f065e080c02.tar.gz sonarqube-f4354c32ebc7ac46ea261c81ed791f065e080c02.zip |
Update scanner report to protobuf 3 (imply SONAR-7497)
Diffstat (limited to 'sonar-scanner-protocol')
7 files changed, 203 insertions, 201 deletions
diff --git a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportReader.java b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportReader.java index d47b94225ef..5cb0d7b8bf2 100644 --- a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportReader.java +++ b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportReader.java @@ -39,7 +39,7 @@ public class ScannerReportReader { if (!fileExists(file)) { throw new IllegalStateException("Metadata file is missing in analysis report: " + file); } - return Protobuf.read(file, ScannerReport.Metadata.PARSER); + return Protobuf.read(file, ScannerReport.Metadata.parser()); } public CloseableIterator<ScannerReport.ActiveRule> readActiveRules() { @@ -47,13 +47,13 @@ public class ScannerReportReader { if (!fileExists(file)) { return emptyCloseableIterator(); } - return Protobuf.readStream(file, ScannerReport.ActiveRule.PARSER); + return Protobuf.readStream(file, ScannerReport.ActiveRule.parser()); } public CloseableIterator<ScannerReport.Measure> readComponentMeasures(int componentRef) { File file = fileStructure.fileFor(FileStructure.Domain.MEASURES, componentRef); if (fileExists(file)) { - return Protobuf.readStream(file, ScannerReport.Measure.PARSER); + return Protobuf.readStream(file, ScannerReport.Measure.parser()); } return emptyCloseableIterator(); } @@ -62,7 +62,7 @@ public class ScannerReportReader { public ScannerReport.Changesets readChangesets(int componentRef) { File file = fileStructure.fileFor(FileStructure.Domain.CHANGESETS, componentRef); if (fileExists(file)) { - return Protobuf.read(file, ScannerReport.Changesets.PARSER); + return Protobuf.read(file, ScannerReport.Changesets.parser()); } return null; } @@ -72,13 +72,13 @@ public class ScannerReportReader { if (!fileExists(file)) { throw new IllegalStateException("Unable to find report for component #" + componentRef + ". File does not exist: " + file); } - return Protobuf.read(file, ScannerReport.Component.PARSER); + return Protobuf.read(file, ScannerReport.Component.parser()); } public CloseableIterator<ScannerReport.Issue> readComponentIssues(int componentRef) { File file = fileStructure.fileFor(FileStructure.Domain.ISSUES, componentRef); if (fileExists(file)) { - return Protobuf.readStream(file, ScannerReport.Issue.PARSER); + return Protobuf.readStream(file, ScannerReport.Issue.parser()); } return emptyCloseableIterator(); } @@ -86,7 +86,7 @@ public class ScannerReportReader { public CloseableIterator<ScannerReport.Duplication> readComponentDuplications(int componentRef) { File file = fileStructure.fileFor(FileStructure.Domain.DUPLICATIONS, componentRef); if (fileExists(file)) { - return Protobuf.readStream(file, ScannerReport.Duplication.PARSER); + return Protobuf.readStream(file, ScannerReport.Duplication.parser()); } return emptyCloseableIterator(); } @@ -102,7 +102,7 @@ public class ScannerReportReader { public CloseableIterator<ScannerReport.Symbol> readComponentSymbols(int componentRef) { File file = fileStructure.fileFor(FileStructure.Domain.SYMBOLS, componentRef); if (fileExists(file)) { - return Protobuf.readStream(file, ScannerReport.Symbol.PARSER); + return Protobuf.readStream(file, ScannerReport.Symbol.parser()); } return emptyCloseableIterator(); } @@ -112,10 +112,10 @@ public class ScannerReportReader { return file.exists(); } - public CloseableIterator<ScannerReport.SyntaxHighlighting> readComponentSyntaxHighlighting(int fileRef) { + public CloseableIterator<ScannerReport.SyntaxHighlightingRule> readComponentSyntaxHighlighting(int fileRef) { File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, fileRef); if (fileExists(file)) { - return Protobuf.readStream(file, ScannerReport.SyntaxHighlighting.PARSER); + return Protobuf.readStream(file, ScannerReport.SyntaxHighlightingRule.parser()); } return emptyCloseableIterator(); } @@ -125,10 +125,10 @@ public class ScannerReportReader { return file.exists(); } - public CloseableIterator<ScannerReport.Coverage> readComponentCoverage(int fileRef) { + public CloseableIterator<ScannerReport.LineCoverage> readComponentCoverage(int fileRef) { File file = fileStructure.fileFor(FileStructure.Domain.COVERAGES, fileRef); if (fileExists(file)) { - return Protobuf.readStream(file, ScannerReport.Coverage.PARSER); + return Protobuf.readStream(file, ScannerReport.LineCoverage.parser()); } return emptyCloseableIterator(); } 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 5cbba578c2a..b2da5ba4b56 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 @@ -110,13 +110,13 @@ public class ScannerReportWriter { return file; } - public File writeComponentSyntaxHighlighting(int componentRef, Iterable<ScannerReport.SyntaxHighlighting> syntaxHighlightingRules) { + public File writeComponentSyntaxHighlighting(int componentRef, Iterable<ScannerReport.SyntaxHighlightingRule> syntaxHighlightingRules) { File file = fileStructure.fileFor(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, componentRef); Protobuf.writeStream(syntaxHighlightingRules, file, false); return file; } - public File writeComponentCoverage(int componentRef, Iterable<ScannerReport.Coverage> coverageList) { + public File writeComponentCoverage(int componentRef, Iterable<ScannerReport.LineCoverage> coverageList) { File file = fileStructure.fileFor(FileStructure.Domain.COVERAGES, componentRef); Protobuf.writeStream(coverageList, file, false); return file; diff --git a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/viewer/ScannerReportViewerApp.java b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/viewer/ScannerReportViewerApp.java index 3768c1ca0d2..70ea5f477c9 100644 --- a/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/viewer/ScannerReportViewerApp.java +++ b/sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/viewer/ScannerReportViewerApp.java @@ -47,12 +47,13 @@ import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeSelectionModel; +import org.apache.commons.lang.StringUtils; import org.sonar.core.util.CloseableIterator; -import org.sonar.scanner.protocol.output.ScannerReportReader; import org.sonar.scanner.protocol.output.FileStructure.Domain; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.protocol.output.ScannerReport.Component; import org.sonar.scanner.protocol.output.ScannerReport.Metadata; +import org.sonar.scanner.protocol.output.ScannerReportReader; public class ScannerReportViewerApp { @@ -179,7 +180,8 @@ public class ScannerReportViewerApp { } private void updateTitle() { - frame.setTitle(metadata.getProjectKey() + (metadata.hasBranch() ? (" (" + metadata.getBranch() + ")") : "") + " " + sdf.format(new Date(metadata.getAnalysisDate()))); + frame.setTitle(metadata.getProjectKey() + (StringUtils.isNotEmpty(metadata.getBranch()) ? (" (" + metadata.getBranch() + ")") : "") + " " + + sdf.format(new Date(metadata.getAnalysisDate()))); } private void updateDetails(Component component) { @@ -207,9 +209,9 @@ public class ScannerReportViewerApp { private void updateCoverage(Component component) { coverageEditor.setText(""); - try (CloseableIterator<ScannerReport.Coverage> it = reader.readComponentCoverage(component.getRef())) { + try (CloseableIterator<ScannerReport.LineCoverage> it = reader.readComponentCoverage(component.getRef())) { while (it.hasNext()) { - ScannerReport.Coverage coverage = it.next(); + ScannerReport.LineCoverage coverage = it.next(); coverageEditor.getDocument().insertString(coverageEditor.getDocument().getEndPosition().getOffset(), coverage.toString() + "\n", null); } } catch (Exception e) { @@ -236,9 +238,9 @@ public class ScannerReportViewerApp { private void updateHighlighting(Component component) { highlightingEditor.setText(""); - try (CloseableIterator<ScannerReport.SyntaxHighlighting> it = reader.readComponentSyntaxHighlighting(component.getRef())) { + try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = reader.readComponentSyntaxHighlighting(component.getRef())) { while (it.hasNext()) { - ScannerReport.SyntaxHighlighting rule = it.next(); + ScannerReport.SyntaxHighlightingRule rule = it.next(); highlightingEditor.getDocument().insertString(highlightingEditor.getDocument().getEndPosition().getOffset(), rule.toString() + "\n", null); } } catch (Exception e) { diff --git a/sonar-scanner-protocol/src/main/protobuf/constants.proto b/sonar-scanner-protocol/src/main/protobuf/constants.proto index 862b4afa54c..8be6a361a2d 100644 --- a/sonar-scanner-protocol/src/main/protobuf/constants.proto +++ b/sonar-scanner-protocol/src/main/protobuf/constants.proto @@ -16,64 +16,18 @@ // along with this program; if not, write to the Free Software Foundation, // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -syntax = "proto2"; +syntax = "proto3"; option java_package = "org.sonar.scanner.protocol"; option optimize_for = SPEED; enum Severity { - INFO = 0; - MINOR = 1; - MAJOR = 2; - CRITICAL = 3; - BLOCKER = 4; + UNSET_SEVERITY = 0; + INFO = 1; + MINOR = 2; + MAJOR = 3; + CRITICAL = 4; + BLOCKER = 5; } -enum ComponentType { - PROJECT = 0; - MODULE = 1; - DIRECTORY = 2; - FILE = 3; -} - -enum MeasureValueType { - INT = 0; - LONG = 1; - DOUBLE = 2; - BOOLEAN = 3; - STRING = 4; -} - -// temporary enum during development of computation stack -enum EventCategory { - ALERT = 0; - PROFILE = 1; -} - -enum ComponentLinkType { - HOME = 0; - SCM = 1; - SCM_DEV = 2; - ISSUE = 3; - CI = 4; -} - -enum HighlightingType { - ANNOTATION = 0; - CONSTANT = 1; - COMMENT = 2; - CPP_DOC = 3; - STRUCTURED_COMMENT = 4; - KEYWORD = 5; - HIGHLIGHTING_STRING = 6; - KEYWORD_LIGHT = 7; - PREPROCESS_DIRECTIVE = 8; -} - -enum TestStatus { - OK = 1; - FAILURE = 2; - ERROR = 3; - SKIPPED = 4; -} diff --git a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto index 3df7f4343a6..c7b4964f540 100644 --- a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto +++ b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto @@ -26,7 +26,7 @@ Notes not forward-compatible yet. */ -syntax = "proto2"; +syntax = "proto3"; import "constants.proto"; @@ -35,82 +35,116 @@ option java_package = "org.sonar.scanner.protocol.output"; option optimize_for = SPEED; message Metadata { - optional int64 analysis_date = 1; + int64 analysis_date = 1; // TODO should we keep this project_key here or not ? Because it's a duplication of Component.key - optional string project_key = 2; - optional string branch = 3; - optional int32 root_component_ref = 4; - optional bool cross_project_duplication_activated = 5; + string project_key = 2; + string branch = 3; + int32 root_component_ref = 4; + bool cross_project_duplication_activated = 5; } message ActiveRule { - optional string rule_repository = 1; - optional string rule_key = 2; - optional Severity severity = 3; - repeated ActiveRuleParam param = 4; - - // TODO replace by map - message ActiveRuleParam { - optional string key = 1; - optional string value = 2; - } + string rule_repository = 1; + string rule_key = 2; + Severity severity = 3; + map<string,string> params_by_key = 4; } message ComponentLink { - optional ComponentLinkType type = 1; - optional string href = 2; + ComponentLinkType type = 1; + string href = 2; + + enum ComponentLinkType { + UNSET = 0; + HOME = 1; + SCM = 2; + SCM_DEV = 3; + ISSUE = 4; + CI = 5; + } } message Component { - optional int32 ref = 1; - optional string path = 2; - optional string name = 3; - optional ComponentType type = 4; - optional bool is_test = 5; - optional string language = 6; + int32 ref = 1; + string path = 2; + string name = 3; + ComponentType type = 4; + bool is_test = 5; + string language = 6; repeated int32 child_ref = 7 [packed = true]; repeated ComponentLink link = 8; // Only available on PROJECT and MODULE types - optional string version = 9; + string version = 9; // Only available on PROJECT and MODULE types // TODO rename this property -> batchKey ? moduleKey ? - optional string key = 10; + string key = 10; // Only available on FILE type - optional int32 lines = 11; + int32 lines = 11; // Only available on PROJECT and MODULE types - optional string description = 12; + string description = 12; + + enum ComponentType { + UNSET = 0; + PROJECT = 1; + MODULE = 2; + DIRECTORY = 3; + FILE = 4; + } } message Measure { - optional MeasureValueType value_type = 1; - // all values may be unset for "new_xxx" measures (only variations are populated) - optional bool boolean_value = 2; - optional int32 int_value = 3; - optional int64 long_value = 4; - optional double double_value = 5; - optional string string_value = 6; - optional string metric_key = 7; + string metric_key = 1; + oneof value { + BoolValue boolean_value = 2; + IntValue int_value = 3; + LongValue long_value = 4; + DoubleValue double_value = 5; + StringValue string_value = 6; + } + + message BoolValue { + bool value = 1; + string data = 2; + } + + message IntValue { + int32 value = 1; + string data = 2; + } + + message LongValue { + int64 value = 1; + string data = 2; + } + + message DoubleValue { + double value = 1; + string data = 2; + } + + message StringValue { + string value = 1; + } } message Issue { - optional string rule_repository = 1; - optional string rule_key = 2; + string rule_repository = 1; + string rule_key = 2; // Only when issue component is a file. Can also be empty for a file if this is an issue global to the file. - //TODO To be removed. Use first line of text_range instead - optional int32 line = 3; - optional string msg = 4; - optional Severity severity = 5; - optional double gap = 6; + string msg = 3; + Severity severity = 4; + double gap = 5; // Only when issue component is a file. Can also be empty for a file if this is an issue global to the file. - optional TextRange text_range = 7; - repeated Flow flow = 8; + // Will be identical to the first location of the first flow + TextRange text_range = 6; + repeated Flow flow = 7; } message IssueLocation { - optional int32 component_ref = 1; + int32 component_ref = 1; // Only when component is a file. Can be empty for a file if this is an issue global to the file. - optional TextRange text_range = 2; - optional string msg = 3; + TextRange text_range = 2; + string msg = 3; } message Flow { @@ -118,96 +152,113 @@ message Flow { } message Changesets { - optional int32 component_ref = 1; + int32 component_ref = 1; repeated Changeset changeset = 2; // if changesetIndexByLine[5] = 2 then it means that changeset[2] is the last one on line 6 repeated int32 changesetIndexByLine = 3 [packed = true]; message Changeset { - optional string revision = 1; - optional string author = 2; - optional int64 date = 3; + string revision = 1; + string author = 2; + int64 date = 3; } } message Duplicate { - // Will be null when duplicate is in the same file - optional int32 other_file_ref = 1; - optional TextRange range = 2; + // Will be 0 when duplicate is in the same file + int32 other_file_ref = 1; + // Only start_line and end_line are provided since we dont support "precise" duplication location. + TextRange range = 2; } message Duplication { - // Origin position in current file - optional TextRange origin_position = 1; + // Origin position in current file. Only start_line and end_line are provided since we dont support "precise" duplication location. + TextRange origin_position = 1; repeated Duplicate duplicate = 2; } // Used for cross project duplication message CpdTextBlock { - optional string hash = 1; - optional int32 start_line = 2; - optional int32 end_line = 3; - optional int32 start_token_index = 4; - optional int32 end_token_index = 5; + string hash = 1; + int32 start_line = 2; + int32 end_line = 3; + int32 start_token_index = 4; + int32 end_token_index = 5; } // Lines start at 1 and line offsets start at 0 message TextRange { - // Should never be null - optional int32 start_line = 1; + int32 start_line = 1; // End line (inclusive) - optional int32 end_line = 2; - // If null it means range starts at the first offset of start line - optional int32 start_offset = 3; - // If null it means range ends at the last offset of end line - optional int32 end_offset = 4; + int32 end_line = 2; + int32 start_offset = 3; + int32 end_offset = 4; } message Symbol { - optional TextRange declaration = 1; + TextRange declaration = 1; repeated TextRange reference = 2; } // Only FILE component has coverage information, and only executable lines should contains this information. -// TODO rename it LineCoverage ? -message Coverage { - optional int32 line = 1; +message LineCoverage { + int32 line = 1; // Number of conditions to cover (if set, the value must be greater than 0) - optional int32 conditions = 2; + int32 conditions = 2; // Is the line has been touched by a unit test ? Returning false means that no test has touched this executable line. - optional bool ut_hits = 3; + bool ut_hits = 3; // Is the line has been touched by a integration test ? Returning false means that no test has touched this executable line. - optional bool it_hits = 4; + bool it_hits = 4; // Number of conditions covered by unit tests - optional int32 ut_covered_conditions = 5; + int32 ut_covered_conditions = 5; // Number of conditions covered by integration tests - optional int32 it_covered_conditions = 6; + int32 it_covered_conditions = 6; // Number of conditions covered by overall tests - optional int32 overall_covered_conditions = 7; + int32 overall_covered_conditions = 7; } // Must be sorted by line and start offset -// TODO rename it SyntaxHighlightingRule ? -message SyntaxHighlighting { - optional TextRange range = 1; - optional HighlightingType type = 2; +message SyntaxHighlightingRule { + TextRange range = 1; + HighlightingType type = 2; + + enum HighlightingType { + UNSET = 0; + ANNOTATION = 1; + CONSTANT = 2; + COMMENT = 3; + CPP_DOC = 4; + STRUCTURED_COMMENT = 5; + KEYWORD = 6; + HIGHLIGHTING_STRING = 7; + KEYWORD_LIGHT = 8; + PREPROCESS_DIRECTIVE = 9; + } } message Test { - optional string name = 1; - optional TestStatus status = 2; - optional int64 duration_in_ms = 3; - optional string stacktrace = 4; - optional string msg = 5; + string name = 1; + TestStatus status = 2; + int64 duration_in_ms = 3; + string stacktrace = 4; + string msg = 5; + + enum TestStatus { + UNSET = 0; + OK = 1; + FAILURE = 2; + ERROR = 3; + SKIPPED = 4; + } } message CoverageDetail { - optional string test_name = 1; + string test_name = 1; repeated CoveredFile covered_file = 2; message CoveredFile { - optional int32 file_ref = 1; + int32 file_ref = 1; repeated int32 covered_line = 2 [packed = true]; } } diff --git a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportReaderTest.java b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportReaderTest.java index ce2a6e86149..98b7c7ac71d 100644 --- a/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportReaderTest.java +++ b/sonar-scanner-protocol/src/test/java/org/sonar/scanner/protocol/output/ScannerReportReaderTest.java @@ -30,10 +30,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.core.util.CloseableIterator; -import org.sonar.scanner.protocol.Constants; -import org.sonar.scanner.protocol.output.ScannerReportReader; -import org.sonar.scanner.protocol.output.ScannerReportWriter; -import org.sonar.scanner.protocol.output.FileStructure; +import org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue; +import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType; +import org.sonar.scanner.protocol.output.ScannerReport.Test.TestStatus; import static java.util.Arrays.asList; import static java.util.Collections.singletonList; @@ -98,7 +97,6 @@ public class ScannerReportReaderTest { public void read_issues() { ScannerReportWriter writer = new ScannerReportWriter(dir); ScannerReport.Issue issue = ScannerReport.Issue.newBuilder() - .setLine(50) .build(); writer.writeComponentIssues(1, asList(issue)); @@ -115,7 +113,7 @@ public class ScannerReportReaderTest { public void read_measures() { ScannerReportWriter writer = new ScannerReportWriter(dir); ScannerReport.Measure.Builder measure = ScannerReport.Measure.newBuilder() - .setStringValue("value_a"); + .setStringValue(StringValue.newBuilder().setValue("value_a")); writer.writeComponentMeasures(1, asList(measure.build())); assertThat(underTest.readComponentMeasures(1)).hasSize(1); @@ -211,20 +209,20 @@ public class ScannerReportReaderTest { .setRef(1).build()); writer.writeComponentSyntaxHighlighting(1, asList( - ScannerReport.SyntaxHighlighting.newBuilder() + ScannerReport.SyntaxHighlightingRule.newBuilder() .setRange(ScannerReport.TextRange.newBuilder() .setStartLine(1) .setEndLine(10) .build()) - .setType(Constants.HighlightingType.ANNOTATION) + .setType(HighlightingType.ANNOTATION) .build())); - try (CloseableIterator<ScannerReport.SyntaxHighlighting> it = underTest.readComponentSyntaxHighlighting(1)) { - ScannerReport.SyntaxHighlighting syntaxHighlighting = it.next(); + try (CloseableIterator<ScannerReport.SyntaxHighlightingRule> it = underTest.readComponentSyntaxHighlighting(1)) { + ScannerReport.SyntaxHighlightingRule syntaxHighlighting = it.next(); assertThat(syntaxHighlighting.getRange()).isNotNull(); assertThat(syntaxHighlighting.getRange().getStartLine()).isEqualTo(1); assertThat(syntaxHighlighting.getRange().getEndLine()).isEqualTo(10); - assertThat(syntaxHighlighting.getType()).isEqualTo(Constants.HighlightingType.ANNOTATION); + assertThat(syntaxHighlighting.getType()).isEqualTo(HighlightingType.ANNOTATION); } } @@ -276,7 +274,7 @@ public class ScannerReportReaderTest { .setRef(1).build()); writer.writeComponentCoverage(1, asList( - ScannerReport.Coverage.newBuilder() + ScannerReport.LineCoverage.newBuilder() .setLine(1) .setConditions(1) .setUtHits(true) @@ -285,7 +283,7 @@ public class ScannerReportReaderTest { .setItCoveredConditions(1) .setOverallCoveredConditions(1) .build(), - ScannerReport.Coverage.newBuilder() + ScannerReport.LineCoverage.newBuilder() .setLine(2) .setConditions(5) .setUtHits(false) @@ -296,8 +294,8 @@ public class ScannerReportReaderTest { .build())); underTest = new ScannerReportReader(dir); - try (CloseableIterator<ScannerReport.Coverage> it = new ScannerReportReader(dir).readComponentCoverage(1)) { - ScannerReport.Coverage coverage = it.next(); + try (CloseableIterator<ScannerReport.LineCoverage> it = new ScannerReportReader(dir).readComponentCoverage(1)) { + ScannerReport.LineCoverage coverage = it.next(); assertThat(coverage.getLine()).isEqualTo(1); assertThat(coverage.getConditions()).isEqualTo(1); assertThat(coverage.getUtHits()).isTrue(); @@ -331,15 +329,15 @@ public class ScannerReportReaderTest { .setDurationInMs(60_000) .setStacktrace("stacktrace") .setMsg("message") - .setStatus(Constants.TestStatus.OK) + .setStatus(TestStatus.OK) .build())); try (InputStream inputStream = FileUtils.openInputStream(underTest.readTests(1))) { - ScannerReport.Test testResult = ScannerReport.Test.PARSER.parseDelimitedFrom(inputStream); + ScannerReport.Test testResult = ScannerReport.Test.parser().parseDelimitedFrom(inputStream); assertThat(testResult.getDurationInMs()).isEqualTo(60_000); assertThat(testResult.getStacktrace()).isEqualTo("stacktrace"); assertThat(testResult.getMsg()).isEqualTo("message"); - assertThat(testResult.getStatus()).isEqualTo(Constants.TestStatus.OK); + assertThat(testResult.getStatus()).isEqualTo(TestStatus.OK); } } @@ -360,7 +358,7 @@ public class ScannerReportReaderTest { .build())); try (InputStream inputStream = FileUtils.openInputStream(underTest.readCoverageDetails(1))) { - ScannerReport.CoverageDetail coverageDetail = ScannerReport.CoverageDetail.PARSER.parseDelimitedFrom(inputStream); + ScannerReport.CoverageDetail coverageDetail = ScannerReport.CoverageDetail.parser().parseDelimitedFrom(inputStream); assertThat(coverageDetail.getTestName()).isEqualTo("test-name"); assertThat(coverageDetail.getCoveredFile(0).getFileRef()).isEqualTo(2); assertThat(coverageDetail.getCoveredFile(0).getCoveredLineList()).containsExactly(1, 2, 3, 5, 7); 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 9a08cd726ac..c55abc01c9b 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 @@ -28,9 +28,9 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.sonar.core.util.CloseableIterator; import org.sonar.core.util.Protobuf; -import org.sonar.scanner.protocol.Constants; -import org.sonar.scanner.protocol.output.ScannerReportWriter; -import org.sonar.scanner.protocol.output.FileStructure; +import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType; +import org.sonar.scanner.protocol.output.ScannerReport.Measure.DoubleValue; +import org.sonar.scanner.protocol.output.ScannerReport.SyntaxHighlightingRule.HighlightingType; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; @@ -64,7 +64,7 @@ public class ScannerReportWriterTest { .setRootComponentRef(1); underTest.writeMetadata(metadata.build()); - ScannerReport.Metadata read = Protobuf.read(underTest.getFileStructure().metadataFile(), ScannerReport.Metadata.PARSER); + ScannerReport.Metadata read = Protobuf.read(underTest.getFileStructure().metadataFile(), ScannerReport.Metadata.parser()); assertThat(read.getAnalysisDate()).isEqualTo(15000000L); assertThat(read.getProjectKey()).isEqualTo("PROJECT_A"); assertThat(read.getRootComponentRef()).isEqualTo(1); @@ -80,7 +80,7 @@ public class ScannerReportWriterTest { .setRef(1) .setLanguage("java") .setPath("src/Foo.java") - .setType(Constants.ComponentType.FILE) + .setType(ComponentType.FILE) .setIsTest(false) .addChildRef(5) .addChildRef(42); @@ -89,10 +89,10 @@ public class ScannerReportWriterTest { assertThat(underTest.hasComponentData(FileStructure.Domain.COMPONENT, 1)).isTrue(); File file = underTest.getFileStructure().fileFor(FileStructure.Domain.COMPONENT, 1); assertThat(file).exists().isFile(); - ScannerReport.Component read = Protobuf.read(file, ScannerReport.Component.PARSER); + ScannerReport.Component read = Protobuf.read(file, ScannerReport.Component.parser()); assertThat(read.getRef()).isEqualTo(1); assertThat(read.getChildRefList()).containsOnly(5, 42); - assertThat(read.hasName()).isFalse(); + assertThat(read.getName()).isEmpty(); assertThat(read.getIsTest()).isFalse(); } @@ -103,7 +103,6 @@ public class ScannerReportWriterTest { // write data ScannerReport.Issue issue = ScannerReport.Issue.newBuilder() - .setLine(50) .setMsg("the message") .build(); @@ -112,7 +111,7 @@ public class ScannerReportWriterTest { assertThat(underTest.hasComponentData(FileStructure.Domain.ISSUES, 1)).isTrue(); File file = underTest.getFileStructure().fileFor(FileStructure.Domain.ISSUES, 1); assertThat(file).exists().isFile(); - try (CloseableIterator<ScannerReport.Issue> read = Protobuf.readStream(file, ScannerReport.Issue.PARSER)) { + try (CloseableIterator<ScannerReport.Issue> read = Protobuf.readStream(file, ScannerReport.Issue.parser())) { assertThat(Iterators.size(read)).isEqualTo(1); } } @@ -122,9 +121,7 @@ public class ScannerReportWriterTest { assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isFalse(); ScannerReport.Measure measure = ScannerReport.Measure.newBuilder() - .setStringValue("text-value") - .setDoubleValue(2.5d) - .setValueType(Constants.MeasureValueType.DOUBLE) + .setDoubleValue(DoubleValue.newBuilder().setValue(2.5d).setData("text-value")) .build(); underTest.writeComponentMeasures(1, asList(measure)); @@ -132,7 +129,7 @@ public class ScannerReportWriterTest { assertThat(underTest.hasComponentData(FileStructure.Domain.MEASURES, 1)).isTrue(); File file = underTest.getFileStructure().fileFor(FileStructure.Domain.MEASURES, 1); assertThat(file).exists().isFile(); - try (CloseableIterator<ScannerReport.Measure> read = Protobuf.readStream(file, ScannerReport.Measure.PARSER)) { + try (CloseableIterator<ScannerReport.Measure> read = Protobuf.readStream(file, ScannerReport.Measure.parser())) { assertThat(Iterators.size(read)).isEqualTo(1); } } @@ -155,7 +152,7 @@ public class ScannerReportWriterTest { assertThat(underTest.hasComponentData(FileStructure.Domain.CHANGESETS, 1)).isTrue(); File file = underTest.getFileStructure().fileFor(FileStructure.Domain.CHANGESETS, 1); assertThat(file).exists().isFile(); - ScannerReport.Changesets read = Protobuf.read(file, ScannerReport.Changesets.PARSER); + ScannerReport.Changesets read = Protobuf.read(file, ScannerReport.Changesets.parser()); assertThat(read.getComponentRef()).isEqualTo(1); assertThat(read.getChangesetCount()).isEqualTo(1); assertThat(read.getChangesetList()).hasSize(1); @@ -184,7 +181,7 @@ public class ScannerReportWriterTest { assertThat(underTest.hasComponentData(FileStructure.Domain.DUPLICATIONS, 1)).isTrue(); File file = underTest.getFileStructure().fileFor(FileStructure.Domain.DUPLICATIONS, 1); assertThat(file).exists().isFile(); - try (CloseableIterator<ScannerReport.Duplication> duplications = Protobuf.readStream(file, ScannerReport.Duplication.PARSER)) { + try (CloseableIterator<ScannerReport.Duplication> duplications = Protobuf.readStream(file, ScannerReport.Duplication.parser())) { ScannerReport.Duplication dup = duplications.next(); assertThat(dup.getOriginPosition()).isNotNull(); assertThat(dup.getDuplicateList()).hasSize(1); @@ -244,7 +241,7 @@ public class ScannerReportWriterTest { File file = underTest.getFileStructure().fileFor(FileStructure.Domain.SYMBOLS, 1); assertThat(file).exists().isFile(); - try (CloseableIterator<ScannerReport.Symbol> read = Protobuf.readStream(file, ScannerReport.Symbol.PARSER)) { + try (CloseableIterator<ScannerReport.Symbol> read = Protobuf.readStream(file, ScannerReport.Symbol.parser())) { assertThat(read).hasSize(1); } } @@ -255,12 +252,12 @@ public class ScannerReportWriterTest { assertThat(underTest.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, 1)).isFalse(); underTest.writeComponentSyntaxHighlighting(1, asList( - ScannerReport.SyntaxHighlighting.newBuilder() + ScannerReport.SyntaxHighlightingRule.newBuilder() .setRange(ScannerReport.TextRange.newBuilder() .setStartLine(1) .setEndLine(1) .build()) - .setType(Constants.HighlightingType.ANNOTATION) + .setType(HighlightingType.ANNOTATION) .build())); assertThat(underTest.hasComponentData(FileStructure.Domain.SYNTAX_HIGHLIGHTINGS, 1)).isTrue(); @@ -272,7 +269,7 @@ public class ScannerReportWriterTest { assertThat(underTest.hasComponentData(FileStructure.Domain.COVERAGES, 1)).isFalse(); underTest.writeComponentCoverage(1, asList( - ScannerReport.Coverage.newBuilder() + ScannerReport.LineCoverage.newBuilder() .setLine(1) .setConditions(1) .setUtHits(true) |