Changes in trunk [12322:12321] in josm
- Location:
- trunk/src/org/openstreetmap/josm/plugins
- Files:
-
- 1 deleted
- 3 edited
-
PluginClassLoader.java (deleted)
-
PluginHandler.java (modified) (6 diffs)
-
PluginInformation.java (modified) (1 diff)
-
PluginProxy.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r12322 r12321 290 290 291 291 /** 292 * Class loader to locate resources from plugins. 293 * @see #getJoinedPluginResourceCL() 294 */ 295 private static DynamicURLClassLoader joinedPluginResourceCL; 292 * Global plugin ClassLoader. 293 */ 294 private static DynamicURLClassLoader pluginClassLoader; 296 295 297 296 /** … … 710 709 711 710 /** 712 * Method to get the (now obsolete)class loader for loading plugin code.711 * Get the class loader for loading plugin code. 713 712 * 714 713 * @return the class loader 715 * @deprecated There is no longer a unified plugin class loader. Use {@link PluginProxy#classLoader} 716 * to get the class loader for each plugin. Or <code>PluginClass.class.getClassLoader()</code> 717 * to access the class loader from within the plugin. 718 */ 719 @Deprecated 714 */ 720 715 public static synchronized DynamicURLClassLoader getPluginClassLoader() { 721 return getJoinedPluginResourceCL(); 722 } 723 724 /** 725 * Get class loader to locate resources from plugins. 726 * 727 * It joins URLs of all plugins, to find images, etc. 728 * (Not for loading Java classes - each plugin has a separate {@link PluginClassLoader} 729 * for that purpose.) 730 * @return class loader to locate resources from plugins 731 */ 732 private static synchronized DynamicURLClassLoader getJoinedPluginResourceCL() { 733 if (joinedPluginResourceCL == null) { 734 joinedPluginResourceCL = AccessController.doPrivileged((PrivilegedAction<DynamicURLClassLoader>) 716 if (pluginClassLoader == null) { 717 pluginClassLoader = AccessController.doPrivileged((PrivilegedAction<DynamicURLClassLoader>) 735 718 () -> new DynamicURLClassLoader(new URL[0], Main.class.getClassLoader())); 736 sources.add(0, joinedPluginResourceCL);737 } 738 return joinedPluginResourceCL;739 } 740 741 /** 742 * Add more plugins to the joined plugin resourceclass loader.743 * 744 * @param plugins the plugins t o add745 */ 746 p rivatestatic void extendJoinedPluginResourceCL(Collection<PluginInformation> plugins) {719 sources.add(0, pluginClassLoader); 720 } 721 return pluginClassLoader; 722 } 723 724 /** 725 * Add more plugins to the plugin class loader. 726 * 727 * @param plugins the plugins that should be handled by the plugin class loader 728 */ 729 public static void extendPluginClassLoader(Collection<PluginInformation> plugins) { 747 730 // iterate all plugins and collect all libraries of all plugins: 748 731 File pluginDir = Main.pref.getPluginsDirectory(); 749 DynamicURLClassLoader cl = get JoinedPluginResourceCL();732 DynamicURLClassLoader cl = getPluginClassLoader(); 750 733 751 734 for (PluginInformation info : plugins) { … … 771 754 * @param pluginClassLoader the plugin class loader 772 755 */ 773 p rivatestatic void loadPlugin(Component parent, PluginInformation plugin,PluginClassLoader pluginClassLoader) {756 public static void loadPlugin(Component parent, PluginInformation plugin, ClassLoader pluginClassLoader) { 774 757 String msg = tr("Could not load plugin {0}. Delete from preferences?", plugin.name); 775 758 try { … … 777 760 if (klass != null) { 778 761 Main.info(tr("loading plugin ''{0}'' (version {1})", plugin.name, plugin.localversion)); 779 PluginProxy pluginProxy = plugin.load(klass , pluginClassLoader);762 PluginProxy pluginProxy = plugin.load(klass); 780 763 pluginList.add(pluginProxy); 781 764 Main.addAndFireMapFrameListener(pluginProxy); … … 825 808 return; 826 809 827 Map<PluginInformation, PluginClassLoader> classLoaders = new HashMap<>(); 828 for (PluginInformation info : toLoad) { 829 classLoaders.put(info, new PluginClassLoader( 830 info.libraries.toArray(new URL[0]), 831 Main.class.getClassLoader(), 832 null)); 833 } 834 835 // resolve dependencies 836 for (PluginInformation info : toLoad) { 837 PluginClassLoader cl = classLoaders.get(info); 838 DEPENDENCIES: 839 for (String depName : info.getRequiredPlugins()) { 840 for (PluginInformation depInfo : toLoad) { 841 if (depInfo.getName().equals(depName)) { 842 cl.addDependency(classLoaders.get(depInfo)); 843 continue DEPENDENCIES; 844 } 845 } 846 for (PluginProxy proxy : pluginList) { 847 if (proxy.getPluginInformation().getName().equals(depName)) { 848 cl.addDependency(proxy.getClassLoader()); 849 continue DEPENDENCIES; 850 } 851 } 852 throw new AssertionError("unable to find dependency " + depName + " for plugin " + info.getName()); 853 } 854 } 855 856 extendJoinedPluginResourceCL(toLoad); 810 extendPluginClassLoader(toLoad); 857 811 monitor.setTicksCount(toLoad.size()); 858 812 for (PluginInformation info : toLoad) { 859 813 monitor.setExtraText(tr("Loading plugin ''{0}''...", info.name)); 860 loadPlugin(parent, info, classLoaders.get(info));814 loadPlugin(parent, info, getPluginClassLoader()); 861 815 monitor.worked(1); 862 816 } … … 1208 1162 for (PluginProxy plugin : pluginList) { 1209 1163 if (plugin.getPluginInformation().name.equals(name)) 1210 return plugin. getPlugin();1164 return plugin.plugin; 1211 1165 } 1212 1166 return null; -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r12322 r12321 316 316 * 317 317 * @param klass the plugin class 318 * @param classLoader the class loader for the plugin319 318 * @return the instantiated and initialized plugin 320 319 * @throws PluginException if the plugin cannot be loaded or instanciated 321 * @since 12322 322 */ 323 public PluginProxy load(Class<?> klass, PluginClassLoader classLoader) throws PluginException { 320 */ 321 public PluginProxy load(Class<?> klass) throws PluginException { 324 322 try { 325 323 Constructor<?> c = klass.getConstructor(PluginInformation.class); 326 324 Object plugin = c.newInstance(this); 327 return new PluginProxy(plugin, this , classLoader);325 return new PluginProxy(plugin, this); 328 326 } catch (ReflectiveOperationException e) { 329 327 throw new PluginException(name, e); -
trunk/src/org/openstreetmap/josm/plugins/PluginProxy.java
r12322 r12321 22 22 * The plugin. 23 23 */ 24 private final Object plugin; 25 private final PluginClassLoader classLoader; 24 public final Object plugin; 26 25 27 26 /** … … 29 28 * @param plugin the plugin 30 29 * @param info the associated plugin info 31 * @param classLoader the class loader for the plugin32 * @since 1232233 30 */ 34 public PluginProxy(Object plugin, PluginInformation info , PluginClassLoader classLoader) {31 public PluginProxy(Object plugin, PluginInformation info) { 35 32 super(info); 36 33 this.plugin = plugin; 37 this.classLoader = classLoader;38 }39 40 /**41 * Get the plugin object.42 * @return the plugin object43 * @since 1232244 */45 public Object getPlugin() {46 return plugin;47 }48 49 /**50 * Get the class loader for the plugin.51 * @return the plugin class loader52 * @since 1232253 */54 public PluginClassLoader getClassLoader() {55 return classLoader;56 34 } 57 35
Note:
See TracChangeset
for help on using the changeset viewer.
