diff options
Diffstat (limited to 'loadtime')
4 files changed, 35 insertions, 4 deletions
diff --git a/loadtime/src/org/aspectj/weaver/loadtime/Aj.java b/loadtime/src/org/aspectj/weaver/loadtime/Aj.java index b0552a040..015a245b3 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/Aj.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/Aj.java @@ -14,6 +14,8 @@ package org.aspectj.weaver.loadtime; import java.util.Map; import java.util.WeakHashMap; +import org.aspectj.weaver.tools.Trace; +import org.aspectj.weaver.tools.TraceFactory; import org.aspectj.weaver.tools.WeavingAdaptor; /** @@ -26,13 +28,17 @@ public class Aj implements ClassPreProcessor { private IWeavingContext weavingContext; + private static Trace trace = TraceFactory.getTraceFactory().getTrace(Aj.class); + public Aj(){ this(null); } public Aj(IWeavingContext context){ - weavingContext = context; + if (trace.isTraceEnabled()) trace.enter("<init>",this,new Object[] {context}); + this.weavingContext = context; + if (trace.isTraceEnabled()) trace.exit("<init>"); } /** @@ -51,22 +57,28 @@ public class Aj implements ClassPreProcessor { * @return weaved bytes */ public byte[] preProcess(String className, byte[] bytes, ClassLoader loader) { + if (trace.isTraceEnabled()) trace.enter("preProcess",this,new Object[] {className,bytes,loader}); + //TODO AV needs to doc that if (loader == null || className == null) { // skip boot loader or null classes (hibernate) + if (trace.isTraceEnabled()) trace.exit("preProcess",bytes); return bytes; } try { WeavingAdaptor weavingAdaptor = WeaverContainer.getWeaver(loader, weavingContext); if (weavingAdaptor == null) { + if (trace.isTraceEnabled()) trace.exit("preProcess",bytes); return bytes; } return weavingAdaptor.weaveClass(className, bytes); } catch (Exception t) { + trace.error("preProcess",t); //FIXME AV wondering if we should have the option to fail (throw runtime exception) here // would make sense at least in test f.e. see TestHelper.handleMessage() t.printStackTrace(); + if (trace.isTraceEnabled()) trace.exit("preProcess",bytes); return bytes; } } diff --git a/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java b/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java index 2f02ca67d..7f6502361 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java @@ -46,6 +46,8 @@ import org.aspectj.weaver.ltw.LTWWorld; import org.aspectj.weaver.patterns.PatternParser; import org.aspectj.weaver.patterns.TypePattern; import org.aspectj.weaver.tools.GeneratedClassHandler; +import org.aspectj.weaver.tools.Trace; +import org.aspectj.weaver.tools.TraceFactory; import org.aspectj.weaver.tools.WeavingAdaptor; /** @@ -72,10 +74,14 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { private ClassLoader classLoader; private IWeavingContext weavingContext; + private static Trace trace = TraceFactory.getTraceFactory().getTrace(ClassLoaderWeavingAdaptor.class); + public ClassLoaderWeavingAdaptor(final ClassLoader loader, IWeavingContext wContext) { super(); + if (trace.isTraceEnabled()) trace.enter("<init>",this); this.classLoader = loader; this.weavingContext = wContext; + if (trace.isTraceEnabled()) trace.exit("<init>"); } protected void initialize (final ClassLoader deprecatedLoader, IWeavingContext deprecatedContext) { @@ -334,6 +340,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { * @param definitions */ private void registerAspects(final BcelWeaver weaver, final ClassLoader loader, final List definitions) { + if (trace.isTraceEnabled()) trace.enter("registerAspects",this, new Object[] { weaver, loader, definitions} ); //TODO: the exclude aspect allow to exclude aspect defined upper in the CL hierarchy - is it what we want ?? // if not, review the getResource so that we track which resource is defined by which CL @@ -396,6 +403,8 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { enabled = false; info("no aspects registered. Disabling weaver for class loader " + getClassLoaderName(loader)); } + + if (trace.isTraceEnabled()) trace.exit("registerAspects",enabled); } /** @@ -647,6 +656,8 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { } private void defineClass(ClassLoader loader, String name, byte[] bytes) { + if (trace.isTraceEnabled()) trace.enter("defineClass",this,new Object[] {loader,name,bytes}); + Object clazz = null; info("generating class '" + name + "'"); try { @@ -655,7 +666,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { "defineClass", new Class[] { String.class, bytes.getClass(), int.class, int.class }); defineClass.setAccessible(true); - defineClass.invoke(loader, new Object[] { name, bytes, + clazz = defineClass.invoke(loader, new Object[] { name, bytes, new Integer(0), new Integer(bytes.length) }); } catch (InvocationTargetException e) { if (e.getTargetException() instanceof LinkageError) { @@ -668,5 +679,7 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor { } catch (Exception e) { warn("define generated class failed",e); } + + if (trace.isTraceEnabled()) trace.exit("defineClass",clazz); } } diff --git a/loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java b/loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java index e3d7264e8..2ec089253 100644 --- a/loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java +++ b/loadtime/src/org/aspectj/weaver/loadtime/DefaultWeavingContext.java @@ -68,7 +68,7 @@ public class DefaultWeavingContext implements IWeavingContext { */ public String getId () { if (shortName == null) { - shortName = getClassLoaderName(); + shortName = getClassLoaderName().replace('$','.'); int index = shortName.lastIndexOf("."); shortName = shortName.substring(index + 1); } diff --git a/loadtime/testsrc/LoadtimeModuleTests.java b/loadtime/testsrc/LoadtimeModuleTests.java index fe0ef3338..342b16f24 100644 --- a/loadtime/testsrc/LoadtimeModuleTests.java +++ b/loadtime/testsrc/LoadtimeModuleTests.java @@ -15,7 +15,10 @@ import junit.framework.Test; import junit.framework.TestSuite; import junit.textui.TestRunner; +import org.aspectj.weaver.loadtime.AjTest; +import org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptorTest; import org.aspectj.weaver.loadtime.JRockitAgentTest; +import org.aspectj.weaver.loadtime.WeavingContextTest; import org.aspectj.weaver.loadtime.WeavingURLClassLoaderTest; import org.aspectj.weaver.loadtime.test.DocumentParserTest; @@ -28,8 +31,11 @@ public class LoadtimeModuleTests extends TestCase { TestSuite suite = new TestSuite(LoadtimeModuleTests.class.getName()); suite.addTestSuite(DocumentParserTest.class); - suite.addTestSuite(WeavingURLClassLoaderTest.class); + suite.addTestSuite(AjTest.class); + suite.addTestSuite(ClassLoaderWeavingAdaptorTest.class); suite.addTestSuite(JRockitAgentTest.class); + suite.addTestSuite(WeavingContextTest.class); + suite.addTestSuite(WeavingURLClassLoaderTest.class); return suite; } |