Changeset 9621 in josm


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

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

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java

    r9616 r9621  
    9898        Collection<PluginInformation> downloaded = task.getDownloadedPlugins();
    9999        Collection<PluginInformation> failed = task.getFailedPlugins();
     100        Exception exception = task.getLastException();
    100101        StringBuilder sb = new StringBuilder();
    101102        if (!downloaded.isEmpty()) {
     
    124125            }
    125126            sb.append("</ul>");
     127        }
     128        if (exception != null) {
     129            // Same i18n string in ExceptionUtil.explainBadRequest()
     130            sb.append(tr("<br>Error message(untranslated): {0}", exception.getMessage()));
    126131        }
    127132        return sb.toString();
  • 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}
  • trunk/test/unit/org/openstreetmap/josm/gui/preferences/plugin/PluginPreferenceTest.java

    r9611 r9621  
    5353                new PluginDownloadTask(NullProgressMonitor.INSTANCE, Arrays.asList(dummy), "")));
    5454        assertEquals("The following plugin has been downloaded <strong>successfully</strong>:<ul><li>dummy_plugin (31772)</li></ul>"+
    55                      "Downloading the following plugin has <strong>failed</strong>:<ul><li>dummy_plugin</li></ul>",
     55                     "Downloading the following plugin has <strong>failed</strong>:<ul><li>dummy_plugin</li></ul>"+
     56                     "<br>Error message(untranslated): test",
    5657                PluginPreference.buildDownloadSummary(
    5758                        new PluginDownloadTask(NullProgressMonitor.INSTANCE, Arrays.asList(dummy), "") {
     
    6465                    public Collection<PluginInformation> getDownloadedPlugins() {
    6566                        return Collections.singleton(dummy);
     67                    }
     68
     69                    @Override
     70                    public Exception getLastException() {
     71                        return new Exception("test");
    6672                    }
    6773                }));
Note: See TracChangeset for help on using the changeset viewer.