Changeset 1647 in josm for trunk/src/org/openstreetmap/josm/plugins
- Timestamp:
- 2009-06-07T02:56:33+02:00 (17 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/plugins
- Files:
-
- 3 edited
-
PluginDownloader.java (modified) (6 diffs)
-
PluginInformation.java (modified) (1 diff)
-
PluginSelection.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/PluginDownloader.java
r1645 r1647 23 23 import java.net.URL; 24 24 import java.util.Arrays; 25 import java.util.concurrent.Future; 25 26 import java.util.Collection; 26 import java.util.regex.Matcher; 27 import java.util.regex.Pattern; 27 import java.util.LinkedList; 28 28 29 29 import javax.swing.JOptionPane; … … 39 39 private static final class UpdateTask extends PleaseWaitRunnable { 40 40 private final Collection<PluginInformation> toUpdate; 41 public final Collection<PluginInformation> failed = new LinkedList<PluginInformation>(); 41 42 private String errors = ""; 42 43 private int count = 0; 44 private boolean update; 43 45 44 private UpdateTask(Collection<PluginInformation> toUpdate) { 45 super(tr("Update Plugins")); 46 private UpdateTask(Collection<PluginInformation> toUpdate, boolean up) { 47 super(up ? tr("Update Plugins") : tr("Download Plugins")); 48 update = up; 46 49 this.toUpdate = toUpdate; 47 50 } … … 52 55 53 56 @Override protected void finish() { 57 Main.pleaseWaitDlg.setVisible(false); 54 58 if (errors.length() > 0) 55 59 JOptionPane.showMessageDialog(Main.parent, tr("There were problems with the following plugins:\n\n {0}",errors)); 56 60 else 57 JOptionPane.showMessageDialog(Main.parent, trn("{0} Plugin successfully updated. Please restart JOSM.", "{0} Plugins successfullyupdated. Please restart JOSM.", count, count));61 JOptionPane.showMessageDialog(Main.parent, trn("{0} Plugin successfully downloaded. Please restart JOSM.", "{0} Plugins successfully downloaded. Please restart JOSM.", count, count)); 58 62 } 59 63 … … 63 67 pluginDir.mkdirs(); 64 68 for (PluginInformation d : toUpdate) { 69 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading Plugin {0}...", d.name)); 65 70 File pluginFile = new File(pluginDir, d.name + ".jar.new"); 66 71 if (download(d, pluginFile)) 72 { 67 73 count++; 74 failed.add(d); 75 } 68 76 else 69 77 errors += d.name + "\n"; … … 103 111 } 104 112 105 public static boolean downloadPlugin(PluginInformation pd) {106 File file = new File(Main.pref.getPluginsDirFile(), pd.name + ".jar");107 if (!download(pd, file)) {108 JOptionPane.showMessageDialog(Main.parent, tr("Could not download plugin: {0} from {1}", pd.name, pd.downloadlink));109 } else {110 try {111 PluginInformation.findPlugin(pd.name);112 return true;113 } catch (Exception e) {114 e.printStackTrace();115 JOptionPane.showMessageDialog(Main.parent, tr("The plugin {0} seems to be broken or could not be downloaded automatically.", pd.name));116 }117 }118 if (file.exists())119 file.delete();120 return false;121 }122 123 113 private static boolean download(PluginInformation pd, File file) { 124 114 if(pd.mainversion > AboutAction.getVersionNumber()) … … 141 131 out.close(); 142 132 in.close(); 133 new PluginInformation(file); 143 134 return true; 144 } catch (MalformedURLException e) { 145 e.printStackTrace(); 146 } catch (FileNotFoundException e) { 147 e.printStackTrace(); 148 } catch (IOException e) { 135 } catch (Exception e) { 149 136 e.printStackTrace(); 150 137 } 138 file.delete(); /* cleanup */ 151 139 return false; 152 140 } 153 141 154 142 public static void update(Collection<PluginInformation> update) { 155 Main.worker.execute(new UpdateTask(update)); 143 Main.worker.execute(new UpdateTask(update, true)); 144 } 145 146 public Collection<PluginInformation> download(Collection<PluginInformation> download) { 147 UpdateTask t = new UpdateTask(download, false); 148 try { 149 Future<UpdateTask> ta = Main.worker.submit(t, t); 150 t = ta.get(); 151 return t.failed; 152 } 153 catch(java.lang.InterruptedException e) {} 154 catch(java.util.concurrent.ExecutionException e) {} 155 return download; 156 156 } 157 157 -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r1645 r1647 110 110 stage = stageStr == null ? 50 : Integer.parseInt(stageStr); 111 111 version = attr.getValue("Plugin-Version"); 112 try { 113 mainversion = Integer.parseInt(attr.getValue("Plugin-Mainversion")); 114 } catch(NumberFormatException e) { 115 e.printStackTrace(); 116 } 112 try { mainversion = Integer.parseInt(attr.getValue("Plugin-Mainversion")); } 113 catch(NumberFormatException e) {} 117 114 author = attr.getValue("Author"); 118 115 -
trunk/src/org/openstreetmap/josm/plugins/PluginSelection.java
r1623 r1647 98 98 String msg = ""; 99 99 for (Entry<String, Boolean> entry : pluginMap.entrySet()) { 100 if (entry.getValue() && PluginInformation.findPlugin(entry.getKey()) == null) { 101 toDownload.add(availablePlugins.get(entry.getKey())); 102 msg += entry.getKey() + "\n"; 100 if(entry.getValue()) 101 { 102 String name = entry.getKey(); 103 PluginInformation ap = availablePlugins.get(name); 104 PluginInformation pi = PluginInformation.findPlugin(name); 105 boolean add = false; 106 if(pi == null) 107 add = true; 108 else if(!pi.version.equals(ap.version)) 109 { 110 add = true; 111 for (PluginProxy proxy : PluginHandler.pluginList) 112 if(proxy.info.name.equals(ap.name)) 113 add = false; 114 } 115 if(add) 116 { 117 toDownload.add(ap); 118 msg += name + "\n"; 119 } 103 120 } 104 121 } … … 109 126 new String[] {tr("Download Plugins"), tr("Cancel")}, 110 127 new String[] {"download.png", "cancel.png"}).getValue(); 111 if (answer != 1) 112 for (PluginInformation pd : toDownload) 113 pluginMap.put(pd.name, false); 114 else 115 for (PluginInformation pd : toDownload) 116 if (!PluginDownloader.downloadPlugin(pd)) 117 pluginMap.put(pd.name, false); 128 Collection<PluginInformation> error = 129 (answer != 1 ? toDownload : new PluginDownloader().download(toDownload)); 130 for (PluginInformation pd : error) 131 pluginMap.put(pd.name, false); 118 132 119 133 } … … 209 223 pluginCheck.addActionListener(new ActionListener(){ 210 224 public void actionPerformed(ActionEvent e) { 211 // if user enabled a plugin, it is not loaded but found somewhere on disk: offer to delete jar212 if (pluginCheck.isSelected()) {213 PluginInformation plinfo = PluginInformation.findPlugin(plugin.name);214 if ((getLoaded(plugin.name) == null) && (plinfo != null)) {215 try {216 int answer = new ExtendedDialog(Main.parent,217 tr("Plugin already exists"),218 tr("Plugin archive already available. Do you want to download"219 + " the current version by deleting existing archive?\n\n{0}",220 plinfo.file.getCanonicalPath()),221 new String[] {tr("Delete and Download"), tr("Cancel")},222 new String[] {"download.png", "cancel.png"}).getValue();223 224 if (answer == 1) {225 if (!plinfo.file.delete()) {226 JOptionPane.showMessageDialog(Main.parent, tr("Error deleting plugin file: {0}", plinfo.file.getCanonicalPath()));227 }228 }229 } catch (IOException e1) {230 e1.printStackTrace();231 JOptionPane.showMessageDialog(Main.parent, tr("Error deleting plugin file: {0}", e1.getMessage()));232 }233 }234 }235 225 pluginMap.put(plugin.name, pluginCheck.isSelected()); 236 226 }
Note:
See TracChangeset
for help on using the changeset viewer.
