Ticket #19098: 19098-try-revert.patch

File 19098-try-revert.patch, 4.9 KB (added by GerdP, 4 years ago)

don't commit!

  • 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.Executors;
     42import java.util.concurrent.Future;
    4043import java.util.concurrent.FutureTask;
    4144import java.util.concurrent.TimeUnit;
    4245import java.util.jar.JarFile;
     
    957960            monitor = NullProgressMonitor.INSTANCE;
    958961        }
    959962        try {
     963            Map<String, PluginInformation> ret = new HashMap<>();
     964            ExecutorService service = Executors.newSingleThreadExecutor(Utils.newThreadFactory("plugin-loader-%d", Thread.NORM_PRIORITY));
    960965            ReadLocalPluginInformationTask task = new ReadLocalPluginInformationTask(monitor);
     966            Future<?> future = service.submit(task);
    961967            try {
    962                 task.run();
    963             } catch (RuntimeException e) { // NOPMD
     968                future.get();
     969            } catch (ExecutionException e) {
    964970                Logging.error(e);
    965                 return null;
     971                return ret;
     972            } catch (InterruptedException e) {
     973                Logging.warn("InterruptedException in " + PluginHandler.class.getSimpleName()
     974                        + " while loading locally available plugin information");
     975                return ret;
    966976            }
    967             Map<String, PluginInformation> ret = new HashMap<>();
    968977            for (PluginInformation pi: task.getAvailablePlugins()) {
    969978                ret.put(pi.name, pi);
    970979            }
     
    11161125        }
    11171126        try {
    11181127            monitor.beginTask("");
     1128            ExecutorService service = Executors.newSingleThreadExecutor(Utils.newThreadFactory("plugin-updater-%d", Thread.NORM_PRIORITY));
    11191129
    11201130            // try to download the plugin lists
    11211131            ReadRemotePluginInformationTask task1 = new ReadRemotePluginInformationTask(
    11221132                    monitor.createSubTaskMonitor(1, false),
    11231133                    Preferences.main().getOnlinePluginSites(), displayErrMsg
    1124             );
    1125             task1.run();
    1126             List<PluginInformation> allPlugins = task1.getAvailablePlugins();
     1134                    );
     1135            List<PluginInformation> allPlugins = null;
     1136            Future<?> future = service.submit(task1);
    11271137
    11281138            try {
     1139                future.get();
     1140                allPlugins = task1.getAvailablePlugins();
    11291141                plugins = buildListOfPluginsToLoad(parent, monitor.createSubTaskMonitor(1, false));
    11301142                // If only some plugins have to be updated, filter the list
    11311143                if (pluginsWanted != null && !pluginsWanted.isEmpty()) {
     
    11321144                    final Collection<String> pluginsWantedName = Utils.transform(pluginsWanted, piw -> piw.name);
    11331145                    plugins = SubclassFilteredCollection.filter(plugins, pi -> pluginsWantedName.contains(pi.name));
    11341146                }
    1135             } catch (RuntimeException e) { // NOPMD
    1136                 Logging.warn(tr("Failed to download plugin information list"));
     1147            } catch (ExecutionException e) {
     1148                Logging.warn(tr("Failed to download plugin information list") + ": ExecutionException");
    11371149                Logging.error(e);
    11381150                // don't abort in case of error, continue with downloading plugins below
     1151            } catch (InterruptedException e) {
     1152                Logging.warn(tr("Failed to download plugin information list") + ": InterruptedException");
     1153                // don't abort in case of error, continue with downloading plugins below
    11391154            }
    11401155
    11411156            // filter plugins which actually have to be updated
     
    11731188                        monitor.createSubTaskMonitor(1, false),
    11741189                        pluginsToDownload,
    11751190                        tr("Update plugins")
    1176                 );
     1191                        );
     1192                future = service.submit(pluginDownloadTask);
     1193
    11771194                try {
    1178                     pluginDownloadTask.run();
    1179                 } catch (RuntimeException e) { // NOPMD
     1195                    future.get();
     1196                } catch (ExecutionException e) {
    11801197                    Logging.error(e);
    11811198                    alertFailedPluginUpdate(parent, pluginsToUpdate);
    11821199                    return plugins;
     1200                } catch (InterruptedException e) {
     1201                    Logging.warn("InterruptedException in " + PluginHandler.class.getSimpleName()
     1202                            + " while updating plugins");
     1203                    alertFailedPluginUpdate(parent, pluginsToUpdate);
     1204                    return plugins;
    11831205                }
    11841206
    11851207                // Update Plugin info for downloaded plugins