Changeset 15416 in josm
- Timestamp:
- 2019-10-05T00:50:17+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/CachedFile.java
r15329 r15416 24 24 import java.util.List; 25 25 import java.util.Map; 26 import java.util.Optional; 26 27 import java.util.concurrent.ConcurrentHashMap; 27 28 import java.util.concurrent.TimeUnit; … … 35 36 import org.openstreetmap.josm.tools.Pair; 36 37 import org.openstreetmap.josm.tools.PlatformManager; 38 import org.openstreetmap.josm.tools.ResourceProvider; 37 39 import org.openstreetmap.josm.tools.Utils; 38 40 … … 41 43 * 42 44 * Supports URLs, local files, and a custom scheme (<code>resource:</code>) to get 43 * resources from the current *.jar file. (Local caching is only done for URLs.) 45 * resources from the current JOSM *.jar file as well as plugins *.jar files. 46 * (Local caching is only done for URLs.) 44 47 * <p> 45 48 * The mirrored file is only downloaded if it has been more than 7 days since … … 225 228 if (file == null) { 226 229 if (name != null && name.startsWith("resource://")) { 227 String resourceName = name.substring("resource:/".length()); 228 InputStream is = Utils.getResourceAsStream(getClass(), resourceName); 229 if (is == null) { 230 throw new IOException(tr("Failed to open input stream for resource ''{0}''", name)); 231 } 232 return is; 230 return Optional.ofNullable(ResourceProvider.getResourceAsStream(name.substring("resource:/".length()))) 231 .orElseThrow(() -> new IOException(tr("Failed to open input stream for resource ''{0}''", name))); 233 232 } else { 234 233 throw new IOException("No file found for: "+name); -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r15381 r15416 73 73 import org.openstreetmap.josm.tools.ImageProvider; 74 74 import org.openstreetmap.josm.tools.Logging; 75 import org.openstreetmap.josm.tools.ResourceProvider; 75 76 import org.openstreetmap.josm.tools.SubclassFilteredCollection; 76 77 import org.openstreetmap.josm.tools.Utils; … … 886 887 887 888 extendJoinedPluginResourceCL(toLoad); 888 ImageProvider.addAdditionalClassLoaders(getResourceClassLoaders());889 ResourceProvider.addAdditionalClassLoaders(getResourceClassLoaders()); 889 890 monitor.setTicksCount(toLoad.size()); 890 891 for (PluginInformation info : toLoad) { -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r15408 r15416 35 35 import java.util.Base64; 36 36 import java.util.Collection; 37 import java.util.Collections;38 37 import java.util.EnumMap; 39 38 import java.util.HashMap; 40 import java.util.HashSet;41 39 import java.util.Hashtable; 42 40 import java.util.Iterator; … … 45 43 import java.util.Map; 46 44 import java.util.Objects; 47 import java.util.Set;48 45 import java.util.TreeSet; 49 46 import java.util.concurrent.CompletableFuture; … … 263 260 public static final String PROP_TRANSPARENCY_COLOR = "josm.transparency.color"; 264 261 265 /** set of class loaders to take images from */266 private static final Set<ClassLoader> classLoaders = Collections.synchronizedSet(new HashSet<>());267 static {268 try {269 classLoaders.add(ClassLoader.getSystemClassLoader());270 } catch (SecurityException e) {271 Logging.log(Logging.LEVEL_ERROR, "Unable to get system classloader", e);272 }273 try {274 classLoaders.add(ImageProvider.class.getClassLoader());275 } catch (SecurityException e) {276 Logging.log(Logging.LEVEL_ERROR, "Unable to get application classloader", e);277 }278 }279 280 262 /** directories in which images are searched */ 281 263 protected Collection<String> dirs; … … 617 599 * @return {@code true} if the set changed as a result of the call 618 600 * @since 12870 619 */ 601 * @deprecated Use ResourceProvider#addAdditionalClassLoader 602 */ 603 @Deprecated 620 604 public static boolean addAdditionalClassLoader(ClassLoader additionalClassLoader) { 621 return classLoaders.add(additionalClassLoader);605 return ResourceProvider.addAdditionalClassLoader(additionalClassLoader); 622 606 } 623 607 … … 627 611 * @return {@code true} if the set changed as a result of the call 628 612 * @since 12870 629 */ 613 * @deprecated Use ResourceProvider#addAdditionalClassLoaders 614 */ 615 @Deprecated 630 616 public static boolean addAdditionalClassLoaders(Collection<ClassLoader> additionalClassLoaders) { 631 return classLoaders.addAll(additionalClassLoaders);617 return ResourceProvider.addAdditionalClassLoaders(additionalClassLoaders); 632 618 } 633 619 … … 1212 1198 private static URL getImageUrl(String path, String name) { 1213 1199 if (path != null && path.startsWith("resource://")) { 1214 String p = path.substring("resource://".length()); 1215 synchronized (classLoaders) { 1216 for (ClassLoader source : classLoaders) { 1217 URL res; 1218 if ((res = source.getResource(p + name)) != null) 1219 return res; 1220 } 1221 } 1200 return ResourceProvider.getResource(path.substring("resource://".length()) + name); 1222 1201 } else { 1223 1202 File f = new File(path, name); -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r15007 r15416 1883 1883 /** 1884 1884 * Finds a resource with a given name, with robustness to known JDK bugs. 1885 * @param klass class on which {@link Class #getResourceAsStream} will be called1885 * @param klass class on which {@link ClassLoader#getResourceAsStream} will be called 1886 1886 * @param path name of the desired resource 1887 1887 * @return A {@link java.io.InputStream} object or {@code null} if no resource with this name is found … … 1889 1889 */ 1890 1890 public static InputStream getResourceAsStream(Class<?> klass, String path) { 1891 return getResourceAsStream(klass.getClassLoader(), path); 1892 } 1893 1894 /** 1895 * Finds a resource with a given name, with robustness to known JDK bugs. 1896 * @param cl classloader on which {@link ClassLoader#getResourceAsStream} will be called 1897 * @param path name of the desired resource 1898 * @return A {@link java.io.InputStream} object or {@code null} if no resource with this name is found 1899 * @since 15416 1900 */ 1901 public static InputStream getResourceAsStream(ClassLoader cl, String path) { 1891 1902 try { 1892 return klass.getResourceAsStream(path); 1903 if (path != null && path.startsWith("/")) { 1904 path = path.substring(1); // See Class#resolveName 1905 } 1906 return cl.getResourceAsStream(path); 1893 1907 } catch (InvalidPathException e) { 1894 1908 Logging.error("Cannot open {0}: {1}", path, e.getMessage()); 1895 1909 Logging.trace(e); 1896 1910 try { 1897 URL betterUrl = betterJarUrl( klass.getResource(path));1911 URL betterUrl = betterJarUrl(cl.getResource(path)); 1898 1912 if (betterUrl != null) { 1899 1913 return betterUrl.openStream();
Note:
See TracChangeset
for help on using the changeset viewer.