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

Last change on this file since 14671 was 14671, checked in by simon04, 5 years ago

Status report: exclude file history, Overpass queries

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