Changeset 8017 in josm for trunk/src/org/openstreetmap/josm/plugins
- Timestamp:
- 2015-02-09T08:43:18+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/plugins
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java
r7597 r8017 187 187 188 188 /** 189 * Replies the list of successfully downloaded plugins190 * 191 * @return the list of successfully downloaded plugins189 * Replies the list of plugins whose download has failed. 190 * 191 * @return the list of plugins whose download has failed 192 192 */ 193 193 public Collection<PluginInformation> getFailedPlugins() { … … 196 196 197 197 /** 198 * Replies the list of plugins whose download has failed199 * 200 * @return the list of plugins whose download has failed198 * Replies the list of successfully downloaded plugins. 199 * 200 * @return the list of successfully downloaded plugins 201 201 */ 202 202 public Collection<PluginInformation> getDownloadedPlugins() { -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r7956 r8017 187 187 188 188 /** 189 * ClassLoader that makes the addURL method of URLClassLoader public. 190 * 191 * Like URLClassLoader, but allows to add more URLs after construction. 192 */ 193 public static class DynamicURLClassLoader extends URLClassLoader { 194 195 public DynamicURLClassLoader(URL[] urls, ClassLoader parent) { 196 super(urls, parent); 197 } 198 199 @Override 200 public void addURL(URL url) { 201 super.addURL(url); 202 } 203 } 204 205 /** 189 206 * List of unmaintained plugins. Not really up-to-date as the vast majority of plugins are not really maintained after a few months, sadly... 190 207 */ … … 200 217 */ 201 218 public static final Collection<PluginProxy> pluginList = new LinkedList<>(); 219 220 /** 221 * Global plugin ClassLoader. 222 */ 223 private static DynamicURLClassLoader pluginClassLoader; 202 224 203 225 /** … … 536 558 537 559 /** 538 * Creates a class loader for loading plugin code. 539 * 540 * @param plugins the collection of plugins which are going to be loaded with this 541 * class loader 560 * Get the class loader for loading plugin code. 561 * 542 562 * @return the class loader 543 563 */ 544 public static ClassLoader createClassLoader(Collection<PluginInformation> plugins) { 564 public static DynamicURLClassLoader getPluginClassLoader() { 565 if (pluginClassLoader == null) { 566 pluginClassLoader = AccessController.doPrivileged(new PrivilegedAction<DynamicURLClassLoader>() { 567 public DynamicURLClassLoader run() { 568 return new DynamicURLClassLoader(new URL[0], Main.class.getClassLoader()); 569 } 570 }); 571 sources.add(0, pluginClassLoader); 572 } 573 return pluginClassLoader; 574 } 575 576 /** 577 * Add more plugins to the plugin class loader. 578 * 579 * @param plugins the plugins that should be handled by the plugin class loader 580 */ 581 public static void extendPluginClassLoader(Collection<PluginInformation> plugins) { 545 582 // iterate all plugins and collect all libraries of all plugins: 546 List<URL> allPluginLibraries = new LinkedList<>();547 583 File pluginDir = Main.pref.getPluginsDirectory(); 548 549 // Add all plugins already loaded (to include early plugins in the classloader, allowing late plugins to rely on early ones) 550 Collection<PluginInformation> allPlugins = new HashSet<>(plugins); 551 for (PluginProxy proxy : pluginList) { 552 allPlugins.add(proxy.getPluginInformation()); 553 } 554 555 for (PluginInformation info : allPlugins) { 584 DynamicURLClassLoader cl = getPluginClassLoader(); 585 586 for (PluginInformation info : plugins) { 556 587 if (info.libraries == null) { 557 588 continue; 558 589 } 559 allPluginLibraries.addAll(info.libraries); 590 for (URL libUrl : info.libraries) { 591 cl.addURL(libUrl); 592 } 560 593 File pluginJar = new File(pluginDir, info.name + ".jar"); 561 594 I18n.addTexts(pluginJar); 562 595 URL pluginJarUrl = Utils.fileToURL(pluginJar); 563 allPluginLibraries.add(pluginJarUrl); 564 } 565 566 // create a classloader for all plugins: 567 final URL[] jarUrls = allPluginLibraries.toArray(new URL[allPluginLibraries.size()]); 568 return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { 569 public ClassLoader run() { 570 return new URLClassLoader(jarUrls, Main.class.getClassLoader()); 571 } 572 }); 596 cl.addURL(pluginJarUrl); 597 } 573 598 } 574 599 … … 614 639 * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null. 615 640 */ 616 public static void loadPlugins(Component parent, Collection<PluginInformation> plugins, ProgressMonitor monitor) {641 public static void loadPlugins(Component parent, Collection<PluginInformation> plugins, ProgressMonitor monitor) { 617 642 if (monitor == null) { 618 643 monitor = NullProgressMonitor.INSTANCE; … … 644 669 return; 645 670 646 ClassLoader pluginClassLoader = createClassLoader(toLoad); 647 sources.add(0, pluginClassLoader); 671 extendPluginClassLoader(toLoad); 648 672 monitor.setTicksCount(toLoad.size()); 649 673 for (PluginInformation info : toLoad) { 650 674 monitor.setExtraText(tr("Loading plugin ''{0}''...", info.name)); 651 loadPlugin(parent, info, pluginClassLoader);675 loadPlugin(parent, info, getPluginClassLoader()); 652 676 monitor.worked(1); 653 677 } … … 1045 1069 * If {@code dowarn} is true, this methods emits warning messages on the console if a downloaded 1046 1070 * but not yet installed plugin .jar can't be be installed. If {@code dowarn} is false, the 1047 * installation of the respective plugin is sil lently skipped.1071 * installation of the respective plugin is silently skipped. 1048 1072 * 1049 1073 * @param dowarn if true, warning messages are displayed; false otherwise -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r7655 r8017 78 78 /** The plugin icon. */ 79 79 public ImageIcon icon; 80 /** Plugin can be loaded at any time and not just at start. */ 81 public boolean canloadatruntime = false; 80 82 /** The libraries referenced in Class-Path manifest attribute. */ 81 83 public List<URL> libraries = new LinkedList<>(); … … 169 171 this.icon = other.icon; 170 172 this.iconPath = other.iconPath; 173 this.canloadatruntime = other.canloadatruntime; 171 174 this.libraries = other.libraries; 172 175 this.attr.clear(); … … 189 192 this.early = other.early; 190 193 this.className = other.className; 194 this.canloadatruntime = other.canloadatruntime; 191 195 this.libraries = other.libraries; 192 196 this.stage = other.stage; … … 250 254 } 251 255 } 256 canloadatruntime = Boolean.parseBoolean(attr.getValue("Plugin-Canloadatruntime")); 252 257 if (oldcheck && mainversion > Version.getInstance().getVersion()) { 253 258 int myv = Version.getInstance().getVersion();
Note: See TracChangeset
for help on using the changeset viewer.