01: package abbot;
02:
03: import javax.swing.UIManager;
04: import java.io.*;
05: import abbot.tester.Robot;
06: import abbot.i18n.Strings;
07:
08: /** Exception for reporting unexpected situations in the program.
09: * Automatically generates a message suitable for posting in a bug report.
10: */
11: public class BugReport extends Error implements Version {
12:
13: private static final String LS = System
14: .getProperty("line.separator");
15:
16: private static final String BUGREPORT_URL = Strings
17: .get("bugreport.url");
18:
19: private static String getReportingInfo() {
20: return Strings.get("bugreport.info", new Object[] { LS
21: + BUGREPORT_URL + LS });
22: }
23:
24: public static String getSystemInfo() {
25: return "" + "abbot version: " + VERSION + LS
26: + " mode: " + Robot.getEventModeDescription()
27: + LS + " OS: "
28: + System.getProperty("os.name") + " "
29: + System.getProperty("os.version") + " ("
30: + System.getProperty("os.arch") + ") " + LS
31: + " Java version: "
32: + System.getProperty("java.version") + " (vm "
33: + System.getProperty("java.vm.version") + ")" + LS
34: + " Classpath: "
35: + System.getProperty("java.class.path") + LS
36: + "Look and Feel: " + UIManager.getLookAndFeel();
37: }
38:
39: private String errorMessage;
40: private Throwable throwable;
41:
42: public BugReport(String error) {
43: this (error, null);
44: }
45:
46: public BugReport(String error, Throwable thr) {
47: super (error);
48: this .errorMessage = error;
49: this .throwable = thr;
50: }
51:
52: public String toString() {
53: String exc = "";
54: if (throwable != null) {
55: StringWriter writer = new StringWriter();
56: throwable.printStackTrace(new PrintWriter(writer));
57: exc = writer.toString();
58: }
59: return errorMessage + LS + getReportingInfo() + LS
60: + getSystemInfo() + LS + exc;
61: }
62: }
|