1 package alt.jiapi.jazzpect; 2 3 import org.apache.log4j.Category; 4 5 import org.aopalliance.intercept.MethodInterceptor; 6 7 import alt.jiapi.InstrumentationContext; 8 import alt.jiapi.InstrumentationDescriptor; 9 import alt.jiapi.JiapiException; 10 import alt.jiapi.interceptor.InvocationInterceptor; 11 import alt.jiapi.util.Bootstrapper; 12 import alt.jiapi.util.InstrumentingClassLoader; 13 14 import alt.jiapi.jazzpect.interceptor.MInterceptor; 15 16 21 public class Initializer { 22 private static Category log = Category.getInstance(Initializer.class); 23 24 private InstrumentationContext ctx; 25 private ClassLoader classLoader; 26 27 public Initializer(MethodInterceptor mi) throws JiapiException { 28 this(new String [] {"*"}, 29 new String [] {"java.*", "org.*", "javax.*"}, 30 "*", mi); 31 } 32 33 public Initializer(String inclusionRule, MethodInterceptor mi) throws JiapiException { 34 this(new String [] {inclusionRule}, null, "*", mi); 35 } 36 37 public Initializer(String [] inclusionRules, MethodInterceptor mi) throws JiapiException { 38 this(inclusionRules, null, "*", mi); 39 } 40 41 public Initializer(String [] inclusionRules, String [] exclusionRules, 42 String resolution, MethodInterceptor mi) throws JiapiException { 43 this.ctx = new InstrumentationContext(); 44 InstrumentationDescriptor id = new InstrumentationDescriptor(); 45 ctx.addInstrumentationDescriptor(id); 46 47 if (inclusionRules != null) { 48 for (int i = 0; i < inclusionRules.length; i++) { 49 if (inclusionRules[i] != null) { 50 id.addInclusionRule(inclusionRules[i]); 51 } 52 else { 53 log.warn("Skipping null inclusion rule"); 54 } 55 } 56 } 57 58 if (exclusionRules != null) { 59 for (int i = 0; i < exclusionRules.length; i++) { 60 if (exclusionRules[i] != null) { 61 id.addExclusionRule(exclusionRules[i]); 62 } 63 else { 64 log.warn("Skipping null exclusion rule"); 65 } 66 } 67 } 68 69 if (resolution == null) { 70 log.warn("Null resolution, no invocation is trapped"); 71 resolution = ""; } 73 74 InvocationInterceptor ii = 76 new InvocationInterceptor(id, resolution, new MInterceptor(mi)); 77 78 this.classLoader = InstrumentingClassLoader.createClassLoader(ctx); 79 } 80 81 82 85 public InstrumentationContext getContext() { 86 return ctx; 87 } 88 89 90 96 public ClassLoader getClassLoader() { 97 return classLoader; 98 } 99 100 101 105 public void runMainMethod(String className, String [] args) { 106 Bootstrapper.launch(className, args, getContext(), getClassLoader()); 107 } 108 } 109 | Popular Tags |