Changeset 7655 in josm
- Timestamp:
- 2014-10-27T15:46:39+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r7536 r7655 1385 1385 */ 1386 1386 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=>")); 1388 1388 } 1389 1389 -
trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java
r7588 r7655 241 241 author = attr.getValue("Author"); 242 242 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 } 246 251 } 247 252 if (oldcheck && mainversion > Version.getInstance().getVersion()) { -
trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java
r7654 r7655 31 31 * <li>.jar.new files, assuming that these are downloaded but not yet installed plugins</li> 32 32 * <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> 34 34 * </ul> 35 35 * … … 99 99 Main.warn(tr("Failed to scan file ''{0}'' for plugin information. Skipping.", fname)); 100 100 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 }126 101 } 127 102 monitor.worked(1); … … 166 141 monitor.beginTask(""); 167 142 scanSiteCacheFiles(monitor, pluginsDirectory); 168 scanIconCacheFiles(monitor, pluginsDirectory);169 143 scanPluginFiles(monitor, pluginsDirectory); 170 144 } finally { -
trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
r7654 r7655 58 58 private boolean displayErrMsg; 59 59 60 protected enum CacheType {PLUGIN_LIST, ICON_LIST}61 62 60 protected final void init(Collection<String> sites, boolean displayErrMsg) { 63 61 this.sites = sites; … … 111 109 * @return the file name for the cache file 112 110 */ 113 protected File createSiteCacheFile(File pluginDir, String site , CacheType type) {111 protected File createSiteCacheFile(File pluginDir, String site) { 114 112 String name; 115 113 try { … … 131 129 } 132 130 } 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"); 141 132 name = sb.toString(); 142 133 } catch(MalformedURLException e) { … … 257 248 258 249 /** 259 * Downloads the icon archive from a remote location260 *261 * @param site the site URL262 * @param monitor a progress monitor263 */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 /**318 250 * Writes the list of plugins to a cache file 319 251 * … … 326 258 Main.warn(tr("Failed to create plugin directory ''{0}''. Cannot cache plugin list from plugin site ''{1}''.", pluginDir.toString(), site)); 327 259 } 328 File cacheFile = createSiteCacheFile(pluginDir, site , CacheType.PLUGIN_LIST);260 File cacheFile = createSiteCacheFile(pluginDir, site); 329 261 getProgressMonitor().subTask(tr("Writing plugin list to local cache ''{0}''", cacheFile.toString())); 330 262 try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(cacheFile), StandardCharsets.UTF_8))) { … … 405 337 String list = downloadPluginList(site, getProgressMonitor().createSubTaskMonitor(0, false)); 406 338 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)); 409 340 if (list != null) { 410 341 getProgressMonitor().worked(1); … … 417 348 if (canceled) return; 418 349 } 419 downloadPluginIcons(site+"-icons.zip", createSiteCacheFile(pluginDir, site, CacheType.ICON_LIST), getProgressMonitor().createSubTaskMonitor(0, false));420 350 } 421 351 // remove old stuff or whole update process is broken
Note:
See TracChangeset
for help on using the changeset viewer.