Ticket #19098: 19098-real-fix.patch

File 19098-real-fix.patch, 6.1 KB (added by GerdP, 5 years ago)
  • src/org/openstreetmap/josm/gui/bugreport/BugReportDialog.java

     
    229229                    );
    230230            return SuppressionMode.NONE;
    231231        } else {
     232            PluginDownloadTask downloadTask = PluginHandler.updateOrdisablePluginAfterException(e);
    232233            return GuiHelper.runInEDTAndWaitAndReturn(() -> {
    233                 PluginDownloadTask downloadTask = PluginHandler.updateOrdisablePluginAfterException(e);
    234234                if (downloadTask != null) {
    235235                    // Ask for restart to install new plugin
    236236                    PluginPreference.notifyDownloadResults(
  • src/org/openstreetmap/josm/plugins/PluginHandler.java

     
    3737import java.util.TreeSet;
    3838import java.util.concurrent.CopyOnWriteArrayList;
    3939import java.util.concurrent.ExecutionException;
     40import java.util.concurrent.ExecutorService;
     41import java.util.concurrent.Future;
    4042import java.util.concurrent.FutureTask;
    4143import java.util.concurrent.TimeUnit;
    4244import java.util.jar.JarFile;
     
    6466import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
    6567import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    6668import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     69import org.openstreetmap.josm.gui.progress.swing.ProgressMonitorExecutor;
    6770import org.openstreetmap.josm.gui.util.GuiHelper;
    6871import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    6972import org.openstreetmap.josm.gui.widgets.JosmTextArea;
     
    953956            monitor = NullProgressMonitor.INSTANCE;
    954957        }
    955958        try {
     959            Map<String, PluginInformation> ret = new HashMap<>();
     960            ExecutorService service = new ProgressMonitorExecutor("plugin-loader-%d", Thread.NORM_PRIORITY);
    956961            ReadLocalPluginInformationTask task = new ReadLocalPluginInformationTask(monitor);
     962            Future<?> future = service.submit(task);
    957963            try {
    958                 task.run();
    959             } catch (RuntimeException e) { // NOPMD
     964                future.get();
     965            } catch (ExecutionException e) {
    960966                Logging.error(e);
    961                 return null;
     967                return ret;
     968            } catch (InterruptedException e) {
     969                Logging.warn("InterruptedException in " + PluginHandler.class.getSimpleName()
     970                        + " while loading locally available plugin information");
     971                return ret;
    962972            }
    963             Map<String, PluginInformation> ret = new HashMap<>();
    964973            for (PluginInformation pi: task.getAvailablePlugins()) {
    965974                ret.put(pi.name, pi);
    966975            }
     
    11121121        }
    11131122        try {
    11141123            monitor.beginTask("");
     1124            ExecutorService service = new ProgressMonitorExecutor("plugin-updater-%d", Thread.NORM_PRIORITY);
    11151125
    11161126            // try to download the plugin lists
    11171127            ReadRemotePluginInformationTask task1 = new ReadRemotePluginInformationTask(
    11181128                    monitor.createSubTaskMonitor(1, false),
    11191129                    Preferences.main().getOnlinePluginSites(), displayErrMsg
    1120             );
    1121             task1.run();
    1122             List<PluginInformation> allPlugins = task1.getAvailablePlugins();
     1130                    );
     1131            List<PluginInformation> allPlugins = null;
     1132            Future<?> future = service.submit(task1);
    11231133
    11241134            try {
     1135                future.get();
     1136                allPlugins = task1.getAvailablePlugins();
    11251137                plugins = buildListOfPluginsToLoad(parent, monitor.createSubTaskMonitor(1, false));
    11261138                // If only some plugins have to be updated, filter the list
    11271139                if (pluginsWanted != null && !pluginsWanted.isEmpty()) {
     
    11281140                    final Collection<String> pluginsWantedName = Utils.transform(pluginsWanted, piw -> piw.name);
    11291141                    plugins = SubclassFilteredCollection.filter(plugins, pi -> pluginsWantedName.contains(pi.name));
    11301142                }
    1131             } catch (RuntimeException e) { // NOPMD
    1132                 Logging.warn(tr("Failed to download plugin information list"));
     1143            } catch (ExecutionException e) {
     1144                Logging.warn(tr("Failed to download plugin information list") + ": ExecutionException");
    11331145                Logging.error(e);
    11341146                // don't abort in case of error, continue with downloading plugins below
     1147            } catch (InterruptedException e) {
     1148                Logging.warn(tr("Failed to download plugin information list") + ": InterruptedException");
     1149                // don't abort in case of error, continue with downloading plugins below
    11351150            }
    11361151
    11371152            // filter plugins which actually have to be updated
     
    11691184                        monitor.createSubTaskMonitor(1, false),
    11701185                        pluginsToDownload,
    11711186                        tr("Update plugins")
    1172                 );
     1187                        );
     1188                future = service.submit(pluginDownloadTask);
     1189
    11731190                try {
    1174                     pluginDownloadTask.run();
    1175                 } catch (RuntimeException e) { // NOPMD
     1191                    future.get();
     1192                } catch (ExecutionException e) {
    11761193                    Logging.error(e);
    11771194                    alertFailedPluginUpdate(parent, pluginsToUpdate);
    11781195                    return plugins;
     1196                } catch (InterruptedException e) {
     1197                    Logging.warn("InterruptedException in " + PluginHandler.class.getSimpleName()
     1198                            + " while updating plugins");
     1199                    alertFailedPluginUpdate(parent, pluginsToUpdate);
     1200                    return plugins;
    11791201                }
    11801202
    11811203                // Update Plugin info for downloaded plugins