1 package org.kohsuke.stapler; 2 3 import java.util.Map ; 4 import java.util.WeakHashMap ; 5 import java.io.File ; 6 import java.net.URLClassLoader ; 7 import java.net.URL ; 8 import java.net.MalformedURLException ; 9 10 16 public class MetaClassLoader extends TearOffSupport { 17 public final MetaClassLoader parent; 18 public final ClassLoader loader; 19 20 public MetaClassLoader(ClassLoader loader) { 21 this.loader = loader; 22 this.parent = get(loader.getParent()); 23 } 24 25 public static MetaClassLoader get(ClassLoader cl) { 26 if(cl ==null) 27 return null; 29 synchronized(classMap) { 30 MetaClassLoader mc = classMap.get(cl); 31 if(mc==null) { 32 mc = new MetaClassLoader(cl); 33 classMap.put(cl,mc); 34 } 35 return mc; 36 } 37 } 38 39 42 public static MetaClassLoader debugLoader = null; 43 44 49 private static final Map <ClassLoader ,MetaClassLoader> classMap = new WeakHashMap <ClassLoader ,MetaClassLoader>(); 50 51 static { 52 try { 53 String path = System.getProperty("stapler.resourcePath"); 54 if(path!=null) { 55 debugLoader = new MetaClassLoader( 56 new URLClassLoader (new URL []{new File (path).toURL()})); 57 } 58 } catch (MalformedURLException e) { 59 throw new Error (e); 60 } 61 } 62 } 63 | Popular Tags |