Ignore:
Timestamp:
2014-08-20T03:07:15+02:00 (7 years ago)
Author:
Don-vip
Message:

fix #8885 (see #4614) - add offline mode with new command line argument --offline which can take one of several of these values (comma separated):

  • josm_website: to disable all accesses to JOSM website (when not cached, disables Getting Started page, help, plugin list, styles, imagery, presets, rules)
  • osm_api: to disable all accesses to OSM API (disables download, upload, changeset queries, history, user message notification)
  • all: alias to disable all values. Currently equivalent to "josm_website,osm_api"

Plus improved javadoc, fixed EDT violations, and fixed a bug with HTTP redirection sent without "Location" header

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

Legend:

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

    r7424 r7434  
    6363import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
    6464import org.openstreetmap.josm.gui.widgets.JosmTextArea;
     65import org.openstreetmap.josm.io.OfflineAccessException;
     66import org.openstreetmap.josm.io.OnlineResource;
    6567import org.openstreetmap.josm.tools.GBC;
    6668import org.openstreetmap.josm.tools.I18n;
     
    303305     */
    304306    public static boolean checkAndConfirmPluginUpdate(Component parent) {
     307        if (!checkOfflineAccess()) {
     308            Main.info(tr("{0} not available (offline mode)", tr("Plugin update")));
     309            return false;
     310        }
    305311        String message = null;
    306312        String togglePreferenceKey = null;
     
    403409        }
    404410        return ret == 0;
     411    }
     412
     413    private static boolean checkOfflineAccess() {
     414        if (Main.isOffline(OnlineResource.ALL)) {
     415            return false;
     416        }
     417        if (Main.isOffline(OnlineResource.JOSM_WEBSITE)) {
     418            for (String updateSite : Main.pref.getPluginSites()) {
     419                try {
     420                    OnlineResource.JOSM_WEBSITE.checkOfflineAccess(updateSite, Main.getJOSMWebsite());
     421                } catch (OfflineAccessException e) {
     422                    if (Main.isTraceEnabled()) {
     423                        Main.trace(e.getMessage());
     424                    }
     425                    return false;
     426                }
     427            }
     428        }
     429        return true;
    405430    }
    406431
  • trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java

    r7082 r7434  
    6060    protected enum CacheType {PLUGIN_LIST, ICON_LIST}
    6161
    62     protected final void init(Collection<String> sites, boolean displayErrMsg){
     62    protected final void init(Collection<String> sites, boolean displayErrMsg) {
    6363        this.sites = sites;
    6464        if (sites == null) {
     
    6868        this.displayErrMsg = displayErrMsg;
    6969    }
    70     /**
    71      * Creates the task
     70
     71    /**
     72     * Constructs a new {@code ReadRemotePluginInformationTask}.
    7273     *
    7374     * @param sites the collection of download sites. Defaults to the empty collection if null.
     
    7980
    8081    /**
    81      * Creates the task
     82     * Constructs a new {@code ReadRemotePluginInformationTask}.
    8283     *
    8384     * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null
     
    104105
    105106    /**
    106      * Creates the file name for the cached plugin list and the icon cache
    107      * file.
     107     * Creates the file name for the cached plugin list and the icon cache file.
    108108     *
    109109     * @param site the name of the site
     
    403403            siteCacheFiles.remove(createSiteCacheFile(pluginDir, site, CacheType.PLUGIN_LIST));
    404404            siteCacheFiles.remove(createSiteCacheFile(pluginDir, site, CacheType.ICON_LIST));
    405             if(list != null)
    406             {
     405            if (list != null) {
    407406                getProgressMonitor().worked(1);
    408407                cachePluginList(site, list);
     
    416415            downloadPluginIcons(site+"-icons.zip", createSiteCacheFile(pluginDir, site, CacheType.ICON_LIST), getProgressMonitor().createSubTaskMonitor(0, false));
    417416        }
    418         for (File file: siteCacheFiles) /* remove old stuff or whole update process is broken */
    419         {
     417        // remove old stuff or whole update process is broken
     418        for (File file: siteCacheFiles) {
    420419            file.delete();
    421420        }
Note: See TracChangeset for help on using the changeset viewer.