Changeset 5723 in josm for trunk/src/org/openstreetmap/josm/plugins
- Timestamp:
- 2013-02-16T16:58:22+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/plugins
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
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.