Changeset 17571 in josm for trunk/src/org
- Timestamp:
- 2021-03-16T21:56:57+01:00 (4 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/plugins
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r17562 r17571 185 185 public String getText() { 186 186 StringBuilder b = new StringBuilder(); 187 for (Entry< String, String> e : info.attr.entrySet()) {187 for (Entry<Object, Object> e : info.attr.entrySet()) { 188 188 b.append(e.getKey()); 189 189 b.append(": "); -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r16874 r17571 19 19 import java.util.Map; 20 20 import java.util.Optional; 21 import java.util.TreeMap;22 21 import java.util.jar.Attributes; 23 22 import java.util.jar.JarInputStream; … … 94 93 public List<URL> libraries = new LinkedList<>(); 95 94 /** All manifest attributes. */ 96 public final Map<String, String> attr = new TreeMap<>();95 public Attributes attr; 97 96 /** Invalid manifest entries */ 98 97 final List<String> invalidManifestEntries = new ArrayList<>(); … … 134 133 if (manifest == null) 135 134 throw new PluginException(tr("The plugin file ''{0}'' does not include a Manifest.", file.toString())); 136 scanManifest(manifest , false);135 scanManifest(manifest.getMainAttributes(), false); 137 136 libraries.add(0, Utils.fileToURL(file)); 138 137 } catch (IOException | InvalidPathException e) { … … 151 150 */ 152 151 public PluginInformation(InputStream manifestStream, String name, String url) throws PluginException { 153 this.name = name;154 152 try { 155 153 Manifest manifest = new Manifest(); … … 158 156 downloadlink = url; 159 157 } 160 scanManifest(manifest , url != null);158 scanManifest(manifest.getMainAttributes(), url != null); 161 159 } catch (IOException e) { 162 160 throw new PluginException(name, e); 163 161 } 162 } 163 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); 164 179 } 165 180 … … 189 204 this.canloadatruntime = other.canloadatruntime; 190 205 this.libraries = other.libraries; 191 this.attr.clear(); 192 this.attr.putAll(other.attr); 206 this.attr = new Attributes(other.attr); 193 207 this.invalidManifestEntries.clear(); 194 208 this.invalidManifestEntries.addAll(other.invalidManifestEntries); … … 215 229 } 216 230 217 private void scanManifest( Manifest manifest, boolean oldcheck) {231 private void scanManifest(Attributes attr, boolean oldcheck) { 218 232 String lang = LanguageInfo.getLanguageCodeManifest(); 219 Attributes attr = manifest.getMainAttributes();220 233 className = attr.getValue("Plugin-Class"); 221 234 String s = Optional.ofNullable(attr.getValue(lang+"Plugin-Link")).orElseGet(() -> attr.getValue("Plugin-Link")); … … 318 331 } 319 332 } 320 for (Object o : attr.keySet()) { 321 this.attr.put(o.toString(), attr.getValue(o.toString())); 322 } 333 this.attr = attr; 323 334 } 324 335 -
trunk/src/org/openstreetmap/josm/plugins/PluginListParser.java
r16643 r17571 5 5 6 6 import java.io.BufferedReader; 7 import java.io.ByteArrayInputStream;8 7 import java.io.IOException; 9 8 import java.io.InputStream; … … 12 11 import java.util.LinkedList; 13 12 import java.util.List; 13 import java.util.jar.Attributes; 14 14 15 15 import org.openstreetmap.josm.tools.Logging; … … 30 30 * @param name the plugin name 31 31 * @param url the plugin download url 32 * @param manifest the plugin manifest 32 * @param manifest the plugin manifest attributes 33 33 * @return a plugin information object 34 34 * @throws PluginListParseException if plugin manifest cannot be parsed 35 35 */ 36 public static PluginInformation createInfo(String name, String url, Stringmanifest) throws PluginListParseException {36 public static PluginInformation createInfo(String name, String url, Attributes manifest) throws PluginListParseException { 37 37 try { 38 38 return new PluginInformation( 39 new ByteArrayInputStream(manifest.getBytes(StandardCharsets.UTF_8)),39 manifest, 40 40 name.substring(0, name.length() - 4), 41 41 url … … 62 62 String name = null; 63 63 String url = null; 64 StringBuilder manifest = new StringBuilder();64 Attributes manifest = new Attributes(); 65 65 for (String line = r.readLine(); line != null; line = r.readLine()) { 66 66 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'); 67 final String[] keyValue = line.split("\\s*:\\s*", 2); 68 manifest.put(new Attributes.Name(keyValue[0].substring(1)), keyValue[1]); 76 69 continue; 77 70 } 78 addPluginInformation(ret, name, url, manifest .toString());71 addPluginInformation(ret, name, url, manifest); 79 72 String[] x = line.split(";", -1); 80 73 if (x.length != 2) … … 82 75 name = x[0]; 83 76 url = x[1]; 84 manifest = new StringBuilder();77 manifest = new Attributes(); 85 78 } 86 addPluginInformation(ret, name, url, manifest .toString());79 addPluginInformation(ret, name, url, manifest); 87 80 return ret; 88 81 } catch (IOException e) { … … 91 84 } 92 85 93 private static void addPluginInformation(List<PluginInformation> ret, String name, String url, Stringmanifest) {86 private static void addPluginInformation(List<PluginInformation> ret, String name, String url, Attributes manifest) { 94 87 try { 95 88 if (name != null) {
Note:
See TracChangeset
for help on using the changeset viewer.