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