From 7a0680dcc97b942f12810e52b46844d610debd0d Mon Sep 17 00:00:00 2001 From: Eduardo Ramos Date: Wed, 6 Jul 2016 00:39:07 +0200 Subject: [PATCH] Fix #1530 Adapt crash reporter to send data to a new service --- modules/DesktopBranding/pom.xml | 23 +++ .../branding/desktop/reporter/Report.java | 2 +- .../desktop/reporter/ReportController.java | 131 +++++++----------- .../desktop/reporter/ReportPanel.form | 1 - .../desktop/reporter/ReportPanel.java | 19 ++- .../DesktopBranding/src/main/nbm/manifest.mf | 2 +- 6 files changed, 85 insertions(+), 93 deletions(-) diff --git a/modules/DesktopBranding/pom.xml b/modules/DesktopBranding/pom.xml index 4a2dff63d..d273bebdb 100644 --- a/modules/DesktopBranding/pom.xml +++ b/modules/DesktopBranding/pom.xml @@ -92,6 +92,29 @@ org.netbeans.modules org-netbeans-core-output2 + + com.getsentry.raven + raven + 7.3.0 + + + org.slf4j + slf4j-api + + + + + + + org.slf4j + slf4j-api + 1.7.21 + + + org.slf4j + slf4j-jdk14 + 1.7.21 + diff --git a/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/Report.java b/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/Report.java index a2aa05d17..404417029 100644 --- a/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/Report.java +++ b/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/Report.java @@ -229,7 +229,7 @@ public class Report { public Element writeXml(Document document) { Element reportE = document.createElement("report"); - reportE.setAttribute("version", "0.7"); + reportE.setAttribute("version", "0.9.1"); //Date Element dateE = document.createElement("date"); diff --git a/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/ReportController.java b/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/ReportController.java index 3bc64948e..27a2ba242 100644 --- a/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/ReportController.java +++ b/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/ReportController.java @@ -41,34 +41,28 @@ Portions Copyrighted 2011 Gephi Consortium. */ package org.gephi.branding.desktop.reporter; +import com.getsentry.raven.Raven; +import com.getsentry.raven.RavenFactory; +import com.getsentry.raven.event.Event; +import com.getsentry.raven.event.EventBuilder; +import com.getsentry.raven.event.interfaces.ExceptionInterface; import java.awt.Dimension; import java.awt.GraphicsEnvironment; import java.awt.Toolkit; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.InputStreamReader; import java.io.LineNumberReader; -import java.io.OutputStreamWriter; import java.io.StringReader; -import java.io.StringWriter; import java.lang.management.ManagementFactory; import java.lang.management.MemoryMXBean; import java.lang.management.OperatingSystemMXBean; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLEncoder; import java.text.MessageFormat; import java.util.MissingResourceException; import java.util.logging.Handler; import java.util.logging.Logger; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.progress.ProgressHandleFactory; import org.openide.DialogDisplayer; @@ -85,7 +79,13 @@ import org.w3c.dom.Document; */ public class ReportController { - private static final String POST_URL = "http://gephi.org/crashreporter/report.php"; + private static final String POST_URL = "https://d007fbbdeb6241b5b2c542a6bc548cf3:4a1af110df484e838da9243c1496ebe9@app.getsentry.com/85815"; + + private final Raven raven; + + public ReportController() { + raven = RavenFactory.ravenInstance(POST_URL); + } public void sendReport(final Report report) { Thread thread = new Thread(new Runnable() { @@ -95,16 +95,14 @@ public class ReportController { ProgressHandle handle = ProgressHandleFactory.createHandle(NbBundle.getMessage(ReportController.class, "ReportController.status.sending")); try { handle.start(); - Document doc = buildReportDocument(report); - if (doc != null) { - if (sendDocument(doc)) { - handle.finish(); - DialogDisplayer.getDefault().notify( - new NotifyDescriptor.Message(NbBundle.getMessage(ReportController.class, "ReportController.status.sent"), - NotifyDescriptor.INFORMATION_MESSAGE)); - return; - } - } + + sendSentryReport(report); + + handle.finish(); + DialogDisplayer.getDefault().notify( + new NotifyDescriptor.Message(NbBundle.getMessage(ReportController.class, "ReportController.status.sent"), + NotifyDescriptor.INFORMATION_MESSAGE)); + return; } catch (Exception e) { e.printStackTrace(); } @@ -113,9 +111,33 @@ public class ReportController { new NotifyDescriptor.Message(NbBundle.getMessage(ReportController.class, "ReportController.status.failed"), NotifyDescriptor.WARNING_MESSAGE)); } + }, "Exception Reporter"); thread.start(); } + + private void sendSentryReport(Report report) { + EventBuilder eventBuilder = new EventBuilder().withMessage(report.getThrowable().getMessage()) + .withLevel(Event.Level.ERROR) + .withSentryInterface(new ExceptionInterface(report.getThrowable())) + .withRelease(report.getVersion()) + .withServerName("Gephi Desktop")//Avoid raven looking up 'localhost' as hostname + .withExtra("OS", report.getOs()) + .withExtra("Heap memory usage", report.getHeapMemoryUsage()) + .withExtra("Non heap memory usage", report.getNonHeapMemoryUsage()) + .withExtra("Processors", report.getNumberOfProcessors()) + .withExtra("Screen devices", report.getScreenDevices()) + .withExtra("Screen size", report.getScreenSize()) + .withExtra("User description", report.getUserDescription()) + .withExtra("User email", report.getUserEmail()) + .withExtra("VM", report.getVm()) + .withExtra("OpenGL Vendor", report.getGlVendor()) + .withExtra("OpenGL Renderer", report.getGlRenderer()) + .withExtra("OpenGL Version", report.getGlVersion()) + .withExtra("Log", report.getLog()); + + raven.sendEvent(eventBuilder); + } public Document buildReportDocument(Report report) { logMessageLog(report); @@ -128,58 +150,7 @@ public class ReportController { //logModules(report); return buildXMLDocument(report); } - - public boolean sendDocument(Document document) { - try { - //Get String from Document - TransformerFactory factory = TransformerFactory.newInstance(); - Transformer transformer = factory.newTransformer(); - transformer.setOutputProperty(OutputKeys.INDENT, "yes"); - transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); - StringWriter sw = new StringWriter(); - StreamResult result = new StreamResult(sw); - DOMSource source = new DOMSource(document); - transformer.transform(source, result); - String xmlString = "report=" + URLEncoder.encode(sw.toString(), "UTF-8"); - - URL url = new URL(POST_URL); - URLConnection con = url.openConnection(); - - // specify that we will send output and accept input - con.setDoInput(true); - con.setDoOutput(true); - - con.setUseCaches(false); - con.setDefaultUseCaches(false); - - // tell the web server what we are sending - //con.setRequestProperty("Content-Type", "text/xml"); - //con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); - - OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream()); - writer.write(xmlString); - writer.flush(); - writer.close(); - - // reading the response - InputStreamReader reader = new InputStreamReader(con.getInputStream()); - - StringBuilder buf = new StringBuilder(); - char[] cbuf = new char[2048]; - int num; - - while (-1 != (num = reader.read(cbuf))) { - buf.append(cbuf, 0, num); - } - - String serverResult = buf.toString(); - return true; - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } - + private Document buildXMLDocument(Report report) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -247,12 +218,12 @@ public class ReportController { LineNumberReader lineNumberReader = new LineNumberReader(new StringReader(output)); String line; while ((line = lineNumberReader.readLine()) != null) { - if (line.startsWith("GL_VENDOR:")) { - report.setGlVendor(line.substring(11)); - } else if (line.startsWith("GL_RENDERER:")) { - report.setGlRenderer(line.substring(13)); - } else if (line.startsWith("GL_VERSION:")) { - report.setGlVersion(line.substring(12)); + if (line.contains("GL_VENDOR:")) { + report.setGlVendor(line.replaceFirst(".*GL_VENDOR:", "")); + } else if (line.contains("GL_RENDERER:")) { + report.setGlRenderer(line.replaceFirst(".*GL_RENDERER:", "")); + } else if (line.contains("GL_VERSION:")) { + report.setGlVersion(line.replaceFirst(".*GL_VERSION:", "")); break; } } diff --git a/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/ReportPanel.form b/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/ReportPanel.form index 247dd23d3..064174df8 100644 --- a/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/ReportPanel.form +++ b/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/ReportPanel.form @@ -54,7 +54,6 @@ - diff --git a/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/ReportPanel.java b/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/ReportPanel.java index 1ba84bf39..2920491e1 100644 --- a/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/ReportPanel.java +++ b/modules/DesktopBranding/src/main/java/org/gephi/branding/desktop/reporter/ReportPanel.java @@ -38,7 +38,7 @@ made subject to such option by the copyright holder. Contributor(s): Portions Copyrighted 2011 Gephi Consortium. -*/ + */ package org.gephi.branding.desktop.reporter; import java.awt.event.ActionEvent; @@ -54,11 +54,15 @@ import org.w3c.dom.Document; */ public class ReportPanel extends javax.swing.JPanel { - private Report report; - private ReportController reportController; + private final Report report; + private final ReportController reportController; + private final Document document; public ReportPanel(Report report) { + this.reportController = new ReportController(); this.report = report; + this.document = reportController.buildReportDocument(ReportPanel.this.report); + initComponents(); //Bind @@ -78,10 +82,8 @@ public class ReportPanel extends javax.swing.JPanel { @Override public void actionPerformed(ActionEvent e) { - //Set ReportPanel.this.report.setUserDescription(problemArea.getText()); ReportPanel.this.report.setUserEmail(emailTextField.getText()); - Document document = reportController.buildReportDocument(ReportPanel.this.report); DialogDescriptor dd = new DialogDescriptor(new ViewDataPanel(document), NbBundle.getMessage(ReportPanel.class, "ReportPanel.viewData.title"), true, DialogDescriptor.DEFAULT_OPTION, null, null); DialogDisplayer.getDefault().notify(dd); } @@ -97,7 +99,6 @@ public class ReportPanel extends javax.swing.JPanel { } public void showDialog() { - reportController = new ReportController(); Object[] options = new Object[2]; options[0] = NbBundle.getMessage(ReportPanel.class, "ReportPanel.dialog.sendButton"); options[1] = DialogDescriptor.CANCEL_OPTION; @@ -112,10 +113,8 @@ public class ReportPanel extends javax.swing.JPanel { } } - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. + /** + * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents diff --git a/modules/DesktopBranding/src/main/nbm/manifest.mf b/modules/DesktopBranding/src/main/nbm/manifest.mf index 8afd37b0b..5bb4b84d3 100644 --- a/modules/DesktopBranding/src/main/nbm/manifest.mf +++ b/modules/DesktopBranding/src/main/nbm/manifest.mf @@ -3,6 +3,6 @@ AutoUpdate-Essential-Module: true OpenIDE-Module-Install: org/gephi/branding/desktop/Installer.class OpenIDE-Module-Layer: org/gephi/branding/desktop/layer.xml OpenIDE-Module-Localizing-Bundle: org/gephi/branding/desktop/Bundle.properties -OpenIDE-Module-Specification-Version: ${gephi.modules.specification.version} +OpenIDE-Module-Specification-Version: 0.9.1.1 OpenIDE-Module-Display-Category: Gephi UI OpenIDE-Module-Name: Desktop Branding \ No newline at end of file -- GitLab