From ad5e52729d542dc2ee5fc7b4a90ced2f69eaed9b Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Tue, 8 Aug 2017 19:24:23 +0200 Subject: [PATCH] Update scanner report viewer to show QP and plugins --- .../viewer/ScannerReportViewerApp.java | 53 ++++++++++++++++--- 1 file changed, 47 insertions(+), 6 deletions(-) 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 e34e0421444..ed5accc8d00 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 @@ -32,8 +32,8 @@ import java.nio.charset.StandardCharsets; import java.sql.Date; import java.text.SimpleDateFormat; import java.util.List; +import java.util.Map; import java.util.Scanner; - import javax.annotation.CheckForNull; import javax.swing.JEditorPane; import javax.swing.JFileChooser; @@ -51,7 +51,6 @@ import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreeSelectionModel; - import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.sonar.core.util.CloseableIterator; @@ -62,6 +61,8 @@ import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Changeset; import org.sonar.scanner.protocol.output.ScannerReport.Component; import org.sonar.scanner.protocol.output.ScannerReport.Issue; import org.sonar.scanner.protocol.output.ScannerReport.Metadata; +import org.sonar.scanner.protocol.output.ScannerReport.Metadata.Plugin; +import org.sonar.scanner.protocol.output.ScannerReport.Metadata.QProfile; import org.sonar.scanner.protocol.output.ScannerReportReader; public class ScannerReportViewerApp { @@ -97,6 +98,10 @@ public class ScannerReportViewerApp { private JEditorPane scmEditor; private JScrollPane activeRuleTab; private JEditorPane activeRuleEditor; + private JScrollPane qualityProfileTab; + private JEditorPane qualityProfileEditor; + private JScrollPane pluginTab; + private JEditorPane pluginEditor; private JScrollPane cpdTextBlocksTab; private JEditorPane cpdTextBlocksEditor; @@ -189,6 +194,8 @@ public class ScannerReportViewerApp { updateTitle(); loadComponents(); updateActiveRules(); + updateQualityProfiles(); + updatePlugins(); } private void loadComponents() { @@ -263,7 +270,7 @@ public class ScannerReportViewerApp { } } } - + private void updateDuplications(Component component) { duplicationEditor.setText(""); if (reader.hasCoverage(component.getRef())) { @@ -349,6 +356,28 @@ public class ScannerReportViewerApp { } } + private void updateQualityProfiles() { + qualityProfileEditor.setText(""); + + StringBuilder builder = new StringBuilder(); + for (Map.Entry qp : metadata.getQprofilesPerLanguage().entrySet()) { + builder.append(qp.getKey()).append(":\n").append(qp.getValue()).append("\n\n"); + + } + qualityProfileEditor.setText(builder.toString()); + } + + private void updatePlugins() { + pluginEditor.setText(""); + + StringBuilder builder = new StringBuilder(); + for (Map.Entry p : metadata.getPluginsByKey().entrySet()) { + builder.append(p.getKey()).append(":\n").append(p.getValue()).append("\n\n"); + + } + pluginEditor.setText(builder.toString()); + } + private void updateHighlighting(Component component) { highlightingEditor.setText(""); try (CloseableIterator it = reader.readComponentSyntaxHighlighting(component.getRef())) { @@ -387,7 +416,7 @@ public class ScannerReportViewerApp { scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), changeset + "\n", null); index++; } - + scmEditor.getDocument().insertString(scmEditor.getDocument().getEndPosition().getOffset(), "\n", null); int line = 1; for (Integer idx : changesetIndexByLine) { @@ -506,12 +535,24 @@ public class ScannerReportViewerApp { activeRuleEditor = new JEditorPane(); activeRuleTab.setViewportView(activeRuleEditor); + qualityProfileTab = new JScrollPane(); + tabbedPane.addTab("Quality Profiles", null, qualityProfileTab, null); + + qualityProfileEditor = new JEditorPane(); + qualityProfileTab.setViewportView(qualityProfileEditor); + + pluginTab = new JScrollPane(); + tabbedPane.addTab("Plugins", null, pluginTab, null); + + pluginEditor = new JEditorPane(); + pluginTab.setViewportView(pluginEditor); + cpdTextBlocksTab = new JScrollPane(); tabbedPane.addTab("CPD Text Blocks", null, cpdTextBlocksTab, null); - + cpdTextBlocksEditor = new JEditorPane(); cpdTextBlocksTab.setViewportView(cpdTextBlocksEditor); - + treeScrollPane = new JScrollPane(); treeScrollPane.setPreferredSize(new Dimension(200, 400)); splitPane.setLeftComponent(treeScrollPane); -- 2.39.5