Changes in trunk [12322:12321] in josm


Ignore:
Location:
trunk/src/org/openstreetmap/josm/plugins
Files:
1 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r12322 r12321  
    290290
    291291    /**
    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;
    296295
    297296    /**
     
    710709
    711710    /**
    712      * Method to get the (now obsolete) class loader for loading plugin code.
     711     * Get the class loader for loading plugin code.
    713712     *
    714713     * @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     */
    720715    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>)
    735718                    () -> 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 resource class loader.
    743      *
    744      * @param plugins the plugins to add
    745      */
    746     private static 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) {
    747730        // iterate all plugins and collect all libraries of all plugins:
    748731        File pluginDir = Main.pref.getPluginsDirectory();
    749         DynamicURLClassLoader cl = getJoinedPluginResourceCL();
     732        DynamicURLClassLoader cl = getPluginClassLoader();
    750733
    751734        for (PluginInformation info : plugins) {
     
    771754     * @param pluginClassLoader the plugin class loader
    772755     */
    773     private static void loadPlugin(Component parent, PluginInformation plugin, PluginClassLoader pluginClassLoader) {
     756    public static void loadPlugin(Component parent, PluginInformation plugin, ClassLoader pluginClassLoader) {
    774757        String msg = tr("Could not load plugin {0}. Delete from preferences?", plugin.name);
    775758        try {
     
    777760            if (klass != null) {
    778761                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);
    780763                pluginList.add(pluginProxy);
    781764                Main.addAndFireMapFrameListener(pluginProxy);
     
    825808                return;
    826809
    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);
    857811            monitor.setTicksCount(toLoad.size());
    858812            for (PluginInformation info : toLoad) {
    859813                monitor.setExtraText(tr("Loading plugin ''{0}''...", info.name));
    860                 loadPlugin(parent, info, classLoaders.get(info));
     814                loadPlugin(parent, info, getPluginClassLoader());
    861815                monitor.worked(1);
    862816            }
     
    12081162        for (PluginProxy plugin : pluginList) {
    12091163            if (plugin.getPluginInformation().name.equals(name))
    1210                 return plugin.getPlugin();
     1164                return plugin.plugin;
    12111165        }
    12121166        return null;
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r12322 r12321  
    316316     *
    317317     * @param klass the plugin class
    318      * @param classLoader the class loader for the plugin
    319318     * @return the instantiated and initialized plugin
    320319     * @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 {
    324322        try {
    325323            Constructor<?> c = klass.getConstructor(PluginInformation.class);
    326324            Object plugin = c.newInstance(this);
    327             return new PluginProxy(plugin, this, classLoader);
     325            return new PluginProxy(plugin, this);
    328326        } catch (ReflectiveOperationException e) {
    329327            throw new PluginException(name, e);
  • trunk/src/org/openstreetmap/josm/plugins/PluginProxy.java

    r12322 r12321  
    2222     * The plugin.
    2323     */
    24     private final Object plugin;
    25     private final PluginClassLoader classLoader;
     24    public final Object plugin;
    2625
    2726    /**
     
    2928     * @param plugin the plugin
    3029     * @param info the associated plugin info
    31      * @param classLoader the class loader for the plugin
    32      * @since 12322
    3330     */
    34     public PluginProxy(Object plugin, PluginInformation info, PluginClassLoader classLoader) {
     31    public PluginProxy(Object plugin, PluginInformation info) {
    3532        super(info);
    3633        this.plugin = plugin;
    37         this.classLoader = classLoader;
    38     }
    39 
    40     /**
    41      * Get the plugin object.
    42      * @return the plugin object
    43      * @since 12322
    44      */
    45     public Object getPlugin() {
    46         return plugin;
    47     }
    48 
    49     /**
    50      * Get the class loader for the plugin.
    51      * @return the plugin class loader
    52      * @since 12322
    53      */
    54     public PluginClassLoader getClassLoader() {
    55         return classLoader;
    5634    }
    5735
Note: See TracChangeset for help on using the changeset viewer.