Ignore:
Timestamp:
2010-05-30T17:07:19+02:00 (14 years ago)
Author:
stoecker
Message:

fix #4706 and fix #5066 - plugin handling

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r3232 r3287  
    620620     * @throws IllegalArgumentException thrown if plugins is null
    621621     */
    622     public static void updatePlugins(Window parent, Collection<PluginInformation> plugins, ProgressMonitor monitor) throws IllegalArgumentException{
     622    public static List<PluginInformation>  updatePlugins(Window parent,
     623    List<PluginInformation> plugins, ProgressMonitor monitor)
     624    throws IllegalArgumentException{
    623625        CheckParameterUtil.ensureParameterNotNull(plugins, "plugins");
    624626        if (monitor == null) {
     
    638640            try {
    639641                future.get();
     642                plugins = buildListOfPluginsToLoad(parent,monitor.createSubTaskMonitor(1, false));
    640643            } catch(ExecutionException e) {
    641644                System.out.println(tr("Warning: failed to download plugin information list"));
     
    672675                    e.printStackTrace();
    673676                    alertFailedPluginUpdate(parent, pluginsToUpdate);
    674                     return;
     677                    return plugins;
    675678                } catch(InterruptedException e) {
    676679                    e.printStackTrace();
    677680                    alertFailedPluginUpdate(parent, pluginsToUpdate);
    678                     return;
     681                    return plugins;
    679682                }
    680683                // notify user if downloading a locally installed plugin failed
     
    682685                if (! task2.getFailedPlugins().isEmpty()) {
    683686                    alertFailedPluginUpdate(parent, task2.getFailedPlugins());
    684                     return;
     687                    return plugins;
    685688                }
    686689            }
     
    692695        Main.pref.putInteger("pluginmanager.version", Version.getInstance().getVersion());
    693696        Main.pref.put("pluginmanager.lastupdate", Long.toString(System.currentTimeMillis()));
     697        return plugins;
    694698    }
    695699
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r3090 r3287  
    351351     */
    352352    public boolean isUpdateRequired(String referenceVersion) {
     353        if (this.downloadlink == null) return false;
    353354        if (this.version == null && referenceVersion!= null)
    354355            return true;
     
    366367     */
    367368    public boolean isUpdateRequired() {
     369        if (this.downloadlink == null) return false;
    368370        if (this.localversion == null) return true;
    369371        return isUpdateRequired(this.localversion);
  • trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java

    r3130 r3287  
    6262        );
    6363        if (!availablePlugins.containsKey(info.getName())) {
     64            info.localversion = info.version;
    6465            availablePlugins.put(info.getName(), info);
    6566        } else {
     
    184185        Collection<String> pluginLocations = PluginInformation.getPluginLocations();
    185186        getProgressMonitor().setTicksCount(pluginLocations.size() + 2);
    186         if (canceled)return;
     187        if (canceled) return;
    187188        for (String location : pluginLocations) {
    188189            scanLocalPluginRepository(
  • trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java

    r3231 r3287  
    77import java.io.ByteArrayInputStream;
    88import java.io.File;
     9import java.io.FilenameFilter;
    910import java.io.FileOutputStream;
    1011import java.io.IOException;
     
    4344    private boolean canceled;
    4445    private HttpURLConnection connection;
    45     private List<PluginInformation> availabePlugins;
     46    private List<PluginInformation> availablePlugins;
    4647
    4748    protected void init(Collection<String> sites){
     
    5051            this.sites = Collections.emptySet();
    5152        }
    52         availabePlugins = new LinkedList<PluginInformation>();
     53        availablePlugins = new LinkedList<PluginInformation>();
    5354
    5455    }
     
    9495     * @return the file name for the cache file
    9596     */
    96     protected String createSiteCacheFileName(String site) {
     97    protected File createSiteCacheFile(File pluginDir, String site) {
     98        String name;
    9799        try {
    98100            URL url = new URL(site);
     
    113115            }
    114116            sb.append(".txt");
    115             return sb.toString();
     117            name = sb.toString();
    116118        } catch(MalformedURLException e) {
    117             return "site-unknown.txt";
    118         }
     119            name = "site-unknown.txt";
     120        }
     121        return new File(pluginDir, name);
    119122    }
    120123
     
    186189                }
    187190            }
    188             File cacheFile = new File(pluginDir, createSiteCacheFileName(site));
     191            File cacheFile = createSiteCacheFile(pluginDir, site);
    189192            getProgressMonitor().subTask(tr("Writing plugin list to local cache ''{0}''", cacheFile.toString()));
    190193            writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(cacheFile), "utf-8"));
     
    231234            InputStream in = new ByteArrayInputStream(doc.getBytes("UTF-8"));
    232235            List<PluginInformation> pis = new PluginListParser().parse(in);
    233             availabePlugins.addAll(filterDeprecatedPlugins(pis));
     236            availablePlugins.addAll(filterDeprecatedPlugins(pis));
    234237        } catch(UnsupportedEncodingException e) {
    235238            System.err.println(tr("Failed to parse plugin list document from site ''{0}''. Skipping site. Exception was: {1}", site, e.toString()));
     
    245248        if (sites == null) return;
    246249        getProgressMonitor().setTicksCount(sites.size() * 3);
     250        File pluginDir = Main.pref.getPluginsDirectory();
     251        List<File> siteCacheFiles = new LinkedList<File>();
     252        for (String location : PluginInformation.getPluginLocations()) {
     253            File [] f = new File(location).listFiles(
     254                new FilenameFilter() {
     255                    public boolean accept(File dir, String name) {
     256                        return name.matches("^([0-9]+-)?site.*\\.txt$");
     257                    }
     258                }
     259            );
     260            if(f != null && f.length > 0)
     261                siteCacheFiles.addAll(Arrays.asList(f));
     262        }
     263
    247264        for (String site: sites) {
    248265            getProgressMonitor().subTask(tr("Processing plugin list from site ''{0}''", site));
    249266            String list = downloadPluginList(site, getProgressMonitor().createSubTaskMonitor(0, false));
    250             if (canceled || list == null) return;
    251             getProgressMonitor().worked(1);
    252             cachePluginList(site, list);
    253267            if (canceled) return;
    254             getProgressMonitor().worked(1);
    255             parsePluginListDocument(site, list);
    256             if (canceled) return;
    257             getProgressMonitor().worked(1);
     268            if(list != null)
     269            {
     270                siteCacheFiles.remove(createSiteCacheFile(pluginDir, site));
     271                getProgressMonitor().worked(1);
     272                cachePluginList(site, list);
     273                if (canceled) return;
     274                getProgressMonitor().worked(1);
     275                parsePluginListDocument(site, list);
     276                if (canceled) return;
     277                getProgressMonitor().worked(1);
     278                if (canceled) return;
     279            }
     280        }
     281        for (File file: siteCacheFiles) /* remove old stuff or whole update process is broken */
     282        {
     283            file.delete();
    258284        }
    259285    }
     
    273299     */
    274300    public List<PluginInformation> getAvailabePlugins() {
    275         return availabePlugins;
     301        return availablePlugins;
    276302    }
    277303}
Note: See TracChangeset for help on using the changeset viewer.