Changeset 6839 in josm for trunk/src


Ignore:
Timestamp:
2014-02-11T14:43:04+01:00 (6 years ago)
Author:
Don-vip
Message:

do not block start when plugin list cannot be retrieved, save the error for later display in global network errors message dialog

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r6830 r6839  
    380380        if (!pluginsToLoad.isEmpty() && PluginHandler.checkAndConfirmPluginUpdate(splash)) {
    381381            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);
    383383        }
    384384
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r6822 r6839  
    122122        });
    123123    }
    124    
     124
    125125    private PluginHandler() {
    126126        // Hide default constructor for utils classes
     
    210210        }
    211211    }
    212    
     212
    213213    private static PluginDownloadTask pluginDownloadTask = null;
    214214
     
    825825     * @param pluginsWanted the collection of plugins to update. Updates all plugins if {@code null}
    826826     * @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.
    827828     * @throws IllegalArgumentException thrown if plugins is null
    828829     */
    829830    public static Collection<PluginInformation> updatePlugins(Component parent,
    830             Collection<PluginInformation> pluginsWanted, ProgressMonitor monitor)
     831            Collection<PluginInformation> pluginsWanted, ProgressMonitor monitor, boolean displayErrMsg)
    831832            throws IllegalArgumentException {
    832833        Collection<PluginInformation> plugins = null;
     
    843844            ReadRemotePluginInformationTask task1 = new ReadRemotePluginInformationTask(
    844845                    monitor.createSubTaskMonitor(1,false),
    845                     Main.pref.getPluginSites()
     846                    Main.pref.getPluginSites(), displayErrMsg
    846847            );
    847848            Future<?> future = service.submit(task1);
     
    852853                allPlugins = task1.getAvailablePlugins();
    853854                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
    855856                if (pluginsWanted != null && !pluginsWanted.isEmpty()) {
    856857                    for (Iterator<PluginInformation> it = plugins.iterator(); it.hasNext();) {
     
    951952    /**
    952953     * Ask the user for confirmation that a plugin shall be disabled.
    953      * 
     954     *
    954955     * @param parent The parent component to be used for the displayed dialog
    955956     * @param reason the reason for disabling the plugin
     
    12331234        case 0:
    12341235            // update the plugin
    1235             updatePlugins(Main.parent, Collections.singleton(pluginInfo), null);
     1236            updatePlugins(Main.parent, Collections.singleton(pluginInfo), null, true);
    12361237            return pluginDownloadTask;
    12371238        case 1:
  • trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java

    r6643 r6839  
    5555    private HttpURLConnection connection;
    5656    private List<PluginInformation> availablePlugins;
     57    private boolean displayErrMsg;
    5758
    5859    protected enum CacheType {PLUGIN_LIST, ICON_LIST}
    5960
    60     protected void init(Collection<String> sites){
     61    protected void init(Collection<String> sites, boolean displayErrMsg){
    6162        this.sites = sites;
    6263        if (sites == null) {
    6364            this.sites = Collections.emptySet();
    6465        }
    65         availablePlugins = new LinkedList<PluginInformation>();
    66 
     66        this.availablePlugins = new LinkedList<PluginInformation>();
     67        this.displayErrMsg = displayErrMsg;
    6768    }
    6869    /**
     
    7374    public ReadRemotePluginInformationTask(Collection<String> sites) {
    7475        super(tr("Download plugin list..."), false /* don't ignore exceptions */);
    75         init(sites);
     76        init(sites, true);
    7677    }
    7778
     
    8182     * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null
    8283     * @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) {
    8587        super(tr("Download plugin list..."), monitor == null ? NullProgressMonitor.INSTANCE: monitor, false /* don't ignore exceptions */);
    86         init(sites);
     88        init(sites, displayErrMsg);
    8789    }
    8890
     
    153155    protected String downloadPluginList(String site, final ProgressMonitor monitor) {
    154156        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
    156167        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 
    166168            monitor.beginTask("");
    167169            monitor.indeterminateSubTask(tr("Downloading plugin list from ''{0}''", printsite));
     
    175177            in = new BufferedReader(new InputStreamReader(connection.getInputStream(), Utils.UTF_8));
    176178            StringBuilder sb = new StringBuilder();
     179            String line;
    177180            while ((line = in.readLine()) != null) {
    178181                sb.append(line).append("\n");
     
    185188        } catch (IOException e) {
    186189            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);
    188192            return null;
    189193        } finally {
     
    198202        }
    199203    }
    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) {
    202206        InputStream errStream = connection.getErrorStream();
    203207        StringBuilder sb = new StringBuilder();
     
    219223        final String msg = e.getMessage();
    220224        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) {
    223237        GuiHelper.runInEDTAndWait(new Runnable() {
    224238            @Override public void run() {
    225239                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));
    227241                StringBuilder b = new StringBuilder();
    228242                for (String part : msg.split("(?<=\\G.{200})")) {
     
    277291        } catch (IOException e) {
    278292            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);
    280294            return;
    281295        } finally {
Note: See TracChangeset for help on using the changeset viewer.