Changeset 5723 in josm for trunk/src


Ignore:
Timestamp:
2013-02-16T16:58:22+01:00 (11 years ago)
Author:
Don-vip
Message:

fix #7754 - plugin management: unable to activate plugin after aborted download + fix EDT violations

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java

    r5631 r5723  
    4545import org.openstreetmap.josm.gui.preferences.plugin.PluginPreferencesModel;
    4646import org.openstreetmap.josm.gui.preferences.plugin.PluginUpdatePolicyPanel;
     47import org.openstreetmap.josm.gui.util.GuiHelper;
    4748import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
    4849import org.openstreetmap.josm.plugins.PluginDownloadTask;
     
    303304
    304305        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();
    308309            sb.append("<html>");
    309310            sb.append(buildDownloadSummary(task));
     
    312313            }
    313314            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            });
    321327        }
    322328
     
    359365                    model.refreshLocalPluginVersion(pluginDownloadTask.getDownloadedPlugins());
    360366                    model.clearPendingPlugins(pluginDownloadTask.getDownloadedPlugins());
    361                     pnlPluginPreferences.refreshView();
     367                    GuiHelper.runInEDT(new Runnable() {
     368                        @Override
     369                        public void run() {
     370                            pnlPluginPreferences.refreshView();                        }
     371                    });
    362372                }
    363373            };
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r5601 r5723  
    3434import java.util.concurrent.Executors;
    3535import java.util.concurrent.Future;
     36import java.util.jar.JarFile;
    3637
    3738import javax.swing.AbstractAction;
     
    509510            }
    510511            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();
    513519            if (e.getCause() instanceof ClassNotFoundException) {
    514520                msg = tr("<html>Could not load plugin {0} because the plugin<br>main class ''{1}'' was not found.<br>"
     
    974980                }
    975981            }
     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
    976992            if (!updatedPlugin.renameTo(plugin) && dowarn) {
    977993                System.err.println(tr("Warning: failed to install plugin ''{0}'' from temporary download file ''{1}''. Renaming failed.", plugin.toString(), updatedPlugin.toString()));
     
    980996        }
    981997        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;
    9821016    }
    9831017   
     
    9911025        File pluginDir = Main.pref.getPluginsDirectory();
    9921026        // 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.
    9951028        File downloadedPluginFile = new File(pluginDir, name + ".jar.new");
    996         if (!(downloadedPluginFile.exists() && downloadedPluginFile.canRead())) {
     1029        if (!isValidJar(downloadedPluginFile)) {
    9971030            downloadedPluginFile = new File(pluginDir, name + ".jar");
    998             if (!(downloadedPluginFile.exists() && downloadedPluginFile.canRead())) {
     1031            if (!isValidJar(downloadedPluginFile)) {
    9991032                return null;
    10001033            }
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r5601 r5723  
    7575    /**
    7676     * Creates a plugin information object for the plugin with name {@code name}.
    77      * Information about the plugin is extracted from the maifest file in the plugin jar
     77     * Information about the plugin is extracted from the manifest file in the plugin jar
    7878     * {@code file}.
    7979     * @param file the plugin jar
     
    8181     * @throws PluginException thrown if reading the manifest file fails
    8282     */
    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        }
    8487        this.name = name;
    8588        this.file = file;
     
    324327        } catch (ClassNotFoundException e) {
    325328            throw new PluginException(name, e);
    326         } catch(ClassCastException e) {
     329        } catch (ClassCastException e) {
    327330            throw new PluginException(name, e);
    328331        }
  • trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java

    r5601 r5723  
    2828 * and extracts plugin information from three kind of files:
    2929 * <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>
    3232 *   <li>cached lists of available plugins, downloaded for instance from
    3333 *   <a href="http://josm.openstreetmap.de/plugins">http://josm.openstreetmap.de/plugins</a></li>
     
    147147                    processJarFile(f, pluginName);
    148148                }
    149             } catch(PluginException e){
     149            } catch (PluginException e){
     150                System.err.println(e.getMessage());
    150151                System.err.println(tr("Warning: Failed to scan file ''{0}'' for plugin information. Skipping.", fname));
    151                 e.printStackTrace();
    152152            }
    153153            monitor.worked(1);
Note: See TracChangeset for help on using the changeset viewer.