Changeset 3090 in josm


Ignore:
Timestamp:
2010-03-06T12:37:34+01:00 (14 years ago)
Author:
Gubaer
Message:

fixed #4443: Plugins with known update site: Don't download unless a new version is available
fixed #4565: local version differs from local version of updated plugin (was: local version number lost, after update plugin list.)

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

Legend:

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

    r3088 r3090  
    1717import java.util.Collection;
    1818import java.util.Collections;
     19import java.util.Iterator;
    1920import java.util.LinkedList;
    2021import java.util.List;
     
    7778            sb.append("<ul>");
    7879            for(PluginInformation pi: downloaded) {
    79                 sb.append("<li>").append(pi.name).append("</li>");
     80                sb.append("<li>").append(pi.name).append(" (").append(pi.version).append(")").append("</li>");
    8081            }
    8182            sb.append("</ul>");
     
    283284                    SwingUtilities.invokeLater(new Runnable() {
    284285                        public void run() {
    285                             model.setAvailablePlugins(task.getAvailabePlugins());
     286                            model.updateAvailablePlugins(task.getAvailabePlugins());
    286287                            pnlPluginPreferences.refreshView();
    287 
    288288                        }
    289289                    });
     
    320320                    sb.toString(),
    321321                    tr("Update plugins"),
    322                     failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE,
     322                    !failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE,
    323323                            // FIXME: check help topic
    324324                            HelpUtil.ht("/Preferences/Plugin")
     
    326326        }
    327327
     328        protected void alertNothingToUpdate() {
     329            HelpAwareOptionPane.showOptionDialog(
     330                    pnlPluginPreferences,
     331                    tr("All installed plugins are up to date. JOSM does not have to download newer versions."),
     332                    tr("Plugins up to date"),
     333                    JOptionPane.INFORMATION_MESSAGE,
     334                    null // FIXME: provide help context
     335            );
     336        }
     337
    328338        public void actionPerformed(ActionEvent e) {
    329             List<PluginInformation> toUpdate = model.getSelectedPlugins();
     339            final List<PluginInformation> toUpdate = model.getSelectedPlugins();
    330340            // the async task for downloading plugins
    331341            final PluginDownloadTask pluginDownloadTask = new PluginDownloadTask(
     
    345355                    notifyDownloadResults(pluginDownloadTask);
    346356                    model.refreshLocalPluginVersion(pluginDownloadTask.getDownloadedPlugins());
     357                    model.clearPendingPlugins(pluginDownloadTask.getDownloadedPlugins());
    347358                    pnlPluginPreferences.refreshView();
    348359                }
     
    355366                    if (pluginInfoDownloadTask.isCanceled())
    356367                        return;
     368                    model.updateAvailablePlugins(pluginInfoDownloadTask.getAvailabePlugins());
     369                    // select plugins which actually have to be updated
     370                    //
     371                    Iterator<PluginInformation> it = toUpdate.iterator();
     372                    while(it.hasNext()) {
     373                        PluginInformation pi = it.next();
     374                        if (!pi.isUpdateRequired()) {
     375                            it.remove();
     376                        }
     377                    }
     378                    if (toUpdate.isEmpty()) {
     379                        alertNothingToUpdate();
     380                        return;
     381                    }
     382                    pluginDownloadTask.setPluginsToDownload(toUpdate);
    357383                    Main.worker.submit(pluginDownloadTask);
    358384                    Main.worker.submit(pluginDownloadContinuation);
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferencesModel.java

    r3083 r3090  
    7474    }
    7575
     76    protected  void updateAvailablePlugin(PluginInformation other) {
     77        if (other == null) return;
     78        PluginInformation pi = getPluginInformation(other.name);
     79        if (pi == null) {
     80            availablePlugins.add(other);
     81            return;
     82        }
     83        pi.updateFromPluginSite(other);
     84    }
     85
     86    /**
     87     * Updates the list of plugin information objects with new information from
     88     * plugin update sites.
     89     *
     90     * @param fromPluginSite plugin information read from plugin update sites
     91     */
     92    public void updateAvailablePlugins(Collection<PluginInformation> fromPluginSite) {
     93        for (PluginInformation other: fromPluginSite) {
     94            updateAvailablePlugin(other);
     95        }
     96        sort();
     97        filterDisplayedPlugins(filterExpression);
     98        Set<String> activePlugins = new HashSet<String>();
     99        activePlugins.addAll(Main.pref.getCollection("plugins", activePlugins));
     100        for (PluginInformation pi: availablePlugins) {
     101            if (selectedPluginsMap.get(pi) == null) {
     102                if (activePlugins.contains(pi.name)) {
     103                    selectedPluginsMap.put(pi, true);
     104                }
     105            }
     106        }
     107        clearChanged();
     108        notifyObservers();
     109    }
     110
    76111    /**
    77112     * Replies the list of selected plugin information objects
     
    113148                new Comparator<PluginInformation>() {
    114149                    public int compare(PluginInformation o1, PluginInformation o2) {
    115                         String n1 = o1.getName() == null ? "" : o1.getName();
    116                         String n2 = o2.getName() == null ? "" : o2.getName();
     150                        String n1 = o1.getName() == null ? "" : o1.getName().toLowerCase();
     151                        String n2 = o2.getName() == null ? "" : o2.getName().toLowerCase();
    117152                        return n1.compareTo(n2);
    118153                    }
     
    164199        if (!selected) {
    165200            pendingDownloads.remove(name);
     201        }
     202    }
     203
     204    /**
     205     * Removes all the plugin in {@code plugins} from the list of plugins
     206     * with a pending download
     207     *
     208     * @param plugins the list of plugins to clear for a pending download
     209     */
     210    public void clearPendingPlugins(Collection<PluginInformation> plugins){
     211        if (plugins == null || plugins.isEmpty()) return;
     212        for(PluginInformation pi: plugins) {
     213            pendingDownloads.remove(pi.name);
    166214        }
    167215    }
  • trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java

    r3083 r3090  
    3838    private static final Logger logger = Logger.getLogger(PluginDownloadTask.class.getName());
    3939
    40     private final Collection<PluginInformation> toUpdate;
     40    private final Collection<PluginInformation> toUpdate = new LinkedList<PluginInformation>();
    4141    private final Collection<PluginInformation> failed = new LinkedList<PluginInformation>();
    4242    private final Collection<PluginInformation> downloaded = new LinkedList<PluginInformation>();
     
    5656        super(parent, title == null ? "" : title, false /* don't ignore exceptions */);
    5757        CheckParameterUtil.ensureParameterNotNull(toUpdate, "toUpdate");
    58         this.toUpdate = toUpdate;
     58        this.toUpdate.addAll(toUpdate);
    5959    }
    6060
     
    7070        super(title, monitor == null? NullProgressMonitor.INSTANCE: monitor, false /* don't ignore exceptions */);
    7171        CheckParameterUtil.ensureParameterNotNull(toUpdate, "toUpdate");
    72         this.toUpdate = toUpdate;
     72        this.toUpdate.addAll(toUpdate);
     73    }
     74
     75    /**
     76     * Sets the collection of plugins to update.
     77     *
     78     * @param toUpdate the collection of plugins to update. Must not be null.
     79     * @throws IllegalArgumentException thrown if toUpdate is null
     80     */
     81    public void setPluginsToDownload(Collection<PluginInformation> toUpdate) throws IllegalArgumentException{
     82        CheckParameterUtil.ensureParameterNotNull(toUpdate, "toUpdate");
     83        this.toUpdate.clear();
     84        this.toUpdate.addAll(toUpdate);
    7385    }
    7486
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r3086 r3090  
    382382                pluginList.add(plugin.load(klass));
    383383            }
    384         } catch (Throwable e) {
     384        } catch(PluginException e) {
     385            if (e.getCause() instanceof ClassNotFoundException) {
     386                e.printStackTrace();
     387                String msg = tr("<html>Could not load plugin {0} because the plugin<br>main class ''{1}'' was not found.<br>"
     388                        + "Delete from preferences?", plugin.name, plugin.className);
     389                if (confirmDisablePlugin(parent, msg, plugin.name)) {
     390                    Main.pref.removeFromCollection("plugins", plugin.name);
     391                }
     392            }
     393        }  catch (Throwable e) {
    385394            e.printStackTrace();
    386395            String msg = tr("Could not load plugin {0}. Delete from preferences?", plugin.name);
     
    639648            }
    640649
    641             // try to update the locally installed plugins
     650            // filter plugins which actually have to be updated
    642651            //
    643             PluginDownloadTask task2 = new PluginDownloadTask(
    644                     monitor.createSubTaskMonitor(1,false),
    645                     plugins,
    646                     tr("Update plugins")
    647             );
    648 
    649             future = service.submit(task2);
    650             try {
    651                 future.get();
    652             } catch(ExecutionException e) {
    653                 e.printStackTrace();
    654                 alertFailedPluginUpdate(parent, plugins);
    655                 return;
    656             } catch(InterruptedException e) {
    657                 e.printStackTrace();
    658                 alertFailedPluginUpdate(parent, plugins);
    659                 return;
    660             }
    661             // notify user if downloading a locally installed plugin failed
    662             //
    663             if (! task2.getFailedPlugins().isEmpty()) {
    664                 alertFailedPluginUpdate(parent, task2.getFailedPlugins());
    665                 return;
     652            Iterator<PluginInformation> it = plugins.iterator();
     653            while(it.hasNext()) {
     654                PluginInformation pi = it.next();
     655                if (!pi.isUpdateRequired()) {
     656                    it.remove();
     657                }
     658            }
     659
     660            if (!plugins.isEmpty()) {
     661                // try to update the locally installed plugins
     662                //
     663                PluginDownloadTask task2 = new PluginDownloadTask(
     664                        monitor.createSubTaskMonitor(1,false),
     665                        plugins,
     666                        tr("Update plugins")
     667                );
     668
     669                future = service.submit(task2);
     670                try {
     671                    future.get();
     672                } catch(ExecutionException e) {
     673                    e.printStackTrace();
     674                    alertFailedPluginUpdate(parent, plugins);
     675                    return;
     676                } catch(InterruptedException e) {
     677                    e.printStackTrace();
     678                    alertFailedPluginUpdate(parent, plugins);
     679                    return;
     680                }
     681                // notify user if downloading a locally installed plugin failed
     682                //
     683                if (! task2.getFailedPlugins().isEmpty()) {
     684                    alertFailedPluginUpdate(parent, task2.getFailedPlugins());
     685                    return;
     686                }
    666687            }
    667688        } finally {
     
    744765     * ".jar" files.
    745766     *
     767     * If {@code dowarn} is true, this methods emits warning messages on the console if a downloaded
     768     * but not yet installed plugin .jar can't be be installed. If {@code dowarn} is false, the
     769     * installation of the respective plugin is sillently skipped.
     770     *
     771     * @param dowarn if true, warning messages are displayed; false otherwise
    746772     */
    747773    public static void installDownloadedPlugins(boolean dowarn) {
     
    760786            String pluginName = updatedPlugin.getName().substring(0, updatedPlugin.getName().length() - 8);
    761787            if (plugin.exists()) {
    762                 if (!plugin.delete() && !dowarn) {
     788                if (!plugin.delete() && dowarn) {
    763789                    System.err.println(tr("Warning: failed to delete outdated plugin ''{0}''.", plugin.toString()));
    764790                    System.err.println(tr("Warning: failed to install already downloaded plugin ''{0}''. Skipping installation. JOSM is still going to load the old plugin version.", pluginName));
     
    766792                }
    767793            }
    768             if (!updatedPlugin.renameTo(plugin) && !dowarn) {
     794            if (!updatedPlugin.renameTo(plugin) && dowarn) {
    769795                System.err.println(tr("Warning: failed to install plugin ''{0}'' from temporary download file ''{1}''. Renaming failed.", plugin.toString(), updatedPlugin.toString()));
    770796                System.err.println(tr("Warning: failed to install already downloaded plugin ''{0}''. Skipping installation. JOSM is still going to load the old plugin version.", pluginName));
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r3070 r3090  
    4848    public String downloadlink = null;
    4949    public List<URL> libraries = new LinkedList<URL>();
    50 
    5150    public final Map<String, String> attr = new TreeMap<String, String>();
    5251
    5352    /**
    54      * @param file the plugin jar file.
     53     * Creates a plugin information object by reading the plugin information from
     54     * the manifest in the plugin jar.
     55     *
     56     * The plugin name is derived from the file name.
     57     *
     58     * @param file the plugin jar file
     59     * @throws PluginException if reading the manifest fails
    5560     */
    5661    public PluginInformation(File file) throws PluginException{
     
    5863    }
    5964
     65    /**
     66     * Creates a plugin information object for the plugin with name {@code name}.
     67     * Information about the plugin is extracted from the maifest file in the the plugin jar
     68     * {@code file}.
     69     * @param file the plugin jar
     70     * @param name the plugin name
     71     * @throws PluginException thrown if reading the manifest file fails
     72     */
    6073    public PluginInformation(File file, String name) throws PluginException{
    6174        this.name = name;
     
    8093    }
    8194
     95    /**
     96     * Creates a plugin information object by reading plugin information in Manifest format
     97     * from the input stream {@code manifestStream}.
     98     *
     99     * @param manifestStream the stream to read the manifest from
     100     * @param name the plugin name
     101     * @param url the download URL for the plugin
     102     * @throws PluginException thrown if the plugin information can't be read from the input stream
     103     */
    82104    public PluginInformation(InputStream manifestStream, String name, String url) throws PluginException {
    83105        this.name = name;
     
    94116    }
    95117
    96     private void scanManifest(Manifest manifest, boolean oldcheck)
    97     {
     118    /**
     119     * Updates the plugin information of this plugin information object with the
     120     * plugin information in a plugin information object retrieved from a plugin
     121     * update site.
     122     *
     123     * @param other the plugin information object retrieved from the update
     124     * site
     125     */
     126    public void updateFromPluginSite(PluginInformation other) {
     127        this.mainversion = other.mainversion;
     128        this.className = other.className;
     129        this.requires = other.requires;
     130        this.link = other.link;
     131        this.description = other.description;
     132        this.early = other.early;
     133        this.author = other.author;
     134        this.stage = other.stage;
     135        this.version = other.version;
     136        this.downloadlink = other.downloadlink;
     137        this.libraries = other.libraries;
     138        this.attr.clear();
     139        this.attr.putAll(other.attr);
     140    }
     141
     142    private void scanManifest(Manifest manifest, boolean oldcheck){
    98143        String lang = LanguageInfo.getLanguageCodeManifest();
    99144        Attributes attr = manifest.getMainAttributes();
Note: See TracChangeset for help on using the changeset viewer.