Ticket #19098: 19098-try-revert.patch
File 19098-try-revert.patch, 4.9 KB (added by , 4 years ago) |
---|
-
src/org/openstreetmap/josm/plugins/PluginHandler.java
37 37 import java.util.TreeSet; 38 38 import java.util.concurrent.CopyOnWriteArrayList; 39 39 import java.util.concurrent.ExecutionException; 40 import java.util.concurrent.ExecutorService; 41 import java.util.concurrent.Executors; 42 import java.util.concurrent.Future; 40 43 import java.util.concurrent.FutureTask; 41 44 import java.util.concurrent.TimeUnit; 42 45 import java.util.jar.JarFile; … … 957 960 monitor = NullProgressMonitor.INSTANCE; 958 961 } 959 962 try { 963 Map<String, PluginInformation> ret = new HashMap<>(); 964 ExecutorService service = Executors.newSingleThreadExecutor(Utils.newThreadFactory("plugin-loader-%d", Thread.NORM_PRIORITY)); 960 965 ReadLocalPluginInformationTask task = new ReadLocalPluginInformationTask(monitor); 966 Future<?> future = service.submit(task); 961 967 try { 962 task.run();963 } catch ( RuntimeException e) { // NOPMD968 future.get(); 969 } catch (ExecutionException e) { 964 970 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; 966 976 } 967 Map<String, PluginInformation> ret = new HashMap<>();968 977 for (PluginInformation pi: task.getAvailablePlugins()) { 969 978 ret.put(pi.name, pi); 970 979 } … … 1116 1125 } 1117 1126 try { 1118 1127 monitor.beginTask(""); 1128 ExecutorService service = Executors.newSingleThreadExecutor(Utils.newThreadFactory("plugin-updater-%d", Thread.NORM_PRIORITY)); 1119 1129 1120 1130 // try to download the plugin lists 1121 1131 ReadRemotePluginInformationTask task1 = new ReadRemotePluginInformationTask( 1122 1132 monitor.createSubTaskMonitor(1, false), 1123 1133 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); 1127 1137 1128 1138 try { 1139 future.get(); 1140 allPlugins = task1.getAvailablePlugins(); 1129 1141 plugins = buildListOfPluginsToLoad(parent, monitor.createSubTaskMonitor(1, false)); 1130 1142 // If only some plugins have to be updated, filter the list 1131 1143 if (pluginsWanted != null && !pluginsWanted.isEmpty()) { … … 1132 1144 final Collection<String> pluginsWantedName = Utils.transform(pluginsWanted, piw -> piw.name); 1133 1145 plugins = SubclassFilteredCollection.filter(plugins, pi -> pluginsWantedName.contains(pi.name)); 1134 1146 } 1135 } catch ( RuntimeException e) { // NOPMD1136 Logging.warn(tr("Failed to download plugin information list") );1147 } catch (ExecutionException e) { 1148 Logging.warn(tr("Failed to download plugin information list") + ": ExecutionException"); 1137 1149 Logging.error(e); 1138 1150 // 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 1139 1154 } 1140 1155 1141 1156 // filter plugins which actually have to be updated … … 1173 1188 monitor.createSubTaskMonitor(1, false), 1174 1189 pluginsToDownload, 1175 1190 tr("Update plugins") 1176 ); 1191 ); 1192 future = service.submit(pluginDownloadTask); 1193 1177 1194 try { 1178 pluginDownloadTask.run();1179 } catch ( RuntimeException e) { // NOPMD1195 future.get(); 1196 } catch (ExecutionException e) { 1180 1197 Logging.error(e); 1181 1198 alertFailedPluginUpdate(parent, pluginsToUpdate); 1182 1199 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; 1183 1205 } 1184 1206 1185 1207 // Update Plugin info for downloaded plugins