Ticket #22381: 22381.patch

File 22381.patch, 3.0 KB (added by taylor.smock, 3 years ago)
  • src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java

    Subject: [PATCH] #22381: Plugins with new dependencies don't have those dependencies automatically downloaded
    ---
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    diff --git a/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java b/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
    a b  
    1717import java.util.ArrayList;
    1818import java.util.Collection;
    1919import java.util.Collections;
     20import java.util.HashSet;
    2021import java.util.LinkedList;
    2122import java.util.List;
    2223import java.util.Set;
     
    431432                    alertNothingToUpdate();
    432433                    return;
    433434                }
     435                int toUpdateSize;
     436                boolean refreshRequired = false;
     437                do {
     438                    toUpdateSize = toUpdate.size();
     439                    Set<PluginInformation> enabledPlugins = new HashSet<>(PluginHandler.getPlugins());
     440                    enabledPlugins.addAll(toUpdate);
     441                    Set<PluginInformation> toAdd = new HashSet<>();
     442                    for (PluginInformation pi : toUpdate) {
     443                        if (!PluginHandler.checkRequiredPluginsPreconditions(null, enabledPlugins, pi, false)) {
     444                            // Time to find the missing plugins...
     445                            toAdd.addAll(pi.getRequiredPlugins().stream().filter(plugin -> PluginHandler.getPlugin(plugin) == null)
     446                                    .map(plugin -> model.getPluginInformation(plugin))
     447                                    .collect(Collectors.toSet()));
     448                        }
     449                    }
     450                    toAdd.forEach(plugin -> model.setPluginSelected(plugin.name, true));
     451                    refreshRequired |= !toAdd.isEmpty(); // We need to force refresh the checkboxes if we are adding new plugins
     452                    toAdd.removeIf(plugin -> !plugin.isUpdateRequired()); // Avoid downloading plugins that already exist
     453                    toUpdate.addAll(toAdd);
     454                } while (toUpdateSize != toUpdate.size());
     455
    434456                pluginDownloadTask.setPluginsToDownload(toUpdate);
    435457                MainApplication.worker.submit(pluginDownloadTask);
    436458                MainApplication.worker.submit(pluginDownloadContinuation);
     459                if (refreshRequired) {
     460                    // Needed since we need to recreate the checkboxes to show the enabled dependent plugins that were not previously enabled
     461                    pnlPluginPreferences.resetDisplayedComponents();
     462                }
     463                GuiHelper.runInEDT(pnlPluginPreferences::refreshView);
    437464            };
    438465
    439466            MainApplication.worker.submit(pluginInfoDownloadTask);