source: josm/trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java@ 5873

Last change on this file since 5873 was 5873, checked in by Don-vip, 11 years ago

see #8571, #8602, #8606: Remove "Operating system" line from status report header as it is now fully included in Agent string

  • Property svn:eol-style set to native
File size: 6.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.Dimension;
8import java.awt.event.ActionEvent;
9import java.awt.event.KeyEvent;
10import java.lang.management.ManagementFactory;
11import java.util.ArrayList;
12import java.util.Arrays;
13import java.util.HashSet;
14import java.util.List;
15import java.util.ListIterator;
16import java.util.Map;
17import java.util.Map.Entry;
18import java.util.Set;
19
20import javax.swing.JScrollPane;
21import javax.swing.JTextArea;
22
23import org.openstreetmap.josm.Main;
24import org.openstreetmap.josm.data.Preferences.Setting;
25import org.openstreetmap.josm.data.Version;
26import org.openstreetmap.josm.data.osm.DataSet;
27import org.openstreetmap.josm.data.osm.DatasetConsistencyTest;
28import org.openstreetmap.josm.gui.ExtendedDialog;
29import org.openstreetmap.josm.plugins.PluginHandler;
30import org.openstreetmap.josm.tools.BugReportExceptionHandler;
31import org.openstreetmap.josm.tools.OpenBrowser;
32import org.openstreetmap.josm.tools.Shortcut;
33import org.openstreetmap.josm.tools.Utils;
34
35/**
36 * @author xeen
37 *
38 * Opens a dialog with useful status information like version numbers for Java, JOSM and plugins
39 * Also includes preferences with stripped username and password
40 */
41public final class ShowStatusReportAction extends JosmAction {
42
43 /**
44 * Constructs a new {@code ShowStatusReportAction}
45 */
46 public ShowStatusReportAction() {
47 super(
48 tr("Show Status Report"),
49 "clock",
50 tr("Show status report with useful information that can be attached to bugs"),
51 Shortcut.registerShortcut("help:showstatusreport", tr("Help: {0}",
52 tr("Show Status Report")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false);
53
54 putValue("help", ht("/Action/ShowStatusReport"));
55 putValue("toolbar", "help/showstatusreport");
56 Main.toolbar.register(this);
57 }
58
59 /**
60 * Replies the report header (software and system info)
61 * @return The report header (software and system info)
62 */
63 public static String getReportHeader()
64 {
65 StringBuilder text = new StringBuilder();
66 text.append(Version.getInstance().getReleaseAttributes());
67 text.append("\n");
68 text.append("Identification: " + Version.getInstance().getAgentString());
69 text.append("\n");
70 text.append("Memory Usage: ");
71 text.append(Runtime.getRuntime().totalMemory()/1024/1024);
72 text.append(" MB / ");
73 text.append(Runtime.getRuntime().maxMemory()/1024/1024);
74 text.append(" MB (");
75 text.append(Runtime.getRuntime().freeMemory()/1024/1024);
76 text.append(" MB allocated, but free)");
77 text.append("\n");
78 text.append("Java version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor") + ", " + System.getProperty("java.vm.name"));
79 text.append("\n");
80 try {
81 // Build a new list of VM parameters to modify it below if needed (default implementation returns an UnmodifiableList instance)
82 List<String> vmArguments = new ArrayList<String>(ManagementFactory.getRuntimeMXBean().getInputArguments());
83 // Hide some parameters for privacy concerns
84 for (ListIterator<String> it = vmArguments.listIterator(); it.hasNext(); ) {
85 String value = it.next();
86 if (value.contains("=") && value.toLowerCase().startsWith("-dproxy")) {
87 it.set(value.split("=")[0]+"=xxx");
88 }
89 }
90 if (!vmArguments.isEmpty()) {
91 text.append("VM arguments: "+ vmArguments.toString().replace("\\\\", "\\"));
92 text.append("\n");
93 }
94 } catch (SecurityException e) {
95 // Ignore exception
96 }
97 if (Main.commandLineArgs.length > 0) {
98 text.append("Program arguments: "+ Arrays.toString(Main.commandLineArgs));
99 text.append("\n");
100 }
101 DataSet dataset = Main.main.getCurrentDataSet();
102 if (dataset != null) {
103 String result = DatasetConsistencyTest.runTests(dataset);
104 if (result.length() == 0) {
105 text.append("Dataset consistency test: No problems found\n");
106 } else {
107 text.append("\nDataset consistency test:\n"+result+"\n");
108 }
109 }
110 text.append("\n");
111 text.append(PluginHandler.getBugReportText());
112 text.append("\n");
113
114 return text.toString();
115 }
116
117 public void actionPerformed(ActionEvent e) {
118 StringBuilder text = new StringBuilder();
119 String reportHeader = getReportHeader();
120 text.append(reportHeader);
121 try {
122 Map<String, Setting> settings = Main.pref.getAllSettings();
123 settings.remove("osm-server.username");
124 settings.remove("osm-server.password");
125 settings.remove("oauth.access-token.key");
126 settings.remove("oauth.access-token.secret");
127 Set<String> keys = new HashSet<String>(settings.keySet());
128 for (String key : keys) {
129 if (key.startsWith("marker.show")) {
130 settings.remove(key);
131 }
132 }
133 for (Entry<String, Setting> entry : settings.entrySet()) {
134 text.append(entry.getKey()).append("=").append(entry.getValue().getValue().toString()).append("\n");
135 }
136 } catch (Exception x) {
137 x.printStackTrace();
138 }
139
140 JTextArea ta = new JTextArea(text.toString());
141 ta.setWrapStyleWord(true);
142 ta.setLineWrap(true);
143 ta.setEditable(false);
144 JScrollPane sp = new JScrollPane(ta);
145
146 ExtendedDialog ed = new ExtendedDialog(Main.parent,
147 tr("Status Report"),
148 new String[] {tr("Copy to clipboard and close"), tr("Report bug"), tr("Close") });
149 ed.setButtonIcons(new String[] {"copy.png", "bug.png", "cancel.png" });
150 ed.setContent(sp, false);
151 ed.setMinimumSize(new Dimension(380, 200));
152 ed.setPreferredSize(new Dimension(700, Main.parent.getHeight()-50));
153
154 switch (ed.showDialog().getValue()) {
155 case 1: Utils.copyToClipboard(text.toString()); break;
156 case 2: OpenBrowser.displayUrl(BugReportExceptionHandler.getBugReportUrl(
157 Utils.strip(reportHeader)).toExternalForm()) ; break;
158 }
159 }
160}
Note: See TracBrowser for help on using the repository browser.