| 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 | |
|---|
| 7 | import java.awt.Dimension; |
|---|
| 8 | import java.awt.event.ActionEvent; |
|---|
| 9 | import java.awt.event.KeyEvent; |
|---|
| 10 | import java.util.HashSet; |
|---|
| 11 | import java.util.Map; |
|---|
| 12 | import java.util.Map.Entry; |
|---|
| 13 | import java.util.Set; |
|---|
| 14 | |
|---|
| 15 | import javax.swing.JScrollPane; |
|---|
| 16 | import javax.swing.JTextArea; |
|---|
| 17 | |
|---|
| 18 | import org.openstreetmap.josm.Main; |
|---|
| 19 | import org.openstreetmap.josm.data.Preferences.Setting; |
|---|
| 20 | import org.openstreetmap.josm.data.Version; |
|---|
| 21 | import org.openstreetmap.josm.data.osm.DataSet; |
|---|
| 22 | import org.openstreetmap.josm.data.osm.DatasetConsistencyTest; |
|---|
| 23 | import org.openstreetmap.josm.gui.ExtendedDialog; |
|---|
| 24 | import org.openstreetmap.josm.plugins.PluginHandler; |
|---|
| 25 | import org.openstreetmap.josm.tools.Shortcut; |
|---|
| 26 | import org.openstreetmap.josm.tools.Utils; |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | /** |
|---|
| 30 | * @author xeen |
|---|
| 31 | * |
|---|
| 32 | * Opens a dialog with useful status information like version numbers for Java, JOSM and plugins |
|---|
| 33 | * Also includes preferences with stripped username and password |
|---|
| 34 | */ |
|---|
| 35 | public final class ShowStatusReportAction extends JosmAction { |
|---|
| 36 | public ShowStatusReportAction() { |
|---|
| 37 | super( |
|---|
| 38 | tr("Show Status Report"), |
|---|
| 39 | "clock", |
|---|
| 40 | tr("Show status report with useful information that can be attached to bugs"), |
|---|
| 41 | Shortcut.registerShortcut("help:showstatusreport", tr("Help: {0}", |
|---|
| 42 | tr("Show Status Report")), KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false); |
|---|
| 43 | |
|---|
| 44 | putValue("help", ht("/Action/ShowStatusReport")); |
|---|
| 45 | putValue("toolbar", "help/showstatusreport"); |
|---|
| 46 | Main.toolbar.register(this); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | public static String getReportHeader() |
|---|
| 50 | { |
|---|
| 51 | StringBuilder text = new StringBuilder(); |
|---|
| 52 | text.append(Version.getInstance().getReleaseAttributes()); |
|---|
| 53 | text.append("\n"); |
|---|
| 54 | text.append("Identification: " + Version.getInstance().getAgentString()); |
|---|
| 55 | text.append("\n"); |
|---|
| 56 | text.append("Memory Usage: "); |
|---|
| 57 | text.append(Runtime.getRuntime().totalMemory()/1024/1024); |
|---|
| 58 | text.append(" MB / "); |
|---|
| 59 | text.append(Runtime.getRuntime().maxMemory()/1024/1024); |
|---|
| 60 | text.append(" MB ("); |
|---|
| 61 | text.append(Runtime.getRuntime().freeMemory()/1024/1024); |
|---|
| 62 | text.append(" MB allocated, but free)"); |
|---|
| 63 | text.append("\n"); |
|---|
| 64 | text.append("Java version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor") + ", " + System.getProperty("java.vm.name")); |
|---|
| 65 | text.append("\n"); |
|---|
| 66 | text.append("Operating system: "+ System.getProperty("os.name")); |
|---|
| 67 | text.append("\n"); |
|---|
| 68 | DataSet dataset = Main.main.getCurrentDataSet(); |
|---|
| 69 | if (dataset != null) { |
|---|
| 70 | String result = DatasetConsistencyTest.runTests(dataset); |
|---|
| 71 | if (result.length() == 0) { |
|---|
| 72 | text.append("Dataset consistency test: No problems found\n"); |
|---|
| 73 | } else { |
|---|
| 74 | text.append("\nDataset consistency test:\n"+result+"\n"); |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | text.append("\n"); |
|---|
| 78 | text.append(PluginHandler.getBugReportText()); |
|---|
| 79 | text.append("\n"); |
|---|
| 80 | |
|---|
| 81 | return text.toString(); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | public void actionPerformed(ActionEvent e) { |
|---|
| 85 | StringBuilder text = new StringBuilder(); |
|---|
| 86 | text.append(getReportHeader()); |
|---|
| 87 | try { |
|---|
| 88 | Map<String, Setting> settings = Main.pref.getAllSettings(); |
|---|
| 89 | settings.remove("osm-server.username"); |
|---|
| 90 | settings.remove("osm-server.password"); |
|---|
| 91 | settings.remove("oauth.access-token.key"); |
|---|
| 92 | settings.remove("oauth.access-token.secret"); |
|---|
| 93 | Set<String> keys = new HashSet<String>(settings.keySet()); |
|---|
| 94 | for (String key : keys) { |
|---|
| 95 | if (key.startsWith("marker.show")) { |
|---|
| 96 | settings.remove(key); |
|---|
| 97 | } |
|---|
| 98 | } |
|---|
| 99 | for (Entry<String, Setting> entry : settings.entrySet()) { |
|---|
| 100 | text.append(entry.getKey()).append("=").append(entry.getValue().getValue().toString()).append("\n"); |
|---|
| 101 | } |
|---|
| 102 | } catch (Exception x) { |
|---|
| 103 | x.printStackTrace(); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | JTextArea ta = new JTextArea(text.toString()); |
|---|
| 107 | ta.setWrapStyleWord(true); |
|---|
| 108 | ta.setLineWrap(true); |
|---|
| 109 | ta.setEditable(false); |
|---|
| 110 | JScrollPane sp = new JScrollPane(ta); |
|---|
| 111 | |
|---|
| 112 | ExtendedDialog ed = new ExtendedDialog(Main.parent, |
|---|
| 113 | tr("Status Report"), |
|---|
| 114 | new String[] {tr("Copy to clipboard and close"), tr("Close") }); |
|---|
| 115 | ed.setButtonIcons(new String[] {"copy.png", "cancel.png" }); |
|---|
| 116 | ed.setContent(sp, false); |
|---|
| 117 | ed.setMinimumSize(new Dimension(500, 0)); |
|---|
| 118 | ed.showDialog(); |
|---|
| 119 | |
|---|
| 120 | if(ed.getValue() != 1) return; |
|---|
| 121 | Utils.copyToClipboard(text.toString()); |
|---|
| 122 | } |
|---|
| 123 | } |
|---|