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