Ignore:
Timestamp:
2018-01-07T22:54:01+01:00 (6 years ago)
Author:
Don-vip
Message:

fix #15554 - fix plugin classloader after plugin update

File:
1 edited

Legend:

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

    r13173 r13294  
    1616import java.io.FilenameFilter;
    1717import java.io.IOException;
     18import java.net.MalformedURLException;
    1819import java.net.URL;
    1920import java.net.URLClassLoader;
     
    12341235
    12351236    /**
    1236      * Installs downloaded plugins. Moves files with the suffix ".jar.new" to the corresponding
    1237      * ".jar" files.
     1237     * Installs downloaded plugins. Moves files with the suffix ".jar.new" to the corresponding ".jar" files.
    12381238     *
    12391239     * If {@code dowarn} is true, this methods emits warning messages on the console if a downloaded
     
    12411241     * installation of the respective plugin is silently skipped.
    12421242     *
     1243     * @param pluginsToLoad list of plugin informations to update
    12431244     * @param dowarn if true, warning messages are displayed; false otherwise
    1244      */
    1245     public static void installDownloadedPlugins(boolean dowarn) {
     1245     * @since 13294
     1246     */
     1247    public static void installDownloadedPlugins(Collection<PluginInformation> pluginsToLoad, boolean dowarn) {
    12461248        File pluginDir = Main.pref.getPluginsDirectory();
    12471249        if (!pluginDir.exists() || !pluginDir.isDirectory() || !pluginDir.canWrite())
     
    12741276            }
    12751277            // Install plugin
    1276             if (!updatedPlugin.renameTo(plugin) && dowarn) {
     1278            if (updatedPlugin.renameTo(plugin)) {
     1279                try {
     1280                    // Update plugin URL
     1281                    URL newPluginURL = plugin.toURI().toURL();
     1282                    URL oldPluginURL = updatedPlugin.toURI().toURL();
     1283                    pluginsToLoad.stream().filter(x -> x.libraries.contains(oldPluginURL)).forEach(
     1284                            x -> Collections.replaceAll(x.libraries, oldPluginURL, newPluginURL));
     1285                } catch (MalformedURLException e) {
     1286                    Logging.warn(e);
     1287                }
     1288            } else if (dowarn) {
    12771289                Logging.warn(tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. Renaming failed.",
    12781290                        plugin.toString(), updatedPlugin.toString()));
Note: See TracChangeset for help on using the changeset viewer.