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 | import static org.openstreetmap.josm.tools.Utils.getSystemEnv;
|
---|
7 | import static org.openstreetmap.josm.tools.Utils.getSystemProperty;
|
---|
8 |
|
---|
9 | import java.awt.Dimension;
|
---|
10 | import java.awt.DisplayMode;
|
---|
11 | import java.awt.GraphicsEnvironment;
|
---|
12 | import java.awt.event.ActionEvent;
|
---|
13 | import java.awt.event.KeyEvent;
|
---|
14 | import java.lang.management.ManagementFactory;
|
---|
15 | import java.util.ArrayList;
|
---|
16 | import java.util.Arrays;
|
---|
17 | import java.util.Collection;
|
---|
18 | import java.util.LinkedHashMap;
|
---|
19 | import java.util.List;
|
---|
20 | import java.util.ListIterator;
|
---|
21 | import java.util.Locale;
|
---|
22 | import java.util.Map;
|
---|
23 | import java.util.Map.Entry;
|
---|
24 | import java.util.Set;
|
---|
25 | import java.util.stream.Collectors;
|
---|
26 |
|
---|
27 | import org.openstreetmap.josm.data.Preferences;
|
---|
28 | import org.openstreetmap.josm.data.Version;
|
---|
29 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
30 | import org.openstreetmap.josm.data.osm.DatasetConsistencyTest;
|
---|
31 | import org.openstreetmap.josm.data.preferences.sources.MapPaintPrefHelper;
|
---|
32 | import org.openstreetmap.josm.data.preferences.sources.PresetPrefHelper;
|
---|
33 | import org.openstreetmap.josm.data.preferences.sources.SourcePrefHelper;
|
---|
34 | import org.openstreetmap.josm.data.preferences.sources.ValidatorPrefHelper;
|
---|
35 | import org.openstreetmap.josm.gui.ExtendedDialog;
|
---|
36 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
37 | import org.openstreetmap.josm.gui.bugreport.DebugTextDisplay;
|
---|
38 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
39 | import org.openstreetmap.josm.io.OsmApi;
|
---|
40 | import org.openstreetmap.josm.plugins.PluginHandler;
|
---|
41 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
42 | import org.openstreetmap.josm.tools.Logging;
|
---|
43 | import org.openstreetmap.josm.tools.PlatformHookUnixoid;
|
---|
44 | import org.openstreetmap.josm.tools.PlatformManager;
|
---|
45 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
46 | import org.openstreetmap.josm.tools.Utils;
|
---|
47 | import org.openstreetmap.josm.tools.bugreport.BugReportSender;
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Opens a dialog with useful status information like version numbers for Java, JOSM and plugins
|
---|
51 | * Also includes preferences with stripped username and password.
|
---|
52 | *
|
---|
53 | * @author xeen
|
---|
54 | */
|
---|
55 | public final class ShowStatusReportAction extends JosmAction {
|
---|
56 |
|
---|
57 | /**
|
---|
58 | * Constructs a new {@code ShowStatusReportAction}
|
---|
59 | */
|
---|
60 | public ShowStatusReportAction() {
|
---|
61 | super(
|
---|
62 | tr("Show Status Report"),
|
---|
63 | "clock",
|
---|
64 | tr("Show status report with useful information that can be attached to bugs"),
|
---|
65 | Shortcut.registerShortcut("help:showstatusreport", tr("Help: {0}",
|
---|
66 | tr("Show Status Report")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), true, "help/showstatusreport", false);
|
---|
67 |
|
---|
68 | setHelpId(ht("/Action/ShowStatusReport"));
|
---|
69 | }
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Replies the report header (software and system info)
|
---|
73 | * @return The report header (software and system info)
|
---|
74 | */
|
---|
75 | public static String getReportHeader() {
|
---|
76 | StringBuilder text = new StringBuilder(256);
|
---|
77 | String runtimeVersion = getSystemProperty("java.runtime.version");
|
---|
78 | text.append(Version.getInstance().getReleaseAttributes())
|
---|
79 | .append("\nIdentification: ").append(Version.getInstance().getAgentString());
|
---|
80 | String buildNumber = PlatformManager.getPlatform().getOSBuildNumber();
|
---|
81 | if (!buildNumber.isEmpty()) {
|
---|
82 | text.append("\nOS Build number: ").append(buildNumber);
|
---|
83 | }
|
---|
84 | text.append("\nMemory Usage: ")
|
---|
85 | .append(Runtime.getRuntime().totalMemory()/1024/1024)
|
---|
86 | .append(" MB / ")
|
---|
87 | .append(Runtime.getRuntime().maxMemory()/1024/1024)
|
---|
88 | .append(" MB (")
|
---|
89 | .append(Runtime.getRuntime().freeMemory()/1024/1024)
|
---|
90 | .append(" MB allocated, but free)\nJava version: ")
|
---|
91 | .append(runtimeVersion != null ? runtimeVersion : getSystemProperty("java.version")).append(", ")
|
---|
92 | .append(getSystemProperty("java.vendor")).append(", ")
|
---|
93 | .append(getSystemProperty("java.vm.name"))
|
---|
94 | .append("\nScreen: ");
|
---|
95 | if (!GraphicsEnvironment.isHeadless()) {
|
---|
96 | text.append(Arrays.stream(GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()).map(gd -> {
|
---|
97 | StringBuilder b = new StringBuilder(gd.getIDstring());
|
---|
98 | DisplayMode dm = gd.getDisplayMode();
|
---|
99 | if (dm != null) {
|
---|
100 | b.append(' ').append(dm.getWidth()).append('x').append(dm.getHeight());
|
---|
101 | }
|
---|
102 | return b.toString();
|
---|
103 | }).collect(Collectors.joining(", ")));
|
---|
104 | }
|
---|
105 | Dimension maxScreenSize = GuiHelper.getMaximumScreenSize();
|
---|
106 | text.append("\nMaximum Screen Size: ")
|
---|
107 | .append((int) maxScreenSize.getWidth()).append('x')
|
---|
108 | .append((int) maxScreenSize.getHeight()).append('\n');
|
---|
109 |
|
---|
110 | if (PlatformManager.isPlatformUnixoid()) {
|
---|
111 | PlatformHookUnixoid platform = (PlatformHookUnixoid) PlatformManager.getPlatform();
|
---|
112 | // Add Java package details
|
---|
113 | String packageDetails = platform.getJavaPackageDetails();
|
---|
114 | if (packageDetails != null) {
|
---|
115 | text.append("Java package: ")
|
---|
116 | .append(packageDetails)
|
---|
117 | .append('\n');
|
---|
118 | }
|
---|
119 | // Add WebStart package details if run from JNLP
|
---|
120 | if (Utils.isRunningJavaWebStart()) {
|
---|
121 | String webStartDetails = platform.getWebStartPackageDetails();
|
---|
122 | if (webStartDetails != null) {
|
---|
123 | text.append("WebStart package: ")
|
---|
124 | .append(webStartDetails)
|
---|
125 | .append('\n');
|
---|
126 | }
|
---|
127 | }
|
---|
128 | // Add Gnome Atk wrapper details if found
|
---|
129 | String atkWrapperDetails = platform.getAtkWrapperPackageDetails();
|
---|
130 | if (atkWrapperDetails != null) {
|
---|
131 | text.append("Java ATK Wrapper package: ")
|
---|
132 | .append(atkWrapperDetails)
|
---|
133 | .append('\n');
|
---|
134 | }
|
---|
135 | // Add dependencies details if found
|
---|
136 | for (String p : new String[] {
|
---|
137 | "apache-commons-compress", "libcommons-compress-java",
|
---|
138 | "apache-commons-jcs-core",
|
---|
139 | "apache-commons-logging", "libcommons-logging-java",
|
---|
140 | "fonts-noto",
|
---|
141 | "jsonp",
|
---|
142 | "metadata-extractor2",
|
---|
143 | "signpost-core", "liboauth-signpost-java",
|
---|
144 | "svgsalamander"
|
---|
145 | }) {
|
---|
146 | String details = PlatformHookUnixoid.getPackageDetails(p);
|
---|
147 | if (details != null) {
|
---|
148 | text.append(p).append(": ").append(details).append('\n');
|
---|
149 | }
|
---|
150 | }
|
---|
151 | }
|
---|
152 | try {
|
---|
153 | // Build a new list of VM parameters to modify it below if needed (default implementation returns an UnmodifiableList instance)
|
---|
154 | List<String> vmArguments = new ArrayList<>(ManagementFactory.getRuntimeMXBean().getInputArguments());
|
---|
155 | for (ListIterator<String> it = vmArguments.listIterator(); it.hasNext();) {
|
---|
156 | String value = it.next();
|
---|
157 | if (value.contains("=")) {
|
---|
158 | String[] param = value.split("=", 2);
|
---|
159 | // Hide some parameters for privacy concerns
|
---|
160 | if (param[0].toLowerCase(Locale.ENGLISH).startsWith("-dproxy")) {
|
---|
161 | it.set(param[0]+"=xxx");
|
---|
162 | } else if ("-Djnlpx.vmargs".equals(param[0])) {
|
---|
163 | // Remove jnlpx.vmargs (base64 encoded copy of VM arguments already included in clear)
|
---|
164 | it.remove();
|
---|
165 | } else {
|
---|
166 | // Replace some paths for readability and privacy concerns
|
---|
167 | String val = paramCleanup(param[1]);
|
---|
168 | if (!val.equals(param[1])) {
|
---|
169 | it.set(param[0] + '=' + val);
|
---|
170 | }
|
---|
171 | }
|
---|
172 | } else if (value.startsWith("-X")) {
|
---|
173 | // Remove arguments like -Xbootclasspath/a, -Xverify:remote, that can be very long and unhelpful
|
---|
174 | it.remove();
|
---|
175 | }
|
---|
176 | }
|
---|
177 | if (!vmArguments.isEmpty()) {
|
---|
178 | text.append("VM arguments: ").append(vmArguments.toString().replace("\\\\", "\\")).append('\n');
|
---|
179 | }
|
---|
180 | } catch (SecurityException e) {
|
---|
181 | Logging.trace(e);
|
---|
182 | }
|
---|
183 | List<String> commandLineArgs = MainApplication.getCommandLineArgs();
|
---|
184 | if (!commandLineArgs.isEmpty()) {
|
---|
185 | text.append("Program arguments: ").append(Arrays.toString(paramCleanup(commandLineArgs).toArray())).append('\n');
|
---|
186 | }
|
---|
187 | DataSet dataset = MainApplication.getLayerManager().getActiveDataSet();
|
---|
188 | if (dataset != null) {
|
---|
189 | String result = DatasetConsistencyTest.runTests(dataset);
|
---|
190 | if (result.isEmpty()) {
|
---|
191 | text.append("Dataset consistency test: No problems found\n");
|
---|
192 | } else {
|
---|
193 | text.append("\nDataset consistency test:\n").append(result).append('\n');
|
---|
194 | }
|
---|
195 | }
|
---|
196 | text.append('\n');
|
---|
197 | appendCollection(text, "Plugins", Utils.transform(PluginHandler.getBugReportInformation(), i -> "+ " + i));
|
---|
198 | appendCollection(text, "Tagging presets", getCustomUrls(PresetPrefHelper.INSTANCE));
|
---|
199 | appendCollection(text, "Map paint styles", getCustomUrls(MapPaintPrefHelper.INSTANCE));
|
---|
200 | appendCollection(text, "Validator rules", getCustomUrls(ValidatorPrefHelper.INSTANCE));
|
---|
201 | appendCollection(text, "Last errors/warnings", Utils.transform(Logging.getLastErrorAndWarnings(), i -> "- " + i));
|
---|
202 |
|
---|
203 | String osmApi = OsmApi.getOsmApi().getServerUrl();
|
---|
204 | if (!Config.getUrls().getDefaultOsmApiUrl().equals(osmApi.trim())) {
|
---|
205 | text.append("OSM API: ").append(osmApi).append("\n\n");
|
---|
206 | }
|
---|
207 |
|
---|
208 | return text.toString();
|
---|
209 | }
|
---|
210 |
|
---|
211 | private static Collection<String> getCustomUrls(SourcePrefHelper helper) {
|
---|
212 | final Set<String> defaultUrls = helper.getDefault().stream()
|
---|
213 | .map(i -> i.url)
|
---|
214 | .collect(Collectors.toSet());
|
---|
215 | return helper.get().stream()
|
---|
216 | .filter(i -> !defaultUrls.contains(i.url))
|
---|
217 | .map(i -> (i.active ? "+ " : "- ") + i.url)
|
---|
218 | .collect(Collectors.toList());
|
---|
219 | }
|
---|
220 |
|
---|
221 | private static List<String> paramCleanup(Collection<String> params) {
|
---|
222 | return params.stream()
|
---|
223 | .map(ShowStatusReportAction::paramCleanup)
|
---|
224 | .collect(Collectors.toList());
|
---|
225 | }
|
---|
226 |
|
---|
227 | /**
|
---|
228 | * Fill map with anonymized name to the actual used path.
|
---|
229 | * @return map that maps shortened name to full directory path
|
---|
230 | */
|
---|
231 | static Map<String, String> getAnonimicDirectorySymbolMap() {
|
---|
232 | /** maps the anonymized name to the actual used path */
|
---|
233 | Map<String, String> map = new LinkedHashMap<>();
|
---|
234 | map.put(PlatformManager.isPlatformWindows() ? "%JAVA_HOME%" : "${JAVA_HOME}", getSystemEnv("JAVA_HOME"));
|
---|
235 | map.put("<java.home>", getSystemProperty("java.home"));
|
---|
236 | map.put("<josm.pref>", Config.getDirs().getPreferencesDirectory(false).toString());
|
---|
237 | map.put("<josm.userdata>", Config.getDirs().getUserDataDirectory(false).toString());
|
---|
238 | map.put("<josm.cache>", Config.getDirs().getCacheDirectory(false).toString());
|
---|
239 | map.put(PlatformManager.isPlatformWindows() ? "%UserProfile%" : "${HOME}", getSystemProperty("user.home"));
|
---|
240 | return map;
|
---|
241 | }
|
---|
242 |
|
---|
243 | /**
|
---|
244 | * Shortens and removes private informations from a parameter used for status report.
|
---|
245 | * @param param parameter to cleanup
|
---|
246 | * @return shortened/anonymized parameter
|
---|
247 | */
|
---|
248 | static String paramCleanup(String param) {
|
---|
249 | final String userName = getSystemProperty("user.name");
|
---|
250 | final String userNameAlt = "<user.name>";
|
---|
251 |
|
---|
252 | String val = param;
|
---|
253 | for (Entry<String, String> entry : getAnonimicDirectorySymbolMap().entrySet()) {
|
---|
254 | val = paramReplace(val, entry.getValue(), entry.getKey());
|
---|
255 | }
|
---|
256 | if (userName != null && userName.length() >= 3) {
|
---|
257 | val = paramReplace(val, userName, userNameAlt);
|
---|
258 | }
|
---|
259 | return val;
|
---|
260 | }
|
---|
261 |
|
---|
262 | private static String paramReplace(String str, String target, String replacement) {
|
---|
263 | return target == null ? str : str.replace(target, replacement);
|
---|
264 | }
|
---|
265 |
|
---|
266 | private static void appendCollection(StringBuilder text, String label, Collection<String> col) {
|
---|
267 | if (!col.isEmpty()) {
|
---|
268 | text.append(col.stream().map(o -> paramCleanup(o) + '\n')
|
---|
269 | .collect(Collectors.joining("", label + ":\n", "\n")));
|
---|
270 | }
|
---|
271 | }
|
---|
272 |
|
---|
273 | @Override
|
---|
274 | public void actionPerformed(ActionEvent e) {
|
---|
275 | StringBuilder text = new StringBuilder();
|
---|
276 | String reportHeader = getReportHeader();
|
---|
277 | text.append(reportHeader);
|
---|
278 |
|
---|
279 | Preferences.main().getAllSettings().forEach((key, setting) -> {
|
---|
280 | if ("file-open.history".equals(key)
|
---|
281 | || "download.overpass.query".equals(key)
|
---|
282 | || "download.overpass.queries".equals(key)
|
---|
283 | || key.contains("username")
|
---|
284 | || key.contains("password")
|
---|
285 | || key.contains("access-token")) {
|
---|
286 | // Remove sensitive information from status report
|
---|
287 | return;
|
---|
288 | }
|
---|
289 | text.append(paramCleanup(key))
|
---|
290 | .append('=')
|
---|
291 | .append(paramCleanup(setting.getValue().toString()))
|
---|
292 | .append('\n');
|
---|
293 | });
|
---|
294 |
|
---|
295 | DebugTextDisplay ta = new DebugTextDisplay(text.toString());
|
---|
296 |
|
---|
297 | ExtendedDialog ed = new ExtendedDialog(MainApplication.getMainFrame(),
|
---|
298 | tr("Status Report"),
|
---|
299 | tr("Copy to clipboard and close"), tr("Report bug"), tr("Close"));
|
---|
300 | ed.setButtonIcons("copy", "bug", "cancel");
|
---|
301 | ed.setContent(ta, false);
|
---|
302 | ed.setMinimumSize(new Dimension(380, 200));
|
---|
303 | ed.setPreferredSize(new Dimension(700, MainApplication.getMainFrame().getHeight()-50));
|
---|
304 |
|
---|
305 | switch (ed.showDialog().getValue()) {
|
---|
306 | case 1: ta.copyToClipboard(); break;
|
---|
307 | case 2: BugReportSender.reportBug(reportHeader); break;
|
---|
308 | default: // do nothing
|
---|
309 | }
|
---|
310 | GuiHelper.destroyComponents(ed, false);
|
---|
311 | }
|
---|
312 | }
|
---|