]> source.dussan.org Git - aspectj.git/commitdiff
add test for proxy weaving and jit class weaving, update ltw doc
authoravasseur <avasseur>
Thu, 11 Aug 2005 09:22:07 +0000 (09:22 +0000)
committeravasseur <avasseur>
Thu, 11 Aug 2005 09:22:07 +0000 (09:22 +0000)
bridge/src/org/aspectj/bridge/MessageWriter.java
bridge/src/org/aspectj/bridge/Version.java
docs/adk15ProgGuideDB/ltw.xml
lib/asm/asm-2.0.jar [new file with mode: 0644]
tests/java5/ataspectj/ajc-ant.xml
tests/java5/ataspectj/ataspectj/UnweavableTest.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjLTWTests.java
tests/src/org/aspectj/systemtest/ajc150/ataspectj/ltw.xml
weaver/src/org/aspectj/weaver/bcel/AtAjAttributes.java
weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java

index bc9530314a5ebddc626786a4b9916c2bb7595a31..b019403253b4693923e3229861519347a9d86db2 100644 (file)
@@ -42,7 +42,7 @@ public class MessageWriter implements IMessageHandler {
             if (null != result) {
                 writer.println(result);
                 writer.flush();
-                if (abortOnFailure 
+                if (abortOnFailure
                     && (message.isFailed() || message.isAbort())) {
                     throw new AbortException(message);
                 }
index b24fb79837d8c641eff3f439232dea9e739a7836..b729ef55b05e8239fa040696d50952ebbdaeace2 100644 (file)
@@ -37,7 +37,7 @@ public class Version {
       * Time text set by build script using SIMPLE_DATE_FORMAT.
       * (if DEVELOPMENT version, invalid)
       */
-    public static final String time_text = "";
+    public static final String time_text = "mardi juil. 5, 2005 at 09:56:18 GMT";
 
     /** 
       * time in seconds-since-... format, used by programmatic clients.
@@ -46,20 +46,18 @@ public class Version {
     public static final long time;
     
        /** format used by build script to set time_text */
-    public static final String SIMPLE_DATE_FORMAT = "MM/dd/yy 'at' hh:mm:ss z";
+    public static final String SIMPLE_DATE_FORMAT = "EEEE MMM d, yyyy 'at' HH:mm:ss z";
     
     // if not DEVELOPMENT version, read time text using format used to set time 
     static {
         long foundTime = NOTIME;
-        if (!DEVELOPMENT.equals(text)) {
-               try {
-                   SimpleDateFormat format = new SimpleDateFormat(SIMPLE_DATE_FORMAT);
-                   ParsePosition pos = new ParsePosition(0);
-                   Date date = format.parse(time_text, pos);
-                   foundTime = date.getTime();
-               } catch (Throwable t) {            
-               }
-        }
+           try {
+               SimpleDateFormat format = new SimpleDateFormat(SIMPLE_DATE_FORMAT);
+               ParsePosition pos = new ParsePosition(0);
+               Date date = format.parse(time_text, pos);
+               foundTime = date.getTime();
+           } catch (Throwable t) {            
+           }
         time = foundTime;
     }
 
index 6366d1371d75cd574b9ff15b7573a8251599f008..ae36255acdd069ffccb289264153987485fb93fc 100644 (file)
             </informaltable>
         </sect2>
     </sect1>
+
+    <sect1 id="ltw-specialcases">
+        <title>Special cases</title>
+        <para>
+            Those classes are not exposed to the LTW infrastructure, no matter
+            the configuration of the <literal>aop.xml</literal> file(s):
+            <itemizedlist>
+                <listitem>All <literal>org.aspectj.*</literal> classes (and subpackages) - as those are needed by the infrastructure itself</listitem>
+                <listitem>All <literal>java.*</literal> and <literal>javax.*</literal> classes (and subpackages)</listitem>
+                <listitem>All <literal>sun.reflect.*</literal> classes - as those are JDK specific classes used when reflective calls occurs</listitem>
+            </itemizedlist>
+        </para>
+        <para>
+            Despite those special cases, it is perfectly possible to have call pointcut on those classes members providing the callee
+            class is not itself a speciall case, as well as execution pointcut on subclasses of those providing subclasses are not themselves
+            a special case.
+        </para>
+        <para>
+            It is also worth understanding that dynamic proxy representations are exposed to the LTW infrastructure and are not considered
+            a special case.
+        </para>
+    </sect1>
     
     <sect1 id="ltw-packaging">
         <title>Runtime Requirements for Load-time Weaving</title>
diff --git a/lib/asm/asm-2.0.jar b/lib/asm/asm-2.0.jar
new file mode 100644 (file)
index 0000000..458fd70
Binary files /dev/null and b/lib/asm/asm-2.0.jar differ
index 8381b61359aa13bab74cf9ab9bc7d4f46be8d040..393b92f306b39851a8ccd7fbf78eb7811680a729 100644 (file)
@@ -7,10 +7,11 @@
         value="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"/>
 
     <target name="compile:javac">
-        <!-- compile only javac compilable stuff -->
+        <!-- compile only javac compilable stuff, exclude the one that needs other dependencies -->
         <javac destdir="${aj.sandbox}" classpathref="aj.path"
             srcdir="${basedir}"
             includes="ataspectj/*"
+            excludes="ataspectj/UnweavableTest.java"
             debug="true">
         </javac>
     </target>
             <jvmarg value="-Daj5.def=ataspectj/ltwlog/aop-verboseandshow.xml"/>
         </java>
     </target>
+
+    <target name="ltw.Unweavable">
+        <javac destdir="${aj.sandbox}"
+            srcdir="${basedir}"
+            includes="ataspectj/UnweavableTest.java, ataspectj/TestHelper.java"
+            debug="true">
+            <classpath>
+                <path refid="aj.path"/>
+                <pathelement path="${aj.root}/lib/asm/asm-2.0.jar"/>
+            </classpath>
+        </javac>
+        <java fork="yes" classname="ataspectj.UnweavableTest" failonerror="yes">
+            <classpath>
+                <path refid="aj.path"/>
+                <pathelement path="${aj.root}/lib/asm/asm-2.0.jar"/>
+            </classpath>
+            <jvmarg value="-javaagent:${aj.root}/lib/test/loadtime5.jar"/>
+            <jvmarg value="-Daj5.def=ataspectj/aop-unweavabletest.xml"/>
+        </java>
+    </target>
 </project>
\ No newline at end of file
diff --git a/tests/java5/ataspectj/ataspectj/UnweavableTest.java b/tests/java5/ataspectj/ataspectj/UnweavableTest.java
new file mode 100644 (file)
index 0000000..4ce6897
--- /dev/null
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * Copyright (c) 2005 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Eclipse Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://eclipse.org/legal/epl-v10.html 
+ * 
+ * Contributors:
+ *   Alexandre Vasseur         initial implementation
+ *******************************************************************************/
+package ataspectj;
+
+import junit.framework.TestCase;
+
+import java.lang.reflect.Proxy;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.security.ProtectionDomain;
+
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.AnnotationVisitor;
+
+/**
+ * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a>
+ */
+public class UnweavableTest extends TestCase {
+
+    public void testUnweavableProxy() {
+        TestAspect.I = 0;
+        ISome some = getProxy();
+        some.giveOne();
+        assertEquals(1, TestAspect.I);
+    }
+
+    static interface ISome {
+        public int giveOne();
+    }
+
+    ISome getProxy() {
+        return (ISome) Proxy.newProxyInstance(
+                ISome.class.getClassLoader(),
+                new Class[]{ISome.class},
+                new InvocationHandler() {
+                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+                        return new Integer(1);
+                    }
+                }
+        );
+    }
+
+    @Aspect
+    public static class TestAspect {
+
+        static int I = 0;
+
+        @Before("execution(* ataspectj.UnweavableTest.ISome+.giveOne())")
+        public void before() {
+            I++;
+        }
+    }
+
+    public void testJit() {
+        TestAspect.I = 0;
+        TestAspect2.I = 0;
+        ISome some = getJit();
+        assertNotNull(some.getClass().getAnnotation(ASome.class));
+        assertEquals(2, some.giveOne());
+        assertEquals(1, TestAspect.I);
+        assertEquals(1, TestAspect2.I);
+    }
+
+    @Retention(RetentionPolicy.RUNTIME)
+    static @interface ASome {}
+
+    ISome getJit() {
+        ClassWriter cw = new ClassWriter(true, true);
+        cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "ataspectj/ISomeGen", null, "java/lang/Object", new String[]{"ataspectj/UnweavableTest$ISome"});
+        AnnotationVisitor av = cw.visitAnnotation("Lataspectj/UnweavableTest$ASome;", true);
+        av.visitEnd();
+
+        MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, new String[0]);
+        mv.visitVarInsn(Opcodes.ALOAD, 0);
+        mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
+        mv.visitInsn(Opcodes.RETURN);
+        mv.visitMaxs(0, 0);
+        mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "giveOne", "()I", null, new String[0]);
+        mv.visitInsn(Opcodes.ICONST_2);
+        mv.visitInsn(Opcodes.IRETURN);
+        mv.visitMaxs(0, 0);
+        cw.visitEnd();
+
+        try {
+            ClassLoader loader = this.getClass().getClassLoader();
+            Method def = ClassLoader.class.getDeclaredMethod("defineClass", new Class[]{String.class, byte[].class, int.class, int.class});
+            def.setAccessible(true);
+            Class gen = (Class) def.invoke(loader, "ataspectj.ISomeGen", cw.toByteArray(), 0, cw.toByteArray().length);
+            return (ISome) gen.newInstance();
+        } catch (Throwable t) {
+            fail(t.toString());
+            return null;
+        }
+    }
+
+    @Aspect
+    public static class TestAspect2 {
+        static int I = 0;
+        @Before("execution(* @ataspectj.UnweavableTest$ASome ataspectj..*.giveOne())")
+        public void before() {
+            I++;
+        }
+    }
+
+    public static void main(String args[]) throws Throwable {
+        TestHelper.runAndThrowOnFailure(suite());
+    }
+
+    public static junit.framework.Test suite() {
+        return new junit.framework.TestSuite(UnweavableTest.class);
+    }
+
+}
index e414c63b4bb043fe0fd30029f34c391c1f10807b..a9f9afda49cdbb3c8cf3a38ec812c194d17c42ee 100644 (file)
@@ -36,8 +36,7 @@ public class AtAjLTWTests extends XMLBasedAjcTestCase {
        public void testAjcLTWPerClauseTest_XnoWeave() {
                runTest("AjcLTW PerClauseTest -XnoWeave");
        }
-//FIXME AV - fails with ?? ataspectj\PerClauseTestAspects.java::0 the parameter jp is not bound in [all branches of] pointcut
-//
+
        public void testAjcLTWPerClauseTest_Xreweavable() {
                runTest("AjcLTW PerClauseTest -Xreweavable");
        }
@@ -78,4 +77,9 @@ public class AtAjLTWTests extends XMLBasedAjcTestCase {
         runTest("LTW Log");
     }
 
+    public void testLTWUnweavable() {
+        // actually test that we do LTW proxy and jit classes
+        runTest("LTW Unweavable");
+    }
+
 }
index af74f5b81c2113ffa41064dc39b4c7fc5f2a361e..fda448c229b2453731fbf1e77b7fd84773b0a5a9 100644 (file)
@@ -98,5 +98,8 @@
         <ant file="ajc-ant.xml" target="ltwlog.LTWLog" verbose="true"/>
     </ajc-test>
 
+    <ajc-test dir="java5/ataspectj" title="LTW Unweavable">
+        <ant file="ajc-ant.xml" target="ltw.Unweavable" verbose="true"/>
+    </ajc-test>
 
 </suite>
\ No newline at end of file
index 004a45f0b097ff56dc2b7f34805c30fd716ef8cb..249e9d3fc8c9fcaa805c71bbae84f6efdb5ce87b 100644 (file)
@@ -49,6 +49,7 @@ import org.aspectj.weaver.patterns.PerTypeWithin;
 import org.aspectj.weaver.patterns.Pointcut;
 import org.aspectj.weaver.patterns.SimpleScope;
 import org.aspectj.weaver.patterns.TypePattern;
+import org.aspectj.lang.JoinPoint;
 
 /**
  * Annotation defined aspect reader.
index 4430667c28d45a7ba8962c15f5a10877addc4bec..9f098de0ac732966219407d56916ac73fd7b9ac2 100644 (file)
@@ -197,7 +197,7 @@ public class WeavingAdaptor {
                 ||*/ name.startsWith("org.aspectj.")
                 || name.startsWith("java.")
                 || name.startsWith("javax."))
-                || name.startsWith("$Proxy")//JDK proxies
+                //|| name.startsWith("$Proxy")//JDK proxies//FIXME AV is that 1.3 proxy ? fe. ataspect.$Proxy0 is a java5 proxy...
                 || name.startsWith("sun.reflect."));//JDK reflect
        }