- Timestamp:
- 2017-09-16T01:15:48+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/preferences/CachedProperty.java
r12846 r12867 51 51 public final boolean put(T value) { 52 52 // Not used 53 throw new IllegalAccessError("You cannot use put(T). Use put(String) instead.");53 throw new UnsupportedOperationException("You cannot use put(T). Use put(String) instead."); 54 54 } 55 55 -
trunk/src/org/openstreetmap/josm/plugins/PluginClassLoader.java
r12336 r12867 5 5 import java.net.URLClassLoader; 6 6 import java.util.ArrayList; 7 import java.util.Arrays; 7 8 import java.util.Collection; 9 import java.util.Objects; 8 10 9 11 import org.openstreetmap.josm.tools.Logging; … … 13 15 * <p> 14 16 * In addition to the classes in the plugin jar file, it loads classes of required 15 * plugins. The JOSM core classes should be provided by the theparent class loader.17 * plugins. The JOSM core classes should be provided by the parent class loader. 16 18 * @since 12322 17 19 */ 18 20 public class PluginClassLoader extends URLClassLoader { 19 21 20 Collection<PluginClassLoader> dependencies;22 private final Collection<PluginClassLoader> dependencies; 21 23 22 24 static { … … 39 41 * This plugin will have access to the classes of the dependent plugin 40 42 * @param dependency the class loader of the required plugin 43 * @return {@code true} if the collection of dependencies changed as a result of the call 44 * @since 12867 41 45 */ 42 public void addDependency(PluginClassLoader dependency) { 43 dependencies.add(dependency); 46 public boolean addDependency(PluginClassLoader dependency) { 47 // Add dependency only if not already present (directly or transitively through another one) 48 boolean result = !dependencies.contains(Objects.requireNonNull(dependency, "dependency")) 49 && !dependencies.stream().anyMatch(pcl -> pcl.dependencies.contains(dependency)) 50 && dependencies.add(dependency); 51 if (result) { 52 // Now, remove top-level single dependencies, which would be children of the added one 53 dependencies.removeIf(pcl -> pcl.dependencies.isEmpty() && dependency.dependencies.contains(pcl)); 54 } 55 return result; 44 56 } 45 57 46 58 @Override 47 59 protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { 48 for (PluginClassLoader dep : dependencies) { 49 try { 50 Class<?> result = dep.loadClass(name, resolve); 51 if (result != null) { 52 return result; 60 Class<?> result = findLoadedClass(name); 61 if (result == null) { 62 for (PluginClassLoader dep : dependencies) { 63 try { 64 result = dep.loadClass(name, resolve); 65 if (result != null) { 66 return result; 67 } 68 } catch (ClassNotFoundException e) { 69 // do nothing 70 Logging.trace("Plugin class not found in {0}: {1}", dep, e.getMessage()); 53 71 } 54 } catch (ClassNotFoundException e) {55 // do nothing56 Logging.trace("Plugin class not found in {0}: {1}", dep, e.getMessage());57 72 } 73 result = super.loadClass(name, resolve); 58 74 } 59 Class<?> result = super.loadClass(name, resolve);60 75 if (result != null) { 61 76 return result; … … 63 78 throw new ClassNotFoundException(name); 64 79 } 80 81 @Override 82 public String toString() { 83 return "PluginClassLoader [urls=" + Arrays.toString(getURLs()) + 84 (dependencies.isEmpty() ? "" : ", dependencies=" + dependencies) + ']'; 85 } 65 86 }
Note:
See TracChangeset
for help on using the changeset viewer.