aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-protocol/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-scanner-protocol/src/main')
-rw-r--r--sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportReader.java24
-rw-r--r--sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java4
-rw-r--r--sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/viewer/ScannerReportViewerApp.java14
-rw-r--r--sonar-scanner-protocol/src/main/protobuf/constants.proto60
-rw-r--r--sonar-scanner-protocol/src/main/protobuf/scanner_report.proto231
5 files changed, 170 insertions, 163 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];
}
}