Ignore:
Timestamp:
2016-01-25T00:36:01+01:00 (8 years ago)
Author:
Don-vip
Message:

see #10588 - properly manage exception feedback in PluginDownloadTask. Removes a Findbugs warning

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java

    r9309 r9621  
    3030 * When the task is finished {@link #getDownloadedPlugins()} replies the list of downloaded plugins
    3131 * and {@link #getFailedPlugins()} replies the list of failed plugins.
    32  *
     32 * @since 2817
    3333 */
    3434public class PluginDownloadTask extends PleaseWaitRunnable {
     
    4343    private final Collection<PluginInformation> failed = new LinkedList<>();
    4444    private final Collection<PluginInformation> downloaded = new LinkedList<>();
     45    private Exception lastException;
    4546    private boolean canceled;
    4647    private HttpClient downloadConnection;
     
    9798
    9899    @Override
    99     protected void finish() {}
     100    protected void finish() {
     101        // Do nothing. Error/success feedback is managed in PluginPreference.notifyDownloadResults()
     102    }
    100103
    101104    protected void download(PluginInformation pi, File file) throws PluginDownloadException {
     
    150153        File pluginDir = Main.pref.getPluginsDirectory();
    151154        if (!pluginDir.exists() && !pluginDir.mkdirs()) {
    152             /*lastException =*/ new PluginDownloadException(tr("Failed to create plugin directory ''{0}''", pluginDir.toString()));
     155            String message = tr("Failed to create plugin directory ''{0}''", pluginDir.toString());
     156            lastException = new PluginDownloadException(message);
     157            Main.error(message);
    153158            failed.addAll(toUpdate);
    154159            return;
     
    156161        getProgressMonitor().setTicksCount(toUpdate.size());
    157162        for (PluginInformation d : toUpdate) {
    158             if (canceled) return;
     163            if (canceled)
     164                return;
    159165            String message = tr("Downloading Plugin {0}...", d.name);
    160166            Main.info(message);
     
    165171                download(d, pluginFile);
    166172            } catch (PluginDownloadException e) {
     173                lastException = e;
    167174                Main.error(e);
    168175                failed.add(d);
     
    200207        return downloaded;
    201208    }
     209
     210    /**
     211     * Replies the last exception that occured during download, or {@code null}.
     212     * @return the last exception that occured during download, or {@code null}
     213     * @since 9621
     214     */
     215    public Exception getLastException() {
     216        return lastException;
     217    }
    202218}
Note: See TracChangeset for help on using the changeset viewer.