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