Changeset 1767 in josm


Ignore:
Timestamp:
Jul 11, 2009 2:52:02 PM (4 years ago)
Author:
stoecker
Message:

fix #2859 - better plugin support for older versions

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

Legend:

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

    r1755 r1767  
    1515import java.util.List; 
    1616import java.util.Map; 
     17import java.util.Set; 
    1718import java.util.TreeMap; 
    1819import java.util.jar.Attributes; 
     
    2122 
    2223import org.openstreetmap.josm.Main; 
     24import org.openstreetmap.josm.actions.AboutAction; 
    2325import org.openstreetmap.josm.tools.LanguageInfo; 
    2426 
     
    3436    public int mainversion = 0; 
    3537    public String className = null; 
     38    public boolean oldmode = false; 
    3639    public String requires = null; 
    3740    public String link = null; 
     
    7073            if (manifest == null) 
    7174                throw new IOException(file+" contains no manifest."); 
    72             scanManifest(manifest); 
     75            scanManifest(manifest, false); 
    7376            libraries.add(0, fileToURL(file)); 
    7477            jar.close(); 
     
    7881    } 
    7982 
    80     public PluginInformation(InputStream manifestStream, String name) { 
     83    public PluginInformation(InputStream manifestStream, String name, String url) { 
    8184        this.name = name; 
    8285        try { 
    8386            Manifest manifest = new Manifest(); 
    8487            manifest.read(manifestStream); 
    85             scanManifest(manifest); 
     88            if(url != null) 
     89                downloadlink = url; 
     90            scanManifest(manifest, url != null); 
    8691        } catch (IOException e) { 
    8792            throw new PluginException(null, name, e); 
     
    8994    } 
    9095 
    91     private void scanManifest(Manifest manifest) 
     96    private void scanManifest(Manifest manifest, boolean oldcheck) 
    9297    { 
    9398        String lang = LanguageInfo.getLanguageCodeManifest(); 
     
    114119        catch(NumberFormatException e) {} 
    115120        author = attr.getValue("Author"); 
     121        if(oldcheck && mainversion > AboutAction.getVersionNumber()) 
     122        { 
     123            int myv = AboutAction.getVersionNumber(); 
     124            for(Map.Entry entry : attr.entrySet()) 
     125            { 
     126                try { 
     127                    String key = ((Attributes.Name)entry.getKey()).toString(); 
     128                    if(key.endsWith("_Plugin-Url")) 
     129                    { 
     130                        int mv = Integer.parseInt(key.substring(0,key.length()-11)); 
     131                        if(mv <= myv && (mv > mainversion || mainversion > myv)) 
     132                        { 
     133                            String v = (String)entry.getValue(); 
     134                            int i = v.indexOf(";"); 
     135                            if(i > 0) 
     136                            { 
     137                                downloadlink = v.substring(i+1); 
     138                                mainversion = mv; 
     139                                version = v.substring(0,i); 
     140                                oldmode = true; 
     141                            } 
     142                        } 
     143                    } 
     144                } 
     145                catch(Exception e) { e.printStackTrace(); } 
     146            } 
     147        } 
    116148 
    117149        String classPath = attr.getValue(Attributes.Name.CLASS_PATH); 
     
    213245        InputStream manifestStream = PluginInformation.class.getResourceAsStream("/org/openstreetmap/josm/plugins/"+name+"/MANIFEST.MF"); 
    214246        if (manifestStream != null) 
    215             return new PluginInformation(manifestStream, pluginName); 
     247            return new PluginInformation(manifestStream, pluginName, null); 
    216248 
    217249        Collection<String> locations = getPluginLocations(); 
  • trunk/src/org/openstreetmap/josm/plugins/PluginSelection.java

    r1739 r1767  
    168168            if ((remoteversion == null) || remoteversion.equals("")) 
    169169                remoteversion = tr("unknown"); 
     170            else if(plugin.oldmode) 
     171                remoteversion += "*"; 
    170172 
    171173            String localversion = ""; 
     
    284286                                            PluginInformation info = new PluginInformation( 
    285287                                            new ByteArrayInputStream(manifest.getBytes("utf-8")), 
    286                                             name.substring(0,name.length()-4)); 
    287                                             info.downloadlink = url; 
     288                                            name.substring(0,name.length()-4), url); 
    288289                                            if(!availablePlugins.containsKey(info.name)) 
    289290                                                availablePlugins.put(info.name, info); 
     
    305306                                PluginInformation info = new PluginInformation( 
    306307                                new ByteArrayInputStream(manifest.getBytes("utf-8")), 
    307                                 name.substring(0,name.length()-4)); 
    308                                 info.downloadlink = url; 
     308                                name.substring(0,name.length()-4), url); 
    309309                                if(!availablePlugins.containsKey(info.name)) 
    310310                                    availablePlugins.put(info.name, info); 
Note: See TracChangeset for help on using the changeset viewer.