- Timestamp:
- 2010-03-06T12:37:34+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java
r3088 r3090 17 17 import java.util.Collection; 18 18 import java.util.Collections; 19 import java.util.Iterator; 19 20 import java.util.LinkedList; 20 21 import java.util.List; … … 77 78 sb.append("<ul>"); 78 79 for(PluginInformation pi: downloaded) { 79 sb.append("<li>").append(pi.name).append(" </li>");80 sb.append("<li>").append(pi.name).append(" (").append(pi.version).append(")").append("</li>"); 80 81 } 81 82 sb.append("</ul>"); … … 283 284 SwingUtilities.invokeLater(new Runnable() { 284 285 public void run() { 285 model. setAvailablePlugins(task.getAvailabePlugins());286 model.updateAvailablePlugins(task.getAvailabePlugins()); 286 287 pnlPluginPreferences.refreshView(); 287 288 288 } 289 289 }); … … 320 320 sb.toString(), 321 321 tr("Update plugins"), 322 failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE,322 !failed.isEmpty() ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE, 323 323 // FIXME: check help topic 324 324 HelpUtil.ht("/Preferences/Plugin") … … 326 326 } 327 327 328 protected void alertNothingToUpdate() { 329 HelpAwareOptionPane.showOptionDialog( 330 pnlPluginPreferences, 331 tr("All installed plugins are up to date. JOSM does not have to download newer versions."), 332 tr("Plugins up to date"), 333 JOptionPane.INFORMATION_MESSAGE, 334 null // FIXME: provide help context 335 ); 336 } 337 328 338 public void actionPerformed(ActionEvent e) { 329 List<PluginInformation> toUpdate = model.getSelectedPlugins();339 final List<PluginInformation> toUpdate = model.getSelectedPlugins(); 330 340 // the async task for downloading plugins 331 341 final PluginDownloadTask pluginDownloadTask = new PluginDownloadTask( … … 345 355 notifyDownloadResults(pluginDownloadTask); 346 356 model.refreshLocalPluginVersion(pluginDownloadTask.getDownloadedPlugins()); 357 model.clearPendingPlugins(pluginDownloadTask.getDownloadedPlugins()); 347 358 pnlPluginPreferences.refreshView(); 348 359 } … … 355 366 if (pluginInfoDownloadTask.isCanceled()) 356 367 return; 368 model.updateAvailablePlugins(pluginInfoDownloadTask.getAvailabePlugins()); 369 // select plugins which actually have to be updated 370 // 371 Iterator<PluginInformation> it = toUpdate.iterator(); 372 while(it.hasNext()) { 373 PluginInformation pi = it.next(); 374 if (!pi.isUpdateRequired()) { 375 it.remove(); 376 } 377 } 378 if (toUpdate.isEmpty()) { 379 alertNothingToUpdate(); 380 return; 381 } 382 pluginDownloadTask.setPluginsToDownload(toUpdate); 357 383 Main.worker.submit(pluginDownloadTask); 358 384 Main.worker.submit(pluginDownloadContinuation); -
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferencesModel.java
r3083 r3090 74 74 } 75 75 76 protected void updateAvailablePlugin(PluginInformation other) { 77 if (other == null) return; 78 PluginInformation pi = getPluginInformation(other.name); 79 if (pi == null) { 80 availablePlugins.add(other); 81 return; 82 } 83 pi.updateFromPluginSite(other); 84 } 85 86 /** 87 * Updates the list of plugin information objects with new information from 88 * plugin update sites. 89 * 90 * @param fromPluginSite plugin information read from plugin update sites 91 */ 92 public void updateAvailablePlugins(Collection<PluginInformation> fromPluginSite) { 93 for (PluginInformation other: fromPluginSite) { 94 updateAvailablePlugin(other); 95 } 96 sort(); 97 filterDisplayedPlugins(filterExpression); 98 Set<String> activePlugins = new HashSet<String>(); 99 activePlugins.addAll(Main.pref.getCollection("plugins", activePlugins)); 100 for (PluginInformation pi: availablePlugins) { 101 if (selectedPluginsMap.get(pi) == null) { 102 if (activePlugins.contains(pi.name)) { 103 selectedPluginsMap.put(pi, true); 104 } 105 } 106 } 107 clearChanged(); 108 notifyObservers(); 109 } 110 76 111 /** 77 112 * Replies the list of selected plugin information objects … … 113 148 new Comparator<PluginInformation>() { 114 149 public int compare(PluginInformation o1, PluginInformation o2) { 115 String n1 = o1.getName() == null ? "" : o1.getName() ;116 String n2 = o2.getName() == null ? "" : o2.getName() ;150 String n1 = o1.getName() == null ? "" : o1.getName().toLowerCase(); 151 String n2 = o2.getName() == null ? "" : o2.getName().toLowerCase(); 117 152 return n1.compareTo(n2); 118 153 } … … 164 199 if (!selected) { 165 200 pendingDownloads.remove(name); 201 } 202 } 203 204 /** 205 * Removes all the plugin in {@code plugins} from the list of plugins 206 * with a pending download 207 * 208 * @param plugins the list of plugins to clear for a pending download 209 */ 210 public void clearPendingPlugins(Collection<PluginInformation> plugins){ 211 if (plugins == null || plugins.isEmpty()) return; 212 for(PluginInformation pi: plugins) { 213 pendingDownloads.remove(pi.name); 166 214 } 167 215 } -
trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java
r3083 r3090 38 38 private static final Logger logger = Logger.getLogger(PluginDownloadTask.class.getName()); 39 39 40 private final Collection<PluginInformation> toUpdate ;40 private final Collection<PluginInformation> toUpdate = new LinkedList<PluginInformation>(); 41 41 private final Collection<PluginInformation> failed = new LinkedList<PluginInformation>(); 42 42 private final Collection<PluginInformation> downloaded = new LinkedList<PluginInformation>(); … … 56 56 super(parent, title == null ? "" : title, false /* don't ignore exceptions */); 57 57 CheckParameterUtil.ensureParameterNotNull(toUpdate, "toUpdate"); 58 this.toUpdate = toUpdate;58 this.toUpdate.addAll(toUpdate); 59 59 } 60 60 … … 70 70 super(title, monitor == null? NullProgressMonitor.INSTANCE: monitor, false /* don't ignore exceptions */); 71 71 CheckParameterUtil.ensureParameterNotNull(toUpdate, "toUpdate"); 72 this.toUpdate = toUpdate; 72 this.toUpdate.addAll(toUpdate); 73 } 74 75 /** 76 * Sets the collection of plugins to update. 77 * 78 * @param toUpdate the collection of plugins to update. Must not be null. 79 * @throws IllegalArgumentException thrown if toUpdate is null 80 */ 81 public void setPluginsToDownload(Collection<PluginInformation> toUpdate) throws IllegalArgumentException{ 82 CheckParameterUtil.ensureParameterNotNull(toUpdate, "toUpdate"); 83 this.toUpdate.clear(); 84 this.toUpdate.addAll(toUpdate); 73 85 } 74 86 -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r3086 r3090 382 382 pluginList.add(plugin.load(klass)); 383 383 } 384 } catch (Throwable e) { 384 } catch(PluginException e) { 385 if (e.getCause() instanceof ClassNotFoundException) { 386 e.printStackTrace(); 387 String msg = tr("<html>Could not load plugin {0} because the plugin<br>main class ''{1}'' was not found.<br>" 388 + "Delete from preferences?", plugin.name, plugin.className); 389 if (confirmDisablePlugin(parent, msg, plugin.name)) { 390 Main.pref.removeFromCollection("plugins", plugin.name); 391 } 392 } 393 } catch (Throwable e) { 385 394 e.printStackTrace(); 386 395 String msg = tr("Could not load plugin {0}. Delete from preferences?", plugin.name); … … 639 648 } 640 649 641 // try to update the locally installed plugins650 // filter plugins which actually have to be updated 642 651 // 643 PluginDownloadTask task2 = new PluginDownloadTask( 644 monitor.createSubTaskMonitor(1,false), 645 plugins, 646 tr("Update plugins") 647 ); 648 649 future = service.submit(task2); 650 try { 651 future.get(); 652 } catch(ExecutionException e) { 653 e.printStackTrace(); 654 alertFailedPluginUpdate(parent, plugins); 655 return; 656 } catch(InterruptedException e) { 657 e.printStackTrace(); 658 alertFailedPluginUpdate(parent, plugins); 659 return; 660 } 661 // notify user if downloading a locally installed plugin failed 662 // 663 if (! task2.getFailedPlugins().isEmpty()) { 664 alertFailedPluginUpdate(parent, task2.getFailedPlugins()); 665 return; 652 Iterator<PluginInformation> it = plugins.iterator(); 653 while(it.hasNext()) { 654 PluginInformation pi = it.next(); 655 if (!pi.isUpdateRequired()) { 656 it.remove(); 657 } 658 } 659 660 if (!plugins.isEmpty()) { 661 // try to update the locally installed plugins 662 // 663 PluginDownloadTask task2 = new PluginDownloadTask( 664 monitor.createSubTaskMonitor(1,false), 665 plugins, 666 tr("Update plugins") 667 ); 668 669 future = service.submit(task2); 670 try { 671 future.get(); 672 } catch(ExecutionException e) { 673 e.printStackTrace(); 674 alertFailedPluginUpdate(parent, plugins); 675 return; 676 } catch(InterruptedException e) { 677 e.printStackTrace(); 678 alertFailedPluginUpdate(parent, plugins); 679 return; 680 } 681 // notify user if downloading a locally installed plugin failed 682 // 683 if (! task2.getFailedPlugins().isEmpty()) { 684 alertFailedPluginUpdate(parent, task2.getFailedPlugins()); 685 return; 686 } 666 687 } 667 688 } finally { … … 744 765 * ".jar" files. 745 766 * 767 * If {@code dowarn} is true, this methods emits warning messages on the console if a downloaded 768 * but not yet installed plugin .jar can't be be installed. If {@code dowarn} is false, the 769 * installation of the respective plugin is sillently skipped. 770 * 771 * @param dowarn if true, warning messages are displayed; false otherwise 746 772 */ 747 773 public static void installDownloadedPlugins(boolean dowarn) { … … 760 786 String pluginName = updatedPlugin.getName().substring(0, updatedPlugin.getName().length() - 8); 761 787 if (plugin.exists()) { 762 if (!plugin.delete() && !dowarn) {788 if (!plugin.delete() && dowarn) { 763 789 System.err.println(tr("Warning: failed to delete outdated plugin ''{0}''.", plugin.toString())); 764 790 System.err.println(tr("Warning: failed to install already downloaded plugin ''{0}''. Skipping installation. JOSM is still going to load the old plugin version.", pluginName)); … … 766 792 } 767 793 } 768 if (!updatedPlugin.renameTo(plugin) && !dowarn) {794 if (!updatedPlugin.renameTo(plugin) && dowarn) { 769 795 System.err.println(tr("Warning: failed to install plugin ''{0}'' from temporary download file ''{1}''. Renaming failed.", plugin.toString(), updatedPlugin.toString())); 770 796 System.err.println(tr("Warning: failed to install already downloaded plugin ''{0}''. Skipping installation. JOSM is still going to load the old plugin version.", pluginName)); -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r3070 r3090 48 48 public String downloadlink = null; 49 49 public List<URL> libraries = new LinkedList<URL>(); 50 51 50 public final Map<String, String> attr = new TreeMap<String, String>(); 52 51 53 52 /** 54 * @param file the plugin jar file. 53 * Creates a plugin information object by reading the plugin information from 54 * the manifest in the plugin jar. 55 * 56 * The plugin name is derived from the file name. 57 * 58 * @param file the plugin jar file 59 * @throws PluginException if reading the manifest fails 55 60 */ 56 61 public PluginInformation(File file) throws PluginException{ … … 58 63 } 59 64 65 /** 66 * Creates a plugin information object for the plugin with name {@code name}. 67 * Information about the plugin is extracted from the maifest file in the the plugin jar 68 * {@code file}. 69 * @param file the plugin jar 70 * @param name the plugin name 71 * @throws PluginException thrown if reading the manifest file fails 72 */ 60 73 public PluginInformation(File file, String name) throws PluginException{ 61 74 this.name = name; … … 80 93 } 81 94 95 /** 96 * Creates a plugin information object by reading plugin information in Manifest format 97 * from the input stream {@code manifestStream}. 98 * 99 * @param manifestStream the stream to read the manifest from 100 * @param name the plugin name 101 * @param url the download URL for the plugin 102 * @throws PluginException thrown if the plugin information can't be read from the input stream 103 */ 82 104 public PluginInformation(InputStream manifestStream, String name, String url) throws PluginException { 83 105 this.name = name; … … 94 116 } 95 117 96 private void scanManifest(Manifest manifest, boolean oldcheck) 97 { 118 /** 119 * Updates the plugin information of this plugin information object with the 120 * plugin information in a plugin information object retrieved from a plugin 121 * update site. 122 * 123 * @param other the plugin information object retrieved from the update 124 * site 125 */ 126 public void updateFromPluginSite(PluginInformation other) { 127 this.mainversion = other.mainversion; 128 this.className = other.className; 129 this.requires = other.requires; 130 this.link = other.link; 131 this.description = other.description; 132 this.early = other.early; 133 this.author = other.author; 134 this.stage = other.stage; 135 this.version = other.version; 136 this.downloadlink = other.downloadlink; 137 this.libraries = other.libraries; 138 this.attr.clear(); 139 this.attr.putAll(other.attr); 140 } 141 142 private void scanManifest(Manifest manifest, boolean oldcheck){ 98 143 String lang = LanguageInfo.getLanguageCodeManifest(); 99 144 Attributes attr = manifest.getMainAttributes();
Note:
See TracChangeset
for help on using the changeset viewer.