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