Changeset 18694 in josm for trunk/src


Ignore:
Timestamp:
2023-03-16T22:09:01+01:00 (14 months ago)
Author:
taylor.smock
Message:

Fix #22381: Try to automatically install newly required plugins on plugin update

This additionally updates the plugin tests to JUnit 5 (see #16567). Some tests
required fixing (for example, MinimapDialogTest fails if the system of
measurement is metric).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java

    r18211 r18694  
    1818import java.util.Collection;
    1919import java.util.Collections;
     20import java.util.HashSet;
    2021import java.util.LinkedList;
    2122import java.util.List;
     
    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
Note: See TracChangeset for help on using the changeset viewer.