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

Location:
trunk/src/org/openstreetmap/josm/plugins
Files:
2 edited

Legend:

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

    r3083 r9621  
    22package org.openstreetmap.josm.plugins;
    33
     4/**
     5 * Exception thrown during plugin download.
     6 * @since 2817
     7 */
    48public class PluginDownloadException extends Exception {
    59
    6     public PluginDownloadException() {
    7         super();
     10    /**
     11     * Constructs a new {@code PluginDownloadException} with the specified detail message and cause.
     12     * @param message message the detail message (which is saved for later retrieval by the {@link #getMessage()} method).
     13     * @param cause cause the cause (which is saved for later retrieval by the {@link #getCause()} method).
     14     */
     15    public PluginDownloadException(String message, Throwable cause) {
     16        super(message, cause);
    817    }
    918
    10     public PluginDownloadException(String arg0, Throwable arg1) {
    11         super(arg0, arg1);
     19    /**
     20     * Constructs a new {@code PluginDownloadException} with the specified detail message.
     21     * The cause is not initialized, and may subsequently be initialized by a call to {@link #initCause}.
     22     * @param message message the detail message (which is saved for later retrieval by the {@link #getMessage()} method).
     23     */
     24    public PluginDownloadException(String message) {
     25        super(message);
    1226    }
    1327
    14     public PluginDownloadException(String arg0) {
    15         super(arg0);
    16     }
    17 
    18     public PluginDownloadException(Throwable arg0) {
    19         super(arg0);
     28    /**
     29     * Constructs a new {@code PluginDownloadException} with the specified cause and a detail message of
     30     * <tt>(cause==null ? null : cause.toString())</tt> (which typically contains the class and detail message of <tt>cause</tt>).
     31     * @param cause cause the cause (which is saved for later retrieval by the {@link #getCause()} method).
     32     */
     33    public PluginDownloadException(Throwable cause) {
     34        super(cause);
    2035    }
    2136}
  • 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.