Changeset 6839 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2014-02-11T14:43:04+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r6830 r6839 380 380 if (!pluginsToLoad.isEmpty() && PluginHandler.checkAndConfirmPluginUpdate(splash)) { 381 381 monitor.subTask(tr("Updating plugins")); 382 pluginsToLoad = PluginHandler.updatePlugins(splash, null, monitor.createSubTaskMonitor(1, false) );382 pluginsToLoad = PluginHandler.updatePlugins(splash, null, monitor.createSubTaskMonitor(1, false), false); 383 383 } 384 384 -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r6822 r6839 122 122 }); 123 123 } 124 124 125 125 private PluginHandler() { 126 126 // Hide default constructor for utils classes … … 210 210 } 211 211 } 212 212 213 213 private static PluginDownloadTask pluginDownloadTask = null; 214 214 … … 825 825 * @param pluginsWanted the collection of plugins to update. Updates all plugins if {@code null} 826 826 * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null. 827 * @param displayErrMsg if {@code true}, a blocking error message is displayed in case of I/O exception. 827 828 * @throws IllegalArgumentException thrown if plugins is null 828 829 */ 829 830 public static Collection<PluginInformation> updatePlugins(Component parent, 830 Collection<PluginInformation> pluginsWanted, ProgressMonitor monitor )831 Collection<PluginInformation> pluginsWanted, ProgressMonitor monitor, boolean displayErrMsg) 831 832 throws IllegalArgumentException { 832 833 Collection<PluginInformation> plugins = null; … … 843 844 ReadRemotePluginInformationTask task1 = new ReadRemotePluginInformationTask( 844 845 monitor.createSubTaskMonitor(1,false), 845 Main.pref.getPluginSites() 846 Main.pref.getPluginSites(), displayErrMsg 846 847 ); 847 848 Future<?> future = service.submit(task1); … … 852 853 allPlugins = task1.getAvailablePlugins(); 853 854 plugins = buildListOfPluginsToLoad(parent,monitor.createSubTaskMonitor(1, false)); 854 // If only some plugins have to be updated, filter the list 855 // If only some plugins have to be updated, filter the list 855 856 if (pluginsWanted != null && !pluginsWanted.isEmpty()) { 856 857 for (Iterator<PluginInformation> it = plugins.iterator(); it.hasNext();) { … … 951 952 /** 952 953 * Ask the user for confirmation that a plugin shall be disabled. 953 * 954 * 954 955 * @param parent The parent component to be used for the displayed dialog 955 956 * @param reason the reason for disabling the plugin … … 1233 1234 case 0: 1234 1235 // update the plugin 1235 updatePlugins(Main.parent, Collections.singleton(pluginInfo), null );1236 updatePlugins(Main.parent, Collections.singleton(pluginInfo), null, true); 1236 1237 return pluginDownloadTask; 1237 1238 case 1: -
trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
r6643 r6839 55 55 private HttpURLConnection connection; 56 56 private List<PluginInformation> availablePlugins; 57 private boolean displayErrMsg; 57 58 58 59 protected enum CacheType {PLUGIN_LIST, ICON_LIST} 59 60 60 protected void init(Collection<String> sites ){61 protected void init(Collection<String> sites, boolean displayErrMsg){ 61 62 this.sites = sites; 62 63 if (sites == null) { 63 64 this.sites = Collections.emptySet(); 64 65 } 65 availablePlugins = new LinkedList<PluginInformation>();66 66 this.availablePlugins = new LinkedList<PluginInformation>(); 67 this.displayErrMsg = displayErrMsg; 67 68 } 68 69 /** … … 73 74 public ReadRemotePluginInformationTask(Collection<String> sites) { 74 75 super(tr("Download plugin list..."), false /* don't ignore exceptions */); 75 init(sites );76 init(sites, true); 76 77 } 77 78 … … 81 82 * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null 82 83 * @param sites the collection of download sites. Defaults to the empty collection if null. 83 */ 84 public ReadRemotePluginInformationTask(ProgressMonitor monitor, Collection<String> sites) { 84 * @param displayErrMsg if {@code true}, a blocking error message is displayed in case of I/O exception. 85 */ 86 public ReadRemotePluginInformationTask(ProgressMonitor monitor, Collection<String> sites, boolean displayErrMsg) { 85 87 super(tr("Download plugin list..."), monitor == null ? NullProgressMonitor.INSTANCE: monitor, false /* don't ignore exceptions */); 86 init(sites );88 init(sites, displayErrMsg); 87 89 } 88 90 … … 153 155 protected String downloadPluginList(String site, final ProgressMonitor monitor) { 154 156 BufferedReader in = null; 155 String line; 157 158 /* replace %<x> with empty string or x=plugins (separated with comma) */ 159 String pl = Utils.join(",", Main.pref.getCollection("plugins")); 160 String printsite = site.replaceAll("%<(.*)>", ""); 161 if (pl != null && pl.length() != 0) { 162 site = site.replaceAll("%<(.*)>", "$1"+pl); 163 } else { 164 site = printsite; 165 } 166 156 167 try { 157 /* replace %<x> with empty string or x=plugins (separated with comma) */158 String pl = Utils.join(",", Main.pref.getCollection("plugins"));159 String printsite = site.replaceAll("%<(.*)>", "");160 if(pl != null && pl.length() != 0) {161 site = site.replaceAll("%<(.*)>", "$1"+pl);162 } else {163 site = printsite;164 }165 166 168 monitor.beginTask(""); 167 169 monitor.indeterminateSubTask(tr("Downloading plugin list from ''{0}''", printsite)); … … 175 177 in = new BufferedReader(new InputStreamReader(connection.getInputStream(), Utils.UTF_8)); 176 178 StringBuilder sb = new StringBuilder(); 179 String line; 177 180 while ((line = in.readLine()) != null) { 178 181 sb.append(line).append("\n"); … … 185 188 } catch (IOException e) { 186 189 if (canceled) return null; 187 handleIOException(monitor, e, tr("Plugin list download error"), tr("JOSM failed to download plugin list:")); 190 Main.addNetworkError(site, e); 191 handleIOException(monitor, e, tr("Plugin list download error"), tr("JOSM failed to download plugin list:"), displayErrMsg); 188 192 return null; 189 193 } finally { … … 198 202 } 199 203 } 200 201 private void handleIOException(final ProgressMonitor monitor, IOException e, final String title, String firstMessage) {204 205 private void handleIOException(final ProgressMonitor monitor, IOException e, final String title, final String firstMessage, boolean displayMsg) { 202 206 InputStream errStream = connection.getErrorStream(); 203 207 StringBuilder sb = new StringBuilder(); … … 219 223 final String msg = e.getMessage(); 220 224 final String details = sb.toString(); 221 Main.error(details.isEmpty() ? msg : msg + " - Details:\n" + details); 222 225 if (details.isEmpty()) { 226 Main.error(e.getClass().getSimpleName()+": " + msg); 227 } else { 228 Main.error(msg + " - Details:\n" + details); 229 } 230 231 if (displayMsg) { 232 displayErrorMessage(monitor, msg, details, title, firstMessage); 233 } 234 } 235 236 private void displayErrorMessage(final ProgressMonitor monitor, final String msg, final String details, final String title, final String firstMessage) { 223 237 GuiHelper.runInEDTAndWait(new Runnable() { 224 238 @Override public void run() { 225 239 JPanel panel = new JPanel(new GridBagLayout()); 226 panel.add(new JLabel( tr("JOSM failed to download plugin list:")), GBC.eol().insets(0, 0, 0, 10));240 panel.add(new JLabel(firstMessage), GBC.eol().insets(0, 0, 0, 10)); 227 241 StringBuilder b = new StringBuilder(); 228 242 for (String part : msg.split("(?<=\\G.{200})")) { … … 277 291 } catch (IOException e) { 278 292 if (canceled) return; 279 handleIOException(monitor, e, tr("Plugin icons download error"), tr("JOSM failed to download plugin icons:") );293 handleIOException(monitor, e, tr("Plugin icons download error"), tr("JOSM failed to download plugin icons:"), displayErrMsg); 280 294 return; 281 295 } finally {
Note:
See TracChangeset
for help on using the changeset viewer.