From 3df08e5357fed4022b9403282e48d1940d8ac6b0 Mon Sep 17 00:00:00 2001 From: Jeffrey Han Date: Fri, 6 Mar 2015 15:55:15 -0500 Subject: [PATCH] Write build information to "version" file and auto-fill error forms. - Maven version and build date are now written to "res/version". - The GitHub Issues form is auto-filled with error information if available. (reference: fluddokt/opsu@53fe3d9) Signed-off-by: Jeffrey Han --- pom.xml | 14 ++++++++- res/version | 7 +++-- src/itdelatrisu/opsu/ErrorHandler.java | 43 ++++++++++++++++++++++++-- src/itdelatrisu/opsu/Options.java | 14 ++------- 4 files changed, 60 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 1e46e6d1..9ab36367 100644 --- a/pom.xml +++ b/pom.xml @@ -4,16 +4,28 @@ itdelatrisu opsu 0.6.0 - + + ${maven.build.timestamp} + yyyy-MM-dd HH:mm + src + false res **/Thumbs.db + **/version + + true + res + + **/version + + diff --git a/res/version b/res/version index 5dd3872b..11f63e48 100644 --- a/res/version +++ b/res/version @@ -1,3 +1,6 @@ -#Mon, 03 Jun 2013 22:20:24 +0100 -#Sun May 11 20:17:03 BST 2008 +# opsu! build info +version=${pom.version} +build.date=${timestamp} + +# slick build build=237 diff --git a/src/itdelatrisu/opsu/ErrorHandler.java b/src/itdelatrisu/opsu/ErrorHandler.java index 25aab5d4..ef0936a3 100644 --- a/src/itdelatrisu/opsu/ErrorHandler.java +++ b/src/itdelatrisu/opsu/ErrorHandler.java @@ -22,6 +22,9 @@ import java.awt.Cursor; import java.awt.Desktop; import java.io.PrintWriter; import java.io.StringWriter; +import java.net.URI; +import java.net.URLEncoder; +import java.util.Properties; import javax.swing.JOptionPane; import javax.swing.JScrollPane; @@ -29,6 +32,7 @@ import javax.swing.JTextArea; import javax.swing.UIManager; import org.newdawn.slick.util.Log; +import org.newdawn.slick.util.ResourceLoader; /** * Error handler to log and display errors. @@ -92,10 +96,12 @@ public class ErrorHandler { textArea.append(error); textArea.append("\n"); } + String trace = null; if (e != null) { StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); - textArea.append(sw.toString()); + trace = sw.toString(); + textArea.append(trace); } // display popup @@ -109,8 +115,39 @@ public class ErrorHandler { JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE, null, optionsR, optionsR[2]); if (n == 0) { - Desktop.getDesktop().browse(Options.ISSUES_URI); - Desktop.getDesktop().open(Options.LOG_FILE); + // auto-fill debug information + String issueTitle = (error != null) ? error : e.getMessage(); + StringBuilder sb = new StringBuilder(); + Properties props = new Properties(); + props.load(ResourceLoader.getResourceAsStream("version")); + String version = props.getProperty("version"); + if (version != null && !version.equals("${pom.version}")) { + sb.append("**Version:** "); + sb.append(version); + sb.append('\n'); + } + String timestamp = props.getProperty("build.date"); + if (timestamp != null && + !timestamp.equals("${maven.build.timestamp}") && !timestamp.equals("${timestamp}")) { + sb.append("**Build date:** "); + sb.append(timestamp); + sb.append('\n'); + } + if (error != null) { + sb.append("**Error:** `"); + sb.append(error); + sb.append("`\n"); + } + if (trace != null) { + sb.append("**Stack trace:**"); + sb.append("\n```\n"); + sb.append(trace); + sb.append("```"); + } + URI uri = URI.create(String.format(Options.ISSUES_URL, + URLEncoder.encode(issueTitle, "UTF-8"), + URLEncoder.encode(sb.toString(), "UTF-8"))); + Desktop.getDesktop().browse(uri); } else if (n == 1) Desktop.getDesktop().open(Options.LOG_FILE); } else { diff --git a/src/itdelatrisu/opsu/Options.java b/src/itdelatrisu/opsu/Options.java index 5095b32f..ddd4ecda 100644 --- a/src/itdelatrisu/opsu/Options.java +++ b/src/itdelatrisu/opsu/Options.java @@ -26,7 +26,6 @@ import java.io.FileReader; import java.io.IOException; import java.io.OutputStreamWriter; import java.net.URI; -import java.net.URISyntaxException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; @@ -71,19 +70,10 @@ public class Options { public static final String FONT_NAME = "kochi-gothic.ttf"; /** Repository address. */ - public static URI REPOSITORY_URI; + public static URI REPOSITORY_URI = URI.create("https://github.com/itdelatrisu/opsu"); /** Issue reporting address. */ - public static URI ISSUES_URI; - - static { - try { - REPOSITORY_URI = new URI("https://github.com/itdelatrisu/opsu"); - ISSUES_URI = new URI("https://github.com/itdelatrisu/opsu/issues/new"); - } catch (URISyntaxException e) { - Log.error("Problem loading URIs.", e); - } - } + public static String ISSUES_URL = "https://github.com/itdelatrisu/opsu/issues/new?title=%s&body=%s"; /** The beatmap directory. */ private static File beatmapDir;