Changeset 1588 in josm for trunk/src/org
- Timestamp:
- 2009-05-12T18:05:11+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/plugins
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/PluginDownloader.java
r1326 r1588 34 34 35 35 private static final class UpdateTask extends PleaseWaitRunnable { 36 private final Collection<Plugin Description> toUpdate;36 private final Collection<PluginInformation> toUpdate; 37 37 private String errors = ""; 38 38 private int count = 0; 39 39 40 private UpdateTask(Collection<Plugin Description> toUpdate) {40 private UpdateTask(Collection<PluginInformation> toUpdate) { 41 41 super(tr("Update Plugins")); 42 42 this.toUpdate = toUpdate; … … 58 58 if (!pluginDir.exists()) 59 59 pluginDir.mkdirs(); 60 for (Plugin Description d : toUpdate) {60 for (PluginInformation d : toUpdate) { 61 61 File pluginFile = new File(pluginDir, d.name + ".jar.new"); 62 if (download(d. resource, pluginFile))62 if (download(d.downloadlink, pluginFile)) 63 63 count++; 64 64 else … … 69 69 } 70 70 71 private static final Pattern wiki = Pattern.compile("^</td></tr><tr><td><a class=\"ext-link\" href=\"([^\"]*)\"><span class=\"icon\">([^<]*)</span></a></td><td>([^<]*)</td><td>([^<].*)</td><td>(.*)"); 72 73 private final static String[] pluginSites = {"http://josm.openstreetmap.de/wiki/Plugins"}; 71 private final static String[] pluginSites = {"http://josm.openstreetmap.de/plugin"}; 74 72 75 73 public static Collection<String> getSites() { … … 83 81 int count = 0; 84 82 for (String site : getSites()) { 83 /* TODO: remove old site files (everything except .jar) */ 85 84 try { 86 85 BufferedReader r = new BufferedReader(new InputStreamReader(new URL(site).openStream())); 87 CharSequence txt; 88 if (site.toLowerCase().endsWith(".xml")) 89 txt = readXml(r); 90 else 91 txt = readWiki(r); 86 StringBuilder b = new StringBuilder(); 87 for (String line = r.readLine(); line != null; line = r.readLine()) 88 b.append(line+"\n"); 92 89 r.close(); 93 90 new File(Main.pref.getPreferencesDir()+"plugins").mkdir(); 94 91 FileWriter out = new FileWriter(new File(Main.pref 95 92 .getPluginsDirFile(), count + "-site-" 96 + site.replaceAll("[/:\\\\ <>|]", "_") + ". xml"));97 out.append( txt);93 + site.replaceAll("[/:\\\\ <>|]", "_") + ".txt")); 94 out.append(b); 98 95 out.close(); 99 96 count++; … … 104 101 } 105 102 106 private static CharSequence readXml(BufferedReader r) throws IOException {107 StringBuilder b = new StringBuilder();108 for (String line = r.readLine(); line != null; line = r.readLine())109 b.append(line+"\n");110 return b;111 }112 113 private static CharSequence readWiki(BufferedReader r) throws IOException {114 StringBuilder b = new StringBuilder("<plugins>\n");115 for (String line = r.readLine(); line != null; line = r.readLine()) {116 Matcher m = wiki.matcher(line);117 if (!m.matches())118 continue;119 b.append(" <plugin>\n");120 b.append(" <name>"+escape(m.group(2))+"</name>\n");121 b.append(" <resource>"+escape(m.group(1))+"</resource>\n");122 b.append(" <author>"+escape(m.group(3))+"</author>\n");123 b.append(" <description>"+escape(m.group(4))+"</description>\n");124 b.append(" <version>"+escape(m.group(5))+"</version>\n");125 b.append(" </plugin>\n");126 }127 b.append("</plugins>\n");128 return b;129 }130 131 103 private static String escape(String s) { 132 104 return s.replaceAll("<", "<").replaceAll(">", ">"); 133 105 } 134 106 135 public static boolean downloadPlugin(Plugin Description pd) {107 public static boolean downloadPlugin(PluginInformation pd) { 136 108 File file = new File(Main.pref.getPluginsDirFile(), pd.name + ".jar"); 137 if (!download(pd. resource, file)) {138 JOptionPane.showMessageDialog(Main.parent, tr("Could not download plugin: {0} from {1}", pd.name, pd. resource));109 if (!download(pd.downloadlink, file)) { 110 JOptionPane.showMessageDialog(Main.parent, tr("Could not download plugin: {0} from {1}", pd.name, pd.downloadlink)); 139 111 } else { 140 112 try { … … 171 143 } 172 144 173 public static void update(Collection<Plugin Description> update) {145 public static void update(Collection<PluginInformation> update) { 174 146 Main.worker.execute(new UpdateTask(update)); 175 147 } -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r1326 r1588 35 35 public final String className; 36 36 public final String requires; 37 public final String link; 37 38 public final String description; 38 39 public final boolean early; … … 40 41 public final int stage; 41 42 public final String version; 43 public String downloadlink = null; 42 44 public final List<URL> libraries = new LinkedList<URL>(); 43 45 … … 76 78 } 77 79 if (manifest != null) { 80 String s; 81 String lang = Main.getLanguageCode()+"_"; 78 82 Attributes attr = manifest.getMainAttributes(); 79 83 className = attr.getValue("Plugin-Class"); 84 s = attr.getValue(lang+"Plugin-Link"); 85 if(s == null) 86 s = attr.getValue("Plugin-Link"); 87 link = s; 80 88 requires = attr.getValue("Plugin-Requires"); 81 description = attr.getValue("Plugin-Description"); 89 s = attr.getValue(lang+"Plugin-Description"); 90 if(s == null) 91 { 92 s = attr.getValue("Plugin-Description"); 93 if(s != null) 94 s = tr(s); 95 } 96 description = s; 82 97 early = Boolean.parseBoolean(attr.getValue("Plugin-Early")); 83 98 String stageStr = attr.getValue("Plugin-Stage"); … … 106 121 className = null; 107 122 mainversion = null; 108 description = tr("unknown");123 description = null; 109 124 early = false; 110 125 stage = 50; 111 126 requires = null; 127 link = null; 112 128 version = null; 113 129 author = null; … … 121 137 throw new PluginException(null, name, e); 122 138 } 139 } 140 141 public String getLinkDescription() 142 { 143 String d = description == null ? tr("no description available") : description; 144 if(link != null) 145 d += " <A HREF=\""+link+"\">"+tr("More details")+"</A>"; 146 return d; 123 147 } 124 148 -
trunk/src/org/openstreetmap/josm/plugins/PluginSelection.java
r1415 r1588 10 10 import java.awt.event.ActionListener; 11 11 12 import java.io.BufferedReader; 13 import java.io.ByteArrayInputStream; 12 14 import java.io.File; 13 15 import java.io.FileReader; … … 39 41 import org.openstreetmap.josm.gui.ExtendedDialog; 40 42 import org.openstreetmap.josm.tools.OpenBrowser; 41 import org.openstreetmap.josm.tools.XmlObjectParser.Uniform;42 43 43 44 public class PluginSelection { 44 45 45 46 private Map<String, Boolean> pluginMap; 46 private Map<String, Plugin Description> availablePlugins;47 private Map<String, PluginInformation> availablePlugins; 47 48 48 49 public void updateDescription(JPanel pluginPanel) { … … 63 64 drawPanel(pluginPanel); 64 65 65 Set<Plugin Description> toUpdate = new HashSet<PluginDescription>();66 Set<PluginInformation> toUpdate = new HashSet<PluginInformation>(); 66 67 StringBuilder toUpdateStr = new StringBuilder(); 67 68 for (PluginProxy proxy : PluginHandler.pluginList) { 68 Plugin Description description = availablePlugins.get(proxy.info.name);69 PluginInformation description = availablePlugins.get(proxy.info.name); 69 70 if (description != null && (description.version == null || description.version.equals("")) ? 70 71 (proxy.info.version != null && proxy.info.version.equals("")) : !description.version.equals(proxy.info.version)) { … … 77 78 done = true; 78 79 } else { 79 int answer = new ExtendedDialog(Main.parent, 80 tr("Update"), 80 int answer = new ExtendedDialog(Main.parent, 81 tr("Update"), 81 82 tr("Update the following plugins:\n\n{0}", toUpdateStr.toString()), 82 new String[] {tr("Update Plugins"), tr("Cancel")}, 83 new String[] {"dialogs/refresh.png", "cancel.png"}).getValue(); 83 new String[] {tr("Update Plugins"), tr("Cancel")}, 84 new String[] {"dialogs/refresh.png", "cancel.png"}).getValue(); 84 85 if (answer == 1) { 85 86 PluginDownloader.update(toUpdate); … … 93 94 94 95 public Boolean finish() { 95 Collection<Plugin Description> toDownload = new LinkedList<PluginDescription>();96 Collection<PluginInformation> toDownload = new LinkedList<PluginInformation>(); 96 97 String msg = ""; 97 98 for (Entry<String, Boolean> entry : pluginMap.entrySet()) { … … 102 103 } 103 104 if (!toDownload.isEmpty()) { 104 int answer = new ExtendedDialog(Main.parent, 105 int answer = new ExtendedDialog(Main.parent, 105 106 tr("Download missing plugins"), 106 107 tr("Download the following plugins?\n\n{0}", msg), 107 new String[] {tr("Download Plugins"), tr("Cancel")}, 108 new String[] {"download.png", "cancel.png"}).getValue(); 108 new String[] {tr("Download Plugins"), tr("Cancel")}, 109 new String[] {"download.png", "cancel.png"}).getValue(); 109 110 if (answer != 1) 110 for (Plugin Description pd : toDownload)111 for (PluginInformation pd : toDownload) 111 112 pluginMap.put(pd.name, false); 112 113 else 113 for (Plugin Description pd : toDownload)114 for (PluginInformation pd : toDownload) 114 115 if (!PluginDownloader.downloadPlugin(pd)) 115 116 pluginMap.put(pd.name, false); … … 145 146 146 147 int row = 0; 147 for (final Plugin Description plugin : availablePlugins.values()) {148 for (final PluginInformation plugin : availablePlugins.values()) { 148 149 boolean enabled = (enabledPlugins != null) && enabledPlugins.contains(plugin.name); 149 150 if (pluginMap.get(plugin.name) == null) … … 174 175 pluginPanel.add(pluginCheck, gbc); 175 176 176 pluginCheck.setToolTipText(plugin. resource != null ? ""+plugin.resource: tr("Plugin bundled with JOSM"));177 pluginCheck.setToolTipText(plugin.downloadlink != null ? ""+plugin.downloadlink : tr("Plugin bundled with JOSM")); 177 178 178 179 JEditorPane description = new JEditorPane(); 179 180 description.setContentType("text/html"); 180 181 description.setEditable(false); 181 description.setText("<html><i>"+ (plugin.description==null?tr("no description available"):plugin.description)+"</i></html>");182 description.setText("<html><i>"+plugin.getLinkDescription()+"</i></html>"); 182 183 description.setBorder(BorderFactory.createEmptyBorder(0,20,0,0)); 183 184 description.setBackground(UIManager.getColor("Panel.background")); … … 205 206 if ((getLoaded(plugin.name) == null) && (plinfo != null)) { 206 207 try { 207 int answer = new ExtendedDialog(Main.parent, 208 tr("Plugin already exists"), 208 int answer = new ExtendedDialog(Main.parent, 209 tr("Plugin already exists"), 209 210 tr("Plugin archive already available. Do you want to download" 210 211 + " the current version by deleting existing archive?\n\n{0}", 211 212 plinfo.file.getCanonicalPath()), 212 new String[] {tr("Delete and Download"), tr("Cancel")}, 213 new String[] {"download.png", "cancel.png"}).getValue(); 214 213 new String[] {tr("Delete and Download"), tr("Cancel")}, 214 new String[] {"download.png", "cancel.png"}).getValue(); 215 215 216 if (answer == 1) { 216 217 if (!plinfo.file.delete()) { … … 247 248 } 248 249 249 private Map<String, Plugin Description> getAvailablePlugins() {250 SortedMap<String, Plugin Description> availablePlugins = new TreeMap<String, PluginDescription>(new Comparator<String>(){250 private Map<String, PluginInformation> getAvailablePlugins() { 251 SortedMap<String, PluginInformation> availablePlugins = new TreeMap<String, PluginInformation>(new Comparator<String>(){ 251 252 public int compare(String o1, String o2) { 252 253 return o1.compareToIgnoreCase(o2); … … 260 261 if (!f.isFile()) 261 262 continue; 262 if (f.getName().endsWith(".jar")) { 263 String fname = f.getName(); 264 if (fname.endsWith(".jar")) { 263 265 try { 264 PluginInformation info = new PluginInformation(f );266 PluginInformation info = new PluginInformation(f,fname.substring(0,fname.length()-4), null); 265 267 if (!availablePlugins.containsKey(info.name)) 266 availablePlugins.put(info.name, new PluginDescription( 267 info.name, 268 info.description, 269 PluginInformation.fileToURL(f).toString(), 270 info.version)); 268 availablePlugins.put(info.name, info); 271 269 } catch (PluginException x) { 272 270 } 273 } else if (f .getName().matches("^[0-9]+-site.*\\.xml$")) {271 } else if (fname.matches("^[0-9]+-site.*\\.txt$")) { 274 272 try { 275 Uniform<PluginDescription> parser = new Uniform<PluginDescription>(new FileReader(f), "plugin", PluginDescription.class); 276 for (PluginDescription pd : parser) 277 if (!availablePlugins.containsKey(pd.name)) 278 availablePlugins.put(pd.name, pd); 273 BufferedReader r = new BufferedReader(new FileReader(f)); 274 String name = null; 275 String url = null; 276 String manifest = null; 277 for (String line = r.readLine(); line != null; line = r.readLine()) 278 { 279 if(line.startsWith("\t")) 280 { 281 line = line.substring(1); 282 if(line.length() > 70) 283 { 284 manifest += line.substring(0,70)+"\n"; 285 line = " " + line.substring(70); 286 } 287 manifest += line+"\n"; 288 } 289 else 290 { 291 if(name != null) 292 { 293 PluginInformation info = new PluginInformation(null, name.substring(0,name.length()-4), 294 new ByteArrayInputStream(manifest.getBytes())); 295 info.downloadlink = url; 296 if(!availablePlugins.containsKey(info.name)) 297 availablePlugins.put(info.name, info); 298 manifest = null; 299 } 300 String x[] = line.split(";"); 301 name = x[0]; 302 url = x[1]; 303 } 304 } 305 if(name != null) 306 { 307 PluginInformation info = new PluginInformation(null, name.substring(0,name.length()-4), 308 new ByteArrayInputStream(manifest.getBytes())); 309 info.downloadlink = url; 310 if(!availablePlugins.containsKey(info.name)) 311 availablePlugins.put(info.name, info); 312 } 313 r.close(); 279 314 } catch (Exception e) { 280 315 e.printStackTrace(); … … 287 322 for (PluginProxy proxy : PluginHandler.pluginList) 288 323 if (!availablePlugins.containsKey(proxy.info.name)) 289 availablePlugins.put(proxy.info.name, new PluginDescription( 290 proxy.info.name, 291 proxy.info.description, 292 proxy.info.file == null ? null : 293 PluginInformation.fileToURL(proxy.info.file).toString(), 294 proxy.info.version)); 324 availablePlugins.put(proxy.info.name, proxy.info); 295 325 return availablePlugins; 296 326 }
Note:
See TracChangeset
for help on using the changeset viewer.