Changeset 7655 in josm for trunk/src/org


Ignore:
Timestamp:
2014-10-27T15:46:39+01:00 (9 years ago)
Author:
stoecker
Message:

support data: style URL's for icon in plugin list, see #10581, drop old style loading

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r7536 r7655  
    13851385     */
    13861386    public Collection<String> getPluginSites() {
    1387         return getCollection("pluginmanager.sites", Collections.singleton(Main.getJOSMWebsite()+"/plugin%<?plugins=>"));
     1387        return getCollection("pluginmanager.sites", Collections.singleton(Main.getJOSMWebsite()+"/pluginicons%<?plugins=>"));
    13881388    }
    13891389
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r7588 r7655  
    241241        author = attr.getValue("Author");
    242242        iconPath = attr.getValue("Plugin-Icon");
    243         if (iconPath != null && file != null) {
    244             // extract icon from the plugin jar file
    245             icon = new ImageProvider(iconPath).setArchive(file).setMaxWidth(24).setMaxHeight(24).setOptional(true).get();
     243        if (iconPath != null)
     244        {
     245            if (file != null) {
     246                // extract icon from the plugin jar file
     247                icon = new ImageProvider(iconPath).setArchive(file).setMaxWidth(24).setMaxHeight(24).setOptional(true).get();
     248            } else if (iconPath.startsWith("data:")) {
     249                icon = new ImageProvider(iconPath).setMaxWidth(24).setMaxHeight(24).setOptional(true).get();
     250            }
    246251        }
    247252        if (oldcheck && mainversion > Version.getInstance().getVersion()) {
  • trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java

    r7654 r7655  
    3131 *   <li>.jar.new files, assuming that these are downloaded but not yet installed plugins</li>
    3232 *   <li>cached lists of available plugins, downloaded for instance from
    33  *   <a href="https://josm.openstreetmap.de/plugin">https://josm.openstreetmap.de/plugin</a></li>
     33 *   <a href="https://josm.openstreetmap.de/pluginicons">https://josm.openstreetmap.de/pluginicons</a></li>
    3434 * </ul>
    3535 *
     
    9999                Main.warn(tr("Failed to scan file ''{0}'' for plugin information. Skipping.", fname));
    100100                Main.error(e);
    101             }
    102             monitor.worked(1);
    103         }
    104     }
    105     protected void scanIconCacheFiles(ProgressMonitor monitor, File pluginsDirectory) {
    106         File[] siteCacheFiles = listFiles(pluginsDirectory, "^([0-9]+-)?site.*plugin-icons\\.zip$");
    107         if (siteCacheFiles == null || siteCacheFiles.length == 0)
    108             return;
    109         monitor.subTask(tr("Processing plugin site cache icon files..."));
    110         monitor.setTicksCount(siteCacheFiles.length);
    111         for (File f: siteCacheFiles) {
    112             String fname = f.getName();
    113             monitor.setCustomText(tr("Processing file ''{0}''", fname));
    114             for (PluginInformation pi : availablePlugins.values()) {
    115                 if (pi.icon == null && pi.iconPath != null) {
    116                     String path = pi.iconPath;
    117                     if(!path.startsWith("data:")) {
    118                         path = pi.name+".jar/"+path;
    119                     }
    120                     pi.icon = new ImageProvider(path)
    121                                     .setArchive(f)
    122                                     .setMaxWidth(24)
    123                                     .setMaxHeight(24)
    124                                     .setOptional(true).get();
    125                 }
    126101            }
    127102            monitor.worked(1);
     
    166141            monitor.beginTask("");
    167142            scanSiteCacheFiles(monitor, pluginsDirectory);
    168             scanIconCacheFiles(monitor, pluginsDirectory);
    169143            scanPluginFiles(monitor, pluginsDirectory);
    170144        } finally {
  • trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java

    r7654 r7655  
    5858    private boolean displayErrMsg;
    5959
    60     protected enum CacheType {PLUGIN_LIST, ICON_LIST}
    61 
    6260    protected final void init(Collection<String> sites, boolean displayErrMsg) {
    6361        this.sites = sites;
     
    111109     * @return the file name for the cache file
    112110     */
    113     protected File createSiteCacheFile(File pluginDir, String site, CacheType type) {
     111    protected File createSiteCacheFile(File pluginDir, String site) {
    114112        String name;
    115113        try {
     
    131129                }
    132130            }
    133             switch (type) {
    134             case PLUGIN_LIST:
    135                 sb.append(".txt");
    136                 break;
    137             case ICON_LIST:
    138                 sb.append("-icons.zip");
    139                 break;
    140             }
     131            sb.append(".txt");
    141132            name = sb.toString();
    142133        } catch(MalformedURLException e) {
     
    257248
    258249    /**
    259      * Downloads the icon archive from a remote location
    260      *
    261      * @param site the site URL
    262      * @param monitor a progress monitor
    263      */
    264     protected void downloadPluginIcons(String site, File destFile, ProgressMonitor monitor) {
    265         try {
    266             site = site.replaceAll("%<(.*)>", "");
    267 
    268             monitor.beginTask("");
    269             monitor.indeterminateSubTask(tr("Downloading plugin list from ''{0}''", site));
    270 
    271             URL url = new URL(site);
    272             synchronized(this) {
    273                 connection = Utils.openHttpConnection(url);
    274                 connection.setRequestProperty("Cache-Control", "no-cache");
    275             }
    276             try (
    277                 InputStream in = connection.getInputStream();
    278                 OutputStream out = new FileOutputStream(destFile)
    279             ) {
    280                 byte[] buffer = new byte[8192];
    281                 for (int read = in.read(buffer); read != -1; read = in.read(buffer)) {
    282                     out.write(buffer, 0, read);
    283                 }
    284             }
    285         } catch (MalformedURLException e) {
    286             if (canceled) return;
    287             Main.error(e);
    288             return;
    289         } catch (IOException e) {
    290             if (canceled) return;
    291             handleIOException(monitor, e, tr("Plugin icons download error"), tr("JOSM failed to download plugin icons:"), displayErrMsg);
    292             return;
    293         } finally {
    294             synchronized(this) {
    295                 if (connection != null) {
    296                     connection.disconnect();
    297                 }
    298                 connection = null;
    299             }
    300             monitor.finishTask();
    301         }
    302         for (PluginInformation pi : availablePlugins) {
    303             if (pi.icon == null && pi.iconPath != null) {
    304                 String path = pi.iconPath;
    305                 if(!path.startsWith("data:")) {
    306                     path = pi.name+".jar/"+path;
    307                 }
    308                 pi.icon = new ImageProvider(path)
    309                                 .setArchive(destFile)
    310                                 .setMaxWidth(24)
    311                                 .setMaxHeight(24)
    312                                 .setOptional(true).get();
    313             }
    314         }
    315     }
    316 
    317     /**
    318250     * Writes the list of plugins to a cache file
    319251     *
     
    326258            Main.warn(tr("Failed to create plugin directory ''{0}''. Cannot cache plugin list from plugin site ''{1}''.", pluginDir.toString(), site));
    327259        }
    328         File cacheFile = createSiteCacheFile(pluginDir, site, CacheType.PLUGIN_LIST);
     260        File cacheFile = createSiteCacheFile(pluginDir, site);
    329261        getProgressMonitor().subTask(tr("Writing plugin list to local cache ''{0}''", cacheFile.toString()));
    330262        try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(cacheFile), StandardCharsets.UTF_8))) {
     
    405337            String list = downloadPluginList(site, getProgressMonitor().createSubTaskMonitor(0, false));
    406338            if (canceled) return;
    407             siteCacheFiles.remove(createSiteCacheFile(pluginDir, site, CacheType.PLUGIN_LIST));
    408             siteCacheFiles.remove(createSiteCacheFile(pluginDir, site, CacheType.ICON_LIST));
     339            siteCacheFiles.remove(createSiteCacheFile(pluginDir, site));
    409340            if (list != null) {
    410341                getProgressMonitor().worked(1);
     
    417348                if (canceled) return;
    418349            }
    419             downloadPluginIcons(site+"-icons.zip", createSiteCacheFile(pluginDir, site, CacheType.ICON_LIST), getProgressMonitor().createSubTaskMonitor(0, false));
    420350        }
    421351        // remove old stuff or whole update process is broken
Note: See TracChangeset for help on using the changeset viewer.