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