- Timestamp:
- 2017-09-16T22:08:55+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r12862 r12870 307 307 try { 308 308 sources.add(ClassLoader.getSystemClassLoader()); 309 sources.add( org.openstreetmap.josm.gui.MainApplication.class.getClassLoader());309 sources.add(PluginHandler.class.getClassLoader()); 310 310 } catch (SecurityException ex) { 311 311 Logging.debug(ex); … … 862 862 863 863 extendJoinedPluginResourceCL(toLoad); 864 ImageProvider.addAdditionalClassLoaders(getResourceClassLoaders()); 864 865 monitor.setTicksCount(toLoad.size()); 865 866 for (PluginInformation info : toLoad) { -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r12865 r12870 30 30 import java.net.URL; 31 31 import java.nio.charset.StandardCharsets; 32 import java.util.ArrayList;33 32 import java.util.Arrays; 34 33 import java.util.Base64; 35 34 import java.util.Collection; 36 35 import java.util.HashMap; 36 import java.util.HashSet; 37 37 import java.util.Hashtable; 38 38 import java.util.Iterator; … … 40 40 import java.util.List; 41 41 import java.util.Map; 42 import java.util.Set; 42 43 import java.util.TreeSet; 43 44 import java.util.concurrent.CompletableFuture; … … 71 72 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresets; 72 73 import org.openstreetmap.josm.io.CachedFile; 73 import org.openstreetmap.josm.plugins.PluginHandler;74 74 import org.openstreetmap.josm.spi.preferences.Config; 75 75 import org.w3c.dom.Element; … … 248 248 public static final String PROP_TRANSPARENCY_COLOR = "josm.transparency.color"; 249 249 250 /** set of class loaders to take images from */ 251 protected static final Set<ClassLoader> classLoaders = new HashSet<>(Arrays.asList( 252 ClassLoader.getSystemClassLoader(), ImageProvider.class.getClassLoader())); 253 250 254 /** directories in which images are searched */ 251 255 protected Collection<String> dirs; … … 272 276 /** <code>true</code> if warnings should be suppressed */ 273 277 protected boolean suppressWarnings; 274 /** list of class loaders to take images from */275 protected Collection<ClassLoader> additionalClassLoaders;276 278 /** ordered list of overlay images */ 277 279 protected List<ImageOverlay> overlayInfo; … … 334 336 this.optional = image.optional; 335 337 this.suppressWarnings = image.suppressWarnings; 336 this.additionalClassLoaders = image.additionalClassLoaders;337 338 this.overlayInfo = image.overlayInfo; 338 339 this.isDisabled = image.isDisabled; … … 578 579 579 580 /** 581 * Add an additional class loader to search image for. 582 * @param additionalClassLoader class loader to add to the internal set 583 * @return {@code true} if the set changed as a result of the call 584 * @since 12870 585 */ 586 public static boolean addAdditionalClassLoader(ClassLoader additionalClassLoader) { 587 return classLoaders.add(additionalClassLoader); 588 } 589 590 /** 580 591 * Add a collection of additional class loaders to search image for. 581 * @param additionalClassLoaders class loaders to add to the internal list582 * @return the current object, for convenience583 * /584 public ImageProvider setAdditionalClassLoaders(Collection<ClassLoader> additionalClassLoaders) {585 this.additionalClassLoaders = additionalClassLoaders;586 return this;592 * @param additionalClassLoaders class loaders to add to the internal set 593 * @return {@code true} if the set changed as a result of the call 594 * @since 12870 595 */ 596 public static boolean addAdditionalClassLoaders(Collection<ClassLoader> additionalClassLoaders) { 597 return classLoaders.addAll(additionalClassLoaders); 587 598 } 588 599 … … 658 669 */ 659 670 public ImageResource getResource() { 660 ImageResource ir = getIfAvailableImpl( additionalClassLoaders);671 ImageResource ir = getIfAvailableImpl(); 661 672 if (ir == null) { 662 673 if (!optional) { … … 803 814 * Internal implementation of the image request. 804 815 * 805 * @param additionalClassLoaders the list of class loaders to use806 816 * @return the requested image or null if the request failed 807 817 */ 808 private ImageResource getIfAvailableImpl( Collection<ClassLoader> additionalClassLoaders) {818 private ImageResource getIfAvailableImpl() { 809 819 synchronized (cache) { 810 820 // This method is called from different thread and modifying HashMap concurrently can result … … 902 912 // and don't bother to create a URL unless we're actually 903 913 // creating the image. 904 URL path = getImageUrl(fullName , dirs, additionalClassLoaders);914 URL path = getImageUrl(fullName); 905 915 if (path == null) { 906 916 continue; … … 1134 1144 } 1135 1145 1136 private static URL getImageUrl(String path, String name, Collection<ClassLoader> additionalClassLoaders) {1146 private URL getImageUrl(String path, String name) { 1137 1147 if (path != null && path.startsWith("resource://")) { 1138 1148 String p = path.substring("resource://".length()); 1139 Collection<ClassLoader> classLoaders = new ArrayList<>(PluginHandler.getResourceClassLoaders());1140 if (additionalClassLoaders != null) {1141 classLoaders.addAll(additionalClassLoaders);1142 }1143 1149 for (ClassLoader source : classLoaders) { 1144 1150 URL res; … … 1154 1160 } 1155 1161 1156 private static URL getImageUrl(String imageName, Collection<String> dirs, Collection<ClassLoader> additionalClassLoaders) {1162 private URL getImageUrl(String imageName) { 1157 1163 URL u; 1158 1164 … … 1161 1167 for (String name : dirs) { 1162 1168 try { 1163 u = getImageUrl(name, imageName , additionalClassLoaders);1169 u = getImageUrl(name, imageName); 1164 1170 if (u != null) 1165 1171 return u; … … 1176 1182 String dir = new File(Config.getDirs().getUserDataDirectory(false), "images").getAbsolutePath(); 1177 1183 try { 1178 u = getImageUrl(dir, imageName , additionalClassLoaders);1184 u = getImageUrl(dir, imageName); 1179 1185 if (u != null) 1180 1186 return u; … … 1187 1193 1188 1194 // Absolute path? 1189 u = getImageUrl(null, imageName , additionalClassLoaders);1195 u = getImageUrl(null, imageName); 1190 1196 if (u != null) 1191 1197 return u; 1192 1198 1193 1199 // Try plugins and josm classloader 1194 u = getImageUrl("resource://images/", imageName , additionalClassLoaders);1200 u = getImageUrl("resource://images/", imageName); 1195 1201 if (u != null) 1196 1202 return u; … … 1199 1205 if (Main.pref != null) { 1200 1206 for (String location : Main.pref.getAllPossiblePreferenceDirs()) { 1201 u = getImageUrl(location + "images", imageName , additionalClassLoaders);1207 u = getImageUrl(location + "images", imageName); 1202 1208 if (u != null) 1203 1209 return u; 1204 u = getImageUrl(location, imageName , additionalClassLoaders);1210 u = getImageUrl(location, imageName); 1205 1211 if (u != null) 1206 1212 return u;
Note:
See TracChangeset
for help on using the changeset viewer.