Ignore:
Timestamp:
2010-03-06T12:37:34+01:00 (15 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/plugins
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • 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.