aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-protocol/src/main
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2018-09-04 16:08:53 +0200
committerSonarTech <sonartech@sonarsource.com>2018-09-24 20:20:58 +0200
commitcfba7fcb6500d8217bd81ecfcb8f47ec48ad55f2 (patch)
tree81398a80d0269b523e630495a580daf8ac144228 /sonar-scanner-protocol/src/main
parent326b30334f0f5c0bb6a9565a3f6b367695bb1087 (diff)
downloadsonarqube-cfba7fcb6500d8217bd81ecfcb8f47ec48ad55f2.tar.gz
sonarqube-cfba7fcb6500d8217bd81ecfcb8f47ec48ad55f2.zip
SONAR-11209 Allow sensors to provide ad hoc rule metadata for external issues
Diffstat (limited to 'sonar-scanner-protocol/src/main')
-rw-r--r--sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/FileStructure.java4
-rw-r--r--sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportReader.java8
-rw-r--r--sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/output/ScannerReportWriter.java9
-rw-r--r--sonar-scanner-protocol/src/main/java/org/sonar/scanner/protocol/viewer/ScannerReportViewerApp.java43
-rw-r--r--sonar-scanner-protocol/src/main/protobuf/scanner_report.proto16
5 files changed, 75 insertions, 5 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 bab729b95b0..5b7e6ddb851 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
@@ -77,6 +77,10 @@ public class FileStructure {
return new File(dir, "activerules.pb");
}
+ public File adHocRules() {
+ return new File(dir, "adhocrules.pb");
+ }
+
public File fileFor(Domain domain, int componentRef) {
return new File(dir, domain.filePrefix + componentRef + domain.fileSuffix);
}
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 65c7bb79a05..c52726e48c1 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
@@ -50,6 +50,14 @@ public class ScannerReportReader {
return Protobuf.readStream(file, ScannerReport.ActiveRule.parser());
}
+ public CloseableIterator<ScannerReport.AdHocRule> readAdHocRules() {
+ File file = fileStructure.adHocRules();
+ if (!fileExists(file)) {
+ return emptyCloseableIterator();
+ }
+ return Protobuf.readStream(file, ScannerReport.AdHocRule.parser());
+ }
+
public CloseableIterator<ScannerReport.Measure> readComponentMeasures(int componentRef) {
File file = fileStructure.fileFor(FileStructure.Domain.MEASURES, componentRef);
if (fileExists(file)) {
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 1ccb6876e88..5fa89151689 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
@@ -109,6 +109,15 @@ public class ScannerReportWriter {
}
}
+ public void appendAdHocRule(ScannerReport.AdHocRule adHocRule) {
+ File file = fileStructure.adHocRules();
+ try (OutputStream out = new BufferedOutputStream(new FileOutputStream(file, true))) {
+ adHocRule.writeDelimitedTo(out);
+ } catch (Exception e) {
+ throw ContextException.of("Unable to write ad hoc rule", e).addContext("file", file);
+ }
+ }
+
public File writeComponentMeasures(int componentRef, Iterable<ScannerReport.Measure> measures) {
File file = fileStructure.fileFor(FileStructure.Domain.MEASURES, componentRef);
Protobuf.writeStream(measures, file, false);
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 c7ab72ff6d3..4df7d77c080 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
@@ -92,12 +92,16 @@ public class ScannerReportViewerApp {
private JEditorPane duplicationEditor;
private JScrollPane issuesTab;
private JEditorPane issuesEditor;
+ private JScrollPane externalIssuesTab;
+ private JEditorPane externalIssuesEditor;
private JScrollPane measuresTab;
private JEditorPane measuresEditor;
private JScrollPane scmTab;
private JEditorPane scmEditor;
private JScrollPane activeRuleTab;
private JEditorPane activeRuleEditor;
+ private JScrollPane adHocRuleTab;
+ private JEditorPane adHocRuleEditor;
private JScrollPane qualityProfileTab;
private JEditorPane qualityProfileEditor;
private JScrollPane pluginTab;
@@ -196,6 +200,7 @@ public class ScannerReportViewerApp {
updateTitle();
loadComponents();
updateActiveRules();
+ updateAdHocRules();
updateQualityProfiles();
updatePlugins();
}
@@ -254,6 +259,7 @@ public class ScannerReportViewerApp {
updateTests(component);
updateDuplications(component);
updateIssues(component);
+ updateExternalIssues(component);
updateMeasures(component);
updateScm(component);
updateCpdTextBlocks(component);
@@ -317,6 +323,19 @@ public class ScannerReportViewerApp {
}
}
+ private void updateExternalIssues(Component component) {
+ externalIssuesEditor.setText("");
+ try (CloseableIterator<ScannerReport.ExternalIssue> it = reader.readComponentExternalIssues(component.getRef())) {
+ while (it.hasNext()) {
+ ScannerReport.ExternalIssue issue = it.next();
+ int offset = externalIssuesEditor.getDocument().getEndPosition().getOffset();
+ externalIssuesEditor.getDocument().insertString(offset, issue.toString(), null);
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException("Can't read external issues for " + getNodeName(component), e);
+ }
+ }
+
private void updateCoverage(Component component) {
coverageEditor.setText("");
try (CloseableIterator<ScannerReport.LineCoverage> it = reader.readComponentCoverage(component.getRef())) {
@@ -375,6 +394,18 @@ public class ScannerReportViewerApp {
}
}
+ private void updateAdHocRules() {
+ adHocRuleEditor.setText("");
+
+ StringBuilder builder = new StringBuilder();
+ try (CloseableIterator<ScannerReport.AdHocRule> adHocRuleCloseableIterator = reader.readAdHocRules()) {
+ while (adHocRuleCloseableIterator.hasNext()) {
+ builder.append(adHocRuleCloseableIterator.next().toString()).append("\n");
+ }
+ adHocRuleEditor.setText(builder.toString());
+ }
+ }
+
private void updateQualityProfiles() {
qualityProfileEditor.setText("");
@@ -536,6 +567,12 @@ public class ScannerReportViewerApp {
issuesEditor = new JEditorPane();
issuesTab.setViewportView(issuesEditor);
+ externalIssuesTab = new JScrollPane();
+ tabbedPane.addTab("External Issues", null, externalIssuesTab, null);
+
+ externalIssuesEditor = new JEditorPane();
+ externalIssuesTab.setViewportView(externalIssuesEditor);
+
measuresTab = new JScrollPane();
tabbedPane.addTab("Measures", null, measuresTab, null);
@@ -554,6 +591,12 @@ public class ScannerReportViewerApp {
activeRuleEditor = new JEditorPane();
activeRuleTab.setViewportView(activeRuleEditor);
+ adHocRuleTab = new JScrollPane();
+ tabbedPane.addTab("Add Hoc Rules", null, adHocRuleTab, null);
+
+ adHocRuleEditor = new JEditorPane();
+ adHocRuleTab.setViewportView(adHocRuleEditor);
+
qualityProfileTab = new JScrollPane();
tabbedPane.addTab("Quality Profiles", null, qualityProfileTab, null);
diff --git a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto
index ac4c89980b8..0913fc179e9 100644
--- a/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto
+++ b/sonar-scanner-protocol/src/main/protobuf/scanner_report.proto
@@ -187,19 +187,25 @@ message Issue {
}
message ExternalIssue {
- 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.
+ string engine_id = 1;
+ string rule_id = 2;
string msg = 3;
Severity severity = 4;
int64 effort = 5;
- // Only when issue component is a file. Can also be empty for a file if this is an issue global to the file.
- // Will be identical to the first location of the first flow
TextRange text_range = 6;
repeated Flow flow = 7;
IssueType type = 8;
}
+message AdHocRule {
+ string engine_id = 1;
+ string rule_id = 2;
+ string name = 3;
+ string description = 4;
+ Severity severity = 5;
+ IssueType type = 6;
+}
+
enum IssueType {
UNSET = 0;
CODE_SMELL = 1;