Changeset 5601 in josm for trunk/src/org/openstreetmap/josm/plugins
- Timestamp:
- 2012-11-26T19:16:05+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/plugins
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r5508 r5601 424 424 } 425 425 426 return checkRequiredPluginsPreconditions(parent, plugins, plugin );426 return checkRequiredPluginsPreconditions(parent, plugins, plugin, true); 427 427 } 428 428 … … 434 434 * @param plugins the collection of all loaded plugins 435 435 * @param plugin the plugin for which preconditions are checked 436 * @param local Determines if the local or up-to-date plugin dependencies are to be checked. 436 437 * @return true, if the preconditions are met; false otherwise 437 */ 438 public static boolean checkRequiredPluginsPreconditions(Component parent, Collection<PluginInformation> plugins, PluginInformation plugin) { 439 438 * @since 5601 439 */ 440 public static boolean checkRequiredPluginsPreconditions(Component parent, Collection<PluginInformation> plugins, PluginInformation plugin, boolean local) { 441 442 String requires = local ? plugin.localrequires : plugin.requires; 443 440 444 // make sure the dependencies to other plugins are not broken 441 445 // 442 if (plugin.requires != null){446 if (requires != null) { 443 447 Set<String> pluginNames = new HashSet<String>(); 444 448 for (PluginInformation pi: plugins) { … … 446 450 } 447 451 Set<String> missingPlugins = new HashSet<String>(); 448 for (String requiredPlugin : plugin.requires.split(";")) {449 requiredPlugin = requiredPlugin.trim();452 List<String> requiredPlugins = local ? plugin.getLocalRequiredPlugins() : plugin.getRequiredPlugins(); 453 for (String requiredPlugin : requiredPlugins) { 450 454 if (!pluginNames.contains(requiredPlugin)) { 451 455 missingPlugins.add(requiredPlugin); … … 730 734 ); 731 735 } 736 737 private static Set<PluginInformation> findRequiredPluginsToDownload( 738 Collection<PluginInformation> pluginsToUpdate, List<PluginInformation> allPlugins, Set<PluginInformation> pluginsToDownload) { 739 Set<PluginInformation> result = new HashSet<PluginInformation>(); 740 for (PluginInformation pi : pluginsToUpdate) { 741 for (String name : pi.getRequiredPlugins()) { 742 try { 743 PluginInformation installedPlugin = PluginInformation.findPlugin(name); 744 if (installedPlugin == null) { 745 // New required plugin is not installed, find its PluginInformation 746 PluginInformation reqPlugin = null; 747 for (PluginInformation pi2 : allPlugins) { 748 if (pi2.getName().equals(name)) { 749 reqPlugin = pi2; 750 break; 751 } 752 } 753 // Required plugin is known but not already on download list 754 if (reqPlugin != null && !pluginsToDownload.contains(reqPlugin)) { 755 result.add(reqPlugin); 756 } 757 } 758 } catch (PluginException e) { 759 System.out.println(tr("Warning: failed to find plugin {0}", name)); 760 e.printStackTrace(); 761 } 762 } 763 } 764 return result; 765 } 732 766 733 767 /** … … 757 791 ); 758 792 Future<?> future = service.submit(task1); 793 List<PluginInformation> allPlugins = null; 794 759 795 try { 760 796 future.get(); 797 allPlugins = task1.getAvailablePlugins(); 761 798 plugins = buildListOfPluginsToLoad(parent,monitor.createSubTaskMonitor(1, false)); 762 799 } catch(ExecutionException e) { … … 778 815 } 779 816 } 780 817 781 818 if (!pluginsToUpdate.isEmpty()) { 819 820 Set<PluginInformation> pluginsToDownload = new HashSet<PluginInformation>(pluginsToUpdate); 821 822 if (allPlugins != null) { 823 // Updated plugins may need additional plugin dependencies currently not installed 824 // 825 Set<PluginInformation> additionalPlugins = findRequiredPluginsToDownload(pluginsToUpdate, allPlugins, pluginsToDownload); 826 pluginsToDownload.addAll(additionalPlugins); 827 828 // Iterate on required plugins, if they need themselves another plugins (i.e A needs B, but B needs C) 829 while (!additionalPlugins.isEmpty()) { 830 // Install the additional plugins to load them later 831 plugins.addAll(additionalPlugins); 832 additionalPlugins = findRequiredPluginsToDownload(additionalPlugins, allPlugins, pluginsToDownload); 833 pluginsToDownload.addAll(additionalPlugins); 834 } 835 } 836 782 837 // try to update the locally installed plugins 783 838 // 784 839 PluginDownloadTask task2 = new PluginDownloadTask( 785 840 monitor.createSubTaskMonitor(1,false), 786 pluginsTo Update,841 pluginsToDownload, 787 842 tr("Update plugins") 788 843 ); … … 800 855 return plugins; 801 856 } 857 858 // Update Plugin info for downloaded plugins 859 // 860 refreshLocalUpdatedPluginInfo(task2.getDownloadedPlugins()); 861 802 862 // notify user if downloading a locally installed plugin failed 803 863 // … … 921 981 return; 922 982 } 983 984 /** 985 * Replies the updated jar file for the given plugin name. 986 * @param name The plugin name to find. 987 * @return the updated jar file for the given plugin name. null if not found or not readable. 988 * @since 5601 989 */ 990 public static File findUpdatedJar(String name) { 991 File pluginDir = Main.pref.getPluginsDirectory(); 992 // Find the downloaded file. We have tried to install the downloaded plugins 993 // (PluginHandler.installDownloadedPlugins). This succeeds depending on the 994 // platform. 995 File downloadedPluginFile = new File(pluginDir, name + ".jar.new"); 996 if (!(downloadedPluginFile.exists() && downloadedPluginFile.canRead())) { 997 downloadedPluginFile = new File(pluginDir, name + ".jar"); 998 if (!(downloadedPluginFile.exists() && downloadedPluginFile.canRead())) { 999 return null; 1000 } 1001 } 1002 return downloadedPluginFile; 1003 } 1004 1005 /** 1006 * Refreshes the given PluginInformation objects with new contents read from their corresponding jar file. 1007 * @param updatedPlugins The PluginInformation objects to update. 1008 * @since 5601 1009 */ 1010 public static void refreshLocalUpdatedPluginInfo(Collection<PluginInformation> updatedPlugins) { 1011 if (updatedPlugins == null) return; 1012 for (PluginInformation pi : updatedPlugins) { 1013 File downloadedPluginFile = findUpdatedJar(pi.name); 1014 if (downloadedPluginFile == null) { 1015 continue; 1016 } 1017 try { 1018 pi.updateFromJar(new PluginInformation(downloadedPluginFile, pi.name)); 1019 } catch(PluginException e) { 1020 e.printStackTrace(); 1021 } 1022 } 1023 } 923 1024 924 1025 private static boolean confirmDeactivatingPluginAfterException(PluginProxy plugin) { -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r5588 r5601 44 44 public boolean oldmode = false; 45 45 public String requires = null; 46 public String localrequires = null; 46 47 public String link = null; 47 48 public String description = null; … … 157 158 this.attr.putAll(other.attr); 158 159 } 159 160 161 /** 162 * Updates the plugin information of this plugin information object with the 163 * plugin information in a plugin information object retrieved from a plugin 164 * jar. 165 * 166 * @param other the plugin information object retrieved from the jar file 167 * @since 5601 168 */ 169 public void updateFromJar(PluginInformation other) { 170 updateLocalInfo(other); 171 if (other.icon != null) { 172 this.icon = other.icon; 173 } 174 this.early = other.early; 175 this.className = other.className; 176 this.libraries = other.libraries; 177 this.stage = other.stage; 178 } 179 160 180 private void scanManifest(Manifest manifest, boolean oldcheck){ 161 181 String lang = LanguageInfo.getLanguageCodeManifest(); … … 452 472 } 453 473 474 /** 475 * Replies the plugin icon, scaled to 24x24 pixels. 476 * @return the plugin icon, scaled to 24x24 pixels. 477 */ 454 478 public ImageIcon getScaledIcon() { 455 479 if (icon == null) … … 462 486 return getName(); 463 487 } 488 489 private static List<String> getRequiredPlugins(String pluginList) { 490 List<String> requiredPlugins = new ArrayList<String>(); 491 if (pluginList != null) { 492 for (String s : pluginList.split(";")) { 493 String plugin = s.trim(); 494 if (!plugin.isEmpty()) { 495 requiredPlugins.add(plugin); 496 } 497 } 498 } 499 return requiredPlugins; 500 } 501 502 /** 503 * Replies the list of plugins required by the up-to-date version of this plugin. 504 * @return List of plugins required. Empty if no plugin is required. 505 * @since 5601 506 */ 507 public List<String> getRequiredPlugins() { 508 return getRequiredPlugins(requires); 509 } 510 511 /** 512 * Replies the list of plugins required by the local instance of this plugin. 513 * @return List of plugins required. Empty if no plugin is required. 514 * @since 5601 515 */ 516 public List<String> getLocalRequiredPlugins() { 517 return getRequiredPlugins(localrequires); 518 } 519 520 /** 521 * Updates the local fields ({@link #localversion}, {@link #localmainversion}, {@link #localrequires}) 522 * to values contained in the up-to-date fields ({@link #version}, {@link #mainversion}, {@link #requires}) 523 * of the given PluginInformation. 524 * @param info The plugin information to get the data from. 525 * @since 5601 526 */ 527 public void updateLocalInfo(PluginInformation info) { 528 if (info != null) { 529 this.localversion = info.version; 530 this.localmainversion = info.mainversion; 531 this.localrequires = info.requires; 532 } 533 } 464 534 } -
trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java
r5266 r5601 63 63 ); 64 64 if (!availablePlugins.containsKey(info.getName())) { 65 info.localversion = info.version; 66 info.localmainversion = info.mainversion; 65 info.updateLocalInfo(info); 67 66 availablePlugins.put(info.getName(), info); 68 67 } else { 69 68 PluginInformation current = availablePlugins.get(info.getName()); 70 current.localversion = info.version; 71 current.localmainversion = info.mainversion; 72 if (info.icon != null) { 73 current.icon = info.icon; 74 } 75 current.early = info.early; 76 current.className = info.className; 77 current.libraries = info.libraries; 78 current.stage = info.stage; 79 current.requires = info.requires; 69 current.updateFromJar(info); 80 70 } 81 71 } -
trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
r5587 r5601 382 382 * 383 383 * @return the list of plugins 384 */ 385 public List<PluginInformation> getAvailabePlugins() { 384 * @since 5601 385 */ 386 public List<PluginInformation> getAvailablePlugins() { 386 387 return availablePlugins; 387 388 }
Note:
See TracChangeset
for help on using the changeset viewer.