- Timestamp:
- 2013-02-16T16:58:22+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java
r5631 r5723 45 45 import org.openstreetmap.josm.gui.preferences.plugin.PluginPreferencesModel; 46 46 import org.openstreetmap.josm.gui.preferences.plugin.PluginUpdatePolicyPanel; 47 import org.openstreetmap.josm.gui.util.GuiHelper; 47 48 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator; 48 49 import org.openstreetmap.josm.plugins.PluginDownloadTask; … … 303 304 304 305 protected void notifyDownloadResults(PluginDownloadTask task) { 305 Collection<PluginInformation> downloaded = task.getDownloadedPlugins();306 Collection<PluginInformation> failed = task.getFailedPlugins();307 StringBuilder sb = new StringBuilder();306 final Collection<PluginInformation> downloaded = task.getDownloadedPlugins(); 307 final Collection<PluginInformation> failed = task.getFailedPlugins(); 308 final StringBuilder sb = new StringBuilder(); 308 309 sb.append("<html>"); 309 310 sb.append(buildDownloadSummary(task)); … … 312 313 } 313 314 sb.append("</html>"); 314 HelpAwareOptionPane.showOptionDialog( 315 pnlPluginPreferences, 316 sb.toString(), 317 tr("Update plugins"), 318 !failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE, 319 HelpUtil.ht("/Preferences/Plugins") 320 ); 315 GuiHelper.runInEDTAndWait(new Runnable() { 316 @Override 317 public void run() { 318 HelpAwareOptionPane.showOptionDialog( 319 pnlPluginPreferences, 320 sb.toString(), 321 tr("Update plugins"), 322 !failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE, 323 HelpUtil.ht("/Preferences/Plugins") 324 ); 325 } 326 }); 321 327 } 322 328 … … 359 365 model.refreshLocalPluginVersion(pluginDownloadTask.getDownloadedPlugins()); 360 366 model.clearPendingPlugins(pluginDownloadTask.getDownloadedPlugins()); 361 pnlPluginPreferences.refreshView(); 367 GuiHelper.runInEDT(new Runnable() { 368 @Override 369 public void run() { 370 pnlPluginPreferences.refreshView(); } 371 }); 362 372 } 363 373 }; -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r5601 r5723 34 34 import java.util.concurrent.Executors; 35 35 import java.util.concurrent.Future; 36 import java.util.jar.JarFile; 36 37 37 38 import javax.swing.AbstractAction; … … 509 510 } 510 511 msg = null; 511 } catch(PluginException e) { 512 e.printStackTrace(); 512 } catch (PluginException e) { 513 System.err.print(e.getMessage()); 514 Throwable cause = e.getCause(); 515 if (cause != null) { 516 System.err.print(". " + cause.getClass().getName() + ": " + cause.getLocalizedMessage()); 517 } 518 System.err.println(); 513 519 if (e.getCause() instanceof ClassNotFoundException) { 514 520 msg = tr("<html>Could not load plugin {0} because the plugin<br>main class ''{1}'' was not found.<br>" … … 974 980 } 975 981 } 982 try { 983 // Check the plugin is a valid and accessible JAR file before installing it (fix #7754) 984 new JarFile(updatedPlugin).close(); 985 } catch (Exception e) { 986 if (dowarn) { 987 System.err.println(tr("Warning: failed to install plugin ''{0}'' from temporary download file ''{1}''. {2}", plugin.toString(), updatedPlugin.toString(), e.getLocalizedMessage())); 988 } 989 continue; 990 } 991 // Install plugin 976 992 if (!updatedPlugin.renameTo(plugin) && dowarn) { 977 993 System.err.println(tr("Warning: failed to install plugin ''{0}'' from temporary download file ''{1}''. Renaming failed.", plugin.toString(), updatedPlugin.toString())); … … 980 996 } 981 997 return; 998 } 999 1000 /** 1001 * Determines if the specified file is a valid and accessible JAR file. 1002 * @param jar The fil to check 1003 * @return true if file can be opened as a JAR file. 1004 * @since 5723 1005 */ 1006 public static boolean isValidJar(File jar) { 1007 if (jar != null && jar.exists() && jar.canRead()) { 1008 try { 1009 new JarFile(jar).close(); 1010 } catch (Exception e) { 1011 return false; 1012 } 1013 return true; 1014 } 1015 return false; 982 1016 } 983 1017 … … 991 1025 File pluginDir = Main.pref.getPluginsDirectory(); 992 1026 // Find the downloaded file. We have tried to install the downloaded plugins 993 // (PluginHandler.installDownloadedPlugins). This succeeds depending on the 994 // platform. 1027 // (PluginHandler.installDownloadedPlugins). This succeeds depending on the platform. 995 1028 File downloadedPluginFile = new File(pluginDir, name + ".jar.new"); 996 if (! (downloadedPluginFile.exists() && downloadedPluginFile.canRead())) {1029 if (!isValidJar(downloadedPluginFile)) { 997 1030 downloadedPluginFile = new File(pluginDir, name + ".jar"); 998 if (! (downloadedPluginFile.exists() && downloadedPluginFile.canRead())) {1031 if (!isValidJar(downloadedPluginFile)) { 999 1032 return null; 1000 1033 } -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r5601 r5723 75 75 /** 76 76 * Creates a plugin information object for the plugin with name {@code name}. 77 * Information about the plugin is extracted from the ma ifest file in the plugin jar77 * Information about the plugin is extracted from the manifest file in the plugin jar 78 78 * {@code file}. 79 79 * @param file the plugin jar … … 81 81 * @throws PluginException thrown if reading the manifest file fails 82 82 */ 83 public PluginInformation(File file, String name) throws PluginException{ 83 public PluginInformation(File file, String name) throws PluginException { 84 if (!PluginHandler.isValidJar(file)) { 85 throw new PluginException(name, tr("Invalid jar file ''{0}''", file)); 86 } 84 87 this.name = name; 85 88 this.file = file; … … 324 327 } catch (ClassNotFoundException e) { 325 328 throw new PluginException(name, e); 326 } catch (ClassCastException e) {329 } catch (ClassCastException e) { 327 330 throw new PluginException(name, e); 328 331 } -
trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java
r5601 r5723 28 28 * and extracts plugin information from three kind of files: 29 29 * <ul> 30 * <li>.jar -files, assuming that they represent plugin jars</li>31 * <li>.jar.new -files, assuming that these are downloaded but not yet installed plugins</li>30 * <li>.jar files, assuming that they represent plugin jars</li> 31 * <li>.jar.new files, assuming that these are downloaded but not yet installed plugins</li> 32 32 * <li>cached lists of available plugins, downloaded for instance from 33 33 * <a href="http://josm.openstreetmap.de/plugins">http://josm.openstreetmap.de/plugins</a></li> … … 147 147 processJarFile(f, pluginName); 148 148 } 149 } catch(PluginException e){ 149 } catch (PluginException e){ 150 System.err.println(e.getMessage()); 150 151 System.err.println(tr("Warning: Failed to scan file ''{0}'' for plugin information. Skipping.", fname)); 151 e.printStackTrace();152 152 } 153 153 monitor.worked(1);
Note:
See TracChangeset
for help on using the changeset viewer.