Changeset 1326 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2009-01-23T22:22:10+01:00 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r1271 r1326 30 30 import org.openstreetmap.josm.Main; 31 31 import org.openstreetmap.josm.actions.AboutAction; 32 import org.openstreetmap.josm.plugins.PluginException; 33 import org.openstreetmap.josm.plugins.PluginProxy; 32 import org.openstreetmap.josm.plugins.PluginHandler; 34 33 35 34 /** … … 41 40 42 41 public void uncaughtException(Thread t, Throwable e) { 42 handleException(e); 43 } 44 public static void handleException(Throwable e) { 43 45 e.printStackTrace(); 44 46 if (Main.parent != null) { … … 52 54 } 53 55 54 PluginProxy plugin = null; 55 56 // Check for an explicit problem when calling a plugin function 57 if (e instanceof PluginException) 58 plugin = ((PluginException)e).plugin; 59 60 if (plugin == null) 61 plugin = guessPlugin(e); 62 63 if (plugin != null) { 64 int answer = JOptionPane.showConfirmDialog( 65 Main.parent, tr("An unexpected exception occurred that may have come from the ''{0}'' plugin.", 66 plugin.info.name) + "\n"+ (plugin.info.author != null ? 67 tr("According to the information within the plugin, the author is {0}.", 68 plugin.info.author) : "") + "\n" + 69 tr("Try updating to the newest version of this plugin before reporting a bug.") + "\n" + 70 tr("Should the plugin be disabled?"), 71 tr("Disable plugin"), 72 JOptionPane.YES_NO_OPTION); 73 if (answer == JOptionPane.OK_OPTION) { 74 LinkedList<String> plugins = new LinkedList<String>(Arrays.asList(Main.pref.get("plugins").split(","))); 75 if (plugins.contains(plugin.info.name)) { 76 while (plugins.remove(plugin.info.name)) {} 77 String p = ""; 78 for (String s : plugins) 79 p += ","+s; 80 if (p.length() > 0) 81 p = p.substring(1); 82 Main.pref.put("plugins", p); 83 JOptionPane.showMessageDialog(Main.parent, 84 tr("The plugin has been removed from the configuration. Please restart JOSM to unload the plugin.")); 85 } else { 86 JOptionPane.showMessageDialog(Main.parent, 87 tr("The plugin could not be removed. Please tell the people you got JOSM from about the problem.")); 88 } 89 return; 90 } 91 } 56 if(PluginHandler.checkException(e)) 57 return; 92 58 93 59 Object[] options = new String[]{tr("Do nothing"), tr("Report Bug")}; … … 103 69 104 70 String text = AboutAction.getTextBlock(); 105 String pl = Main.pref.get("plugins");106 71 text += "Java version: " + System.getProperty("java.version")+"\n"; 107 if(pl != null && pl.length() != 0) 108 text += "Plugins: "+pl+"\n"; 109 for (final PluginProxy pp : Main.plugins) { 110 text += "Plugin " + pp.info.name + (pp.info.version != null && !pp.info.version.equals("") ? " Version: "+pp.info.version+"\n" : "\n"); 111 } 72 text += PluginHandler.getBugReportText(); 112 73 text += "\n" + stack.getBuffer().toString(); 113 74 … … 137 98 } 138 99 } 139 140 private PluginProxy guessPlugin(Throwable e) {141 String name = guessPluginName(e);142 for (PluginProxy p : Main.plugins)143 if (p.info.name.equals(name))144 return p;145 return null;146 }147 148 /**149 * Analyze the stack of the argument and return a name of a plugin, if150 * some known problem pattern has been found or <code>null</code>, if151 * the stack does not contain plugin-code.152 *153 * Note: This heuristic is not meant as discrimination against specific154 * plugins, but only to stop the flood of similar bug reports about plugins.155 * Of course, plugin writers are free to install their own version of156 * an exception handler with their email address listed to receive157 * bug reports ;-).158 */159 private String guessPluginName(Throwable e) {160 for (StackTraceElement element : e.getStackTrace()) {161 String c = element.getClassName();162 163 if (c.contains("wmsplugin.") || c.contains(".WMSLayer"))164 return "wmsplugin";165 if (c.contains("livegps."))166 return "livegps";167 if (c.startsWith("UtilsPlugin."))168 return "UtilsPlugin";169 170 if (c.startsWith("org.openstreetmap.josm.plugins.")) {171 String p = c.substring("org.openstreetmap.josm.plugins.".length());172 if (p.indexOf('.') != -1 && p.matches("[a-z].*")) {173 return p.substring(0,p.indexOf('.'));174 }175 }176 }177 return null;178 }179 100 }
Note:
See TracChangeset
for help on using the changeset viewer.