Ticket #20563: 20563.patch

File 20563.patch, 9.0 KB (added by simon04, 5 years ago)
  • src/org/openstreetmap/josm/plugins/PluginInformation.java

    diff --git a/src/org/openstreetmap/josm/plugins/PluginInformation.java b/src/org/openstreetmap/josm/plugins/PluginInformation.java
    index b510cbd3b..dfae76790 100644
    a b import java.util.List;  
    1818import java.util.Locale;
    1919import java.util.Map;
    2020import java.util.Optional;
    21 import java.util.TreeMap;
    2221import java.util.jar.Attributes;
    2322import java.util.jar.JarInputStream;
    2423import java.util.jar.Manifest;
    public class PluginInformation {  
    9392    /** The libraries referenced in Class-Path manifest attribute. */
    9493    public List<URL> libraries = new LinkedList<>();
    9594    /** All manifest attributes. */
    96     public final Map<String, String> attr = new TreeMap<>();
     95    public Attributes attr;
    9796    /** Invalid manifest entries */
    9897    final List<String> invalidManifestEntries = new ArrayList<>();
    9998    /** Empty icon for these plugins which have none */
    public class PluginInformation {  
    133132            Manifest manifest = jar.getManifest();
    134133            if (manifest == null)
    135134                throw new PluginException(tr("The plugin file ''{0}'' does not include a Manifest.", file.toString()));
    136             scanManifest(manifest, false);
     135            scanManifest(manifest.getMainAttributes(), false);
    137136            libraries.add(0, Utils.fileToURL(file));
    138137        } catch (IOException | InvalidPathException e) {
    139138            throw new PluginException(name, e);
    public class PluginInformation {  
    150149     * @throws PluginException if the plugin information can't be read from the input stream
    151150     */
    152151    public PluginInformation(InputStream manifestStream, String name, String url) throws PluginException {
    153         this.name = name;
    154152        try {
    155153            Manifest manifest = new Manifest();
    156154            manifest.read(manifestStream);
    157155            if (url != null) {
    158156                downloadlink = url;
    159157            }
    160             scanManifest(manifest, url != null);
     158            scanManifest(manifest.getMainAttributes(), url != null);
    161159        } catch (IOException e) {
    162160            throw new PluginException(name, e);
    163161        }
    164162    }
    165163
     164    /**
     165     * Creates a plugin information object by reading plugin information in Manifest format
     166     * from the input stream {@code manifestStream}.
     167     *
     168     * @param attr the manifest attributes
     169     * @param name the plugin name
     170     * @param url the download URL for the plugin
     171     * @throws PluginException if the plugin information can't be read from the input stream
     172     */
     173    public PluginInformation(Attributes attr, String name, String url) throws PluginException {
     174        this.name = name;
     175        if (url != null) {
     176            downloadlink = url;
     177        }
     178        scanManifest(attr, url != null);
     179    }
     180
    166181    /**
    167182     * Updates the plugin information of this plugin information object with the
    168183     * plugin information in a plugin information object retrieved from a plugin
    public class PluginInformation {  
    188203        this.iconPath = other.iconPath;
    189204        this.canloadatruntime = other.canloadatruntime;
    190205        this.libraries = other.libraries;
    191         this.attr.clear();
    192         this.attr.putAll(other.attr);
     206        this.attr = new Attributes(other.attr);
    193207        this.invalidManifestEntries.clear();
    194208        this.invalidManifestEntries.addAll(other.invalidManifestEntries);
    195209    }
    public class PluginInformation {  
    214228        this.file = other.file;
    215229    }
    216230
    217     private void scanManifest(Manifest manifest, boolean oldcheck) {
     231    private void scanManifest(Attributes attr, boolean oldcheck) {
    218232        String lang = LanguageInfo.getLanguageCodeManifest();
    219         Attributes attr = manifest.getMainAttributes();
    220233        className = attr.getValue("Plugin-Class");
    221234        String s = Optional.ofNullable(attr.getValue(lang+"Plugin-Link")).orElseGet(() -> attr.getValue("Plugin-Link"));
    222235        if (s != null && !Utils.isValidUrl(s)) {
    public class PluginInformation {  
    317330                libraries.add(Utils.fileToURL(entryFile));
    318331            }
    319332        }
    320         for (Object o : attr.keySet()) {
    321             this.attr.put(o.toString(), attr.getValue(o.toString()));
    322         }
     333        this.attr = attr;
    323334    }
    324335
    325336    /**
  • src/org/openstreetmap/josm/plugins/PluginListParser.java

    diff --git a/src/org/openstreetmap/josm/plugins/PluginListParser.java b/src/org/openstreetmap/josm/plugins/PluginListParser.java
    index 4009e0221..e7a050e92 100644
    a b import java.io.InputStreamReader;  
    1111import java.nio.charset.StandardCharsets;
    1212import java.util.LinkedList;
    1313import java.util.List;
     14import java.util.jar.Attributes;
    1415
    1516import org.openstreetmap.josm.tools.Logging;
    1617
    public class PluginListParser {  
    2930     *
    3031     * @param name the plugin name
    3132     * @param url the plugin download url
    32      * @param manifest the plugin manifest
     33     * @param manifest the plugin manifest attributes
    3334     * @return a plugin information object
    3435     * @throws PluginListParseException if plugin manifest cannot be parsed
    3536     */
    36     public static PluginInformation createInfo(String name, String url, String manifest) throws PluginListParseException {
     37    public static PluginInformation createInfo(String name, String url, Attributes manifest) throws PluginListParseException {
    3738        try {
    3839            return new PluginInformation(
    39                     new ByteArrayInputStream(manifest.getBytes(StandardCharsets.UTF_8)),
     40                    manifest,
    4041                    name.substring(0, name.length() - 4),
    4142                    url
    4243                    );
    public class PluginListParser {  
    6162        try (BufferedReader r = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) {
    6263            String name = null;
    6364            String url = null;
    64             StringBuilder manifest = new StringBuilder();
     65            Attributes manifest = new Attributes();
    6566            for (String line = r.readLine(); line != null; line = r.readLine()) {
    6667                if (line.startsWith("\t")) {
    67                     line = line.substring(1);
    68                     /* NOTE: Although manifest specification says line should not be longer than 72 bytes it
    69                        supports more than 500 bytes and thus even the longest possible 72 character UTF-8, so
    70                        this code correctly splits the text at 70 characters, not bytes. */
    71                     while (line.length() > 70) {
    72                         manifest.append(line.substring(0, 70)).append('\n');
    73                         line = ' ' + line.substring(70);
    74                     }
    75                     manifest.append(line).append('\n');
     68                    final String[] keyValue = line.split("\\s*:\\s*", 2);
     69                    manifest.put(new Attributes.Name(keyValue[0].substring(1)), keyValue[1]);
    7670                    continue;
    7771                }
    78                 addPluginInformation(ret, name, url, manifest.toString());
     72                addPluginInformation(ret, name, url, manifest);
    7973                String[] x = line.split(";", -1);
    8074                if (x.length != 2)
    8175                    throw new IOException(tr("Illegal entry in plugin list.") + " " + line);
    8276                name = x[0];
    8377                url = x[1];
    84                 manifest = new StringBuilder();
     78                manifest = new Attributes();
    8579            }
    86             addPluginInformation(ret, name, url, manifest.toString());
     80            addPluginInformation(ret, name, url, manifest);
    8781            return ret;
    8882        } catch (IOException e) {
    8983            throw new PluginListParseException(e);
    9084        }
    9185    }
    9286
    93     private static void addPluginInformation(List<PluginInformation> ret, String name, String url, String manifest) {
     87    private static void addPluginInformation(List<PluginInformation> ret, String name, String url, Attributes manifest) {
    9488        try {
    9589            if (name != null) {
    9690                PluginInformation info = createInfo(name, url, manifest);
  • test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java

    diff --git a/test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java b/test/unit/org/openstreetmap/josm/gui/MainApplicationTest.java
    index 14a922b3b..51fdfb44b 100644
    a b import java.util.Collection;  
    2121import java.util.List;
    2222import java.util.concurrent.ExecutionException;
    2323import java.util.concurrent.Future;
     24import java.util.jar.Attributes;
    2425
    2526import javax.swing.JComponent;
    2627import javax.swing.JPanel;
    public class MainApplicationTest {  
    204205
    205206    private static PluginInformation newPluginInformation(String plugin) throws PluginListParseException {
    206207        return PluginListParser.createInfo(plugin+".jar", "https://josm.openstreetmap.de/osmsvn/applications/editors/josm/dist/"+plugin+".jar",
    207                 "");
     208                new Attributes());
    208209    }
    209210
    210211    /**