]> source.dussan.org Git - aspectj.git/commitdiff
Bug 132080 "LTW concrete-aspect definitions not exposed to weaver"
authormwebster <mwebster>
Wed, 4 Oct 2006 13:35:09 +0000 (13:35 +0000)
committermwebster <mwebster>
Wed, 4 Oct 2006 13:35:09 +0000 (13:35 +0000)
18 files changed:
loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java
loadtime/src/org/aspectj/weaver/loadtime/ConcreteAspectCodeGen.java
tests/bugs153/pr132080/AbstractSuperAspect.aj [new file with mode: 0644]
tests/bugs153/pr132080/AbstractSuperAspectWithAround.aj [new file with mode: 0644]
tests/bugs153/pr132080/AbstractSuperAspectWithInterface.aj [new file with mode: 0644]
tests/bugs153/pr132080/ConcreteAspectWithITD.aj [new file with mode: 0644]
tests/bugs153/pr132080/HelloWorld.java [new file with mode: 0644]
tests/bugs153/pr132080/TestAdvice.aj [new file with mode: 0644]
tests/bugs153/pr132080/TestAroundClosure.aj [new file with mode: 0644]
tests/bugs153/pr132080/TestITD.aj [new file with mode: 0644]
tests/bugs153/pr132080/TestInterface.java [new file with mode: 0644]
tests/bugs153/pr132080/aop-advice.xml [new file with mode: 0644]
tests/bugs153/pr132080/aop-aroundclosure.xml [new file with mode: 0644]
tests/bugs153/pr132080/aop-itd.xml [new file with mode: 0644]
tests/bugs153/pr149096/aop-pr149096.xml
tests/src/org/aspectj/systemtest/ajc153/Ajc153Tests.java
tests/src/org/aspectj/systemtest/ajc153/ajc153.xml
weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java

index e9d46182f22c4668b371b61be87f802201ec7df9..6d814ef95ac8c34c57e912850cf3fe50b193680a 100644 (file)
@@ -40,6 +40,8 @@ import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.World;
 import org.aspectj.weaver.Lint.Kind;
 import org.aspectj.weaver.bcel.BcelWeaver;
+import org.aspectj.weaver.bcel.BcelWorld;
+import org.aspectj.weaver.bcel.Utility;
 import org.aspectj.weaver.loadtime.definition.Definition;
 import org.aspectj.weaver.loadtime.definition.DocumentParser;
 import org.aspectj.weaver.ltw.LTWWorld;
@@ -73,6 +75,8 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
     private StringBuffer namespace;
     private IWeavingContext weavingContext;
 
+    private List concreteAspects = new ArrayList();
+
        private static Trace trace = TraceFactory.getTraceFactory().getTrace(ClassLoaderWeavingAdaptor.class);
     
     public ClassLoaderWeavingAdaptor() {
@@ -156,6 +160,8 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
             
             // after adding aspects
             weaver.prepareForWeave();
+            boolean success = weaveAndDefineConceteAspects();
+            if (!success) disable();
         }
         else {
                bcelWorld = null;
@@ -410,11 +416,12 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
                         success = false;
                         break;
                     }
-                    this.generatedClassHandler.acceptClass(
-                            concreteAspect.name,
-                            gen.getBytes()
-                    );
-                    /*ResolvedType aspect = */weaver.addLibraryAspect(concreteAspect.name);
+                    
+                       ((BcelWorld)weaver.getWorld()).addSourceObjectType(Utility.makeJavaClass(concreteAspect.name, gen.getBytes()));
+
+                       concreteAspects.add(gen);
+                       
+                    weaver.addLibraryAspect(concreteAspect.name);
 
                     //generate key for SC
                     if(namespace==null){
@@ -425,7 +432,6 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
                 }
             }
         }
-//        System.out.println("ClassLoaderWeavingAdaptor.registerAspects() classloader=" + weavingContext.getClassLoaderName() + ", namespace=" + namespace);
         
         /* We couldn't register one or more aspects so disable the adaptor */
         if (!success) {
@@ -442,6 +448,29 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
         if (trace.isTraceEnabled()) trace.exit("registerAspects",isEnabled());
     }
 
+    private boolean weaveAndDefineConceteAspects () {
+       if (trace.isTraceEnabled()) trace.enter("weaveAndDefineConceteAspects",this,concreteAspects);
+       boolean success = true;
+
+       for (Iterator iterator = concreteAspects.iterator(); iterator.hasNext();) {
+               ConcreteAspectCodeGen gen = (ConcreteAspectCodeGen)iterator.next();
+               String name = gen.getClassName();
+               byte[] bytes = gen.getBytes();
+
+               try {
+                       byte[] newBytes = weaveClass(name, bytes);
+                this.generatedClassHandler.acceptClass(name,newBytes);
+               }
+               catch (IOException ex) {
+                       trace.error("weaveAndDefineConceteAspects",ex);
+                               error("exception weaving aspect '" + name + "'",ex);
+               }
+        }
+        
+        if (trace.isTraceEnabled()) trace.exit("weaveAndDefineConceteAspects",success);
+        return success;
+    }
+    
     /**
      * Register the include / exclude filters
      * We duplicate simple patterns in startWith filters that will allow faster matching without ResolvedType
index c3e9614b32d65df0671047b7cb80070de083da47..2b3a3638111d7192645dff377f866d91dbd3bd9f 100644 (file)
@@ -265,6 +265,10 @@ public class ConcreteAspectCodeGen {
          return false;
     }
 
+    public String getClassName () {
+       return m_concreteAspect.name;
+    }
+    
     /**
      * Build the bytecode for the concrete aspect
      *
diff --git a/tests/bugs153/pr132080/AbstractSuperAspect.aj b/tests/bugs153/pr132080/AbstractSuperAspect.aj
new file mode 100644 (file)
index 0000000..9692579
--- /dev/null
@@ -0,0 +1,20 @@
+/*******************************************************************************
+ * 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:
+ *   Matthew Webster         initial implementation
+ *******************************************************************************/
+
+public abstract aspect AbstractSuperAspect {
+       
+               protected abstract pointcut scope ();
+       
+               before () : execution(public static void main(String[])) && scope() {
+                       System.out.println("? " + thisJoinPoint.getSignature());
+               }
+}
diff --git a/tests/bugs153/pr132080/AbstractSuperAspectWithAround.aj b/tests/bugs153/pr132080/AbstractSuperAspectWithAround.aj
new file mode 100644 (file)
index 0000000..15226f2
--- /dev/null
@@ -0,0 +1,9 @@
+public abstract aspect AbstractSuperAspectWithAround {
+       
+       protected abstract pointcut scope ();
+       
+       void around () : execution(public static void main(String[])) && scope() {
+               System.out.println("? " + thisJoinPoint.getSignature());
+               proceed();
+       }
+}
diff --git a/tests/bugs153/pr132080/AbstractSuperAspectWithInterface.aj b/tests/bugs153/pr132080/AbstractSuperAspectWithInterface.aj
new file mode 100644 (file)
index 0000000..8182dfd
--- /dev/null
@@ -0,0 +1,13 @@
+public abstract aspect AbstractSuperAspectWithInterface /*implements TestInterface*/ {
+       
+       protected abstract pointcut scope ();
+       
+       before () : execution(public static void main(String[])) && scope() {
+               System.out.println("? " + thisJoinPoint.getSignature());
+       }
+       
+       protected AbstractSuperAspectWithInterface () {
+               TestInterface test = (TestInterface)this;
+               test.interfaceMethod();
+       }
+}
diff --git a/tests/bugs153/pr132080/ConcreteAspectWithITD.aj b/tests/bugs153/pr132080/ConcreteAspectWithITD.aj
new file mode 100644 (file)
index 0000000..94b82f3
--- /dev/null
@@ -0,0 +1,4 @@
+public aspect ConcreteAspectWithITD extends AbstractSuperAspectWithInterface {
+       protected pointcut scope () :
+               !within(AbstractSuperAspectWithInterface+);
+}
\ No newline at end of file
diff --git a/tests/bugs153/pr132080/HelloWorld.java b/tests/bugs153/pr132080/HelloWorld.java
new file mode 100644 (file)
index 0000000..8f62298
--- /dev/null
@@ -0,0 +1,11 @@
+public class HelloWorld {
+
+       public void println () {
+               System.out.println("Hello World!");
+       }
+       
+       public static void main (String[] args) throws Exception {
+               new HelloWorld().println();
+       }
+       
+}
\ No newline at end of file
diff --git a/tests/bugs153/pr132080/TestAdvice.aj b/tests/bugs153/pr132080/TestAdvice.aj
new file mode 100644 (file)
index 0000000..f9f6453
--- /dev/null
@@ -0,0 +1,5 @@
+public aspect TestAdvice {
+       before () : execution(public new()) && within(!TestAdvice) {
+               System.out.println("? " + thisJoinPoint.getSignature());
+       }
+}
\ No newline at end of file
diff --git a/tests/bugs153/pr132080/TestAroundClosure.aj b/tests/bugs153/pr132080/TestAroundClosure.aj
new file mode 100644 (file)
index 0000000..b232545
--- /dev/null
@@ -0,0 +1,7 @@
+public aspect TestAroundClosure {
+       void around () : execution(public new()) && within(!TestAroundClosure) {
+               System.out.println("> " + thisJoinPoint.getSignature());
+               proceed();
+               System.out.println("< " + thisJoinPoint.getSignature());
+       }
+}
\ No newline at end of file
diff --git a/tests/bugs153/pr132080/TestITD.aj b/tests/bugs153/pr132080/TestITD.aj
new file mode 100644 (file)
index 0000000..3203b82
--- /dev/null
@@ -0,0 +1,8 @@
+public aspect TestITD {
+       
+       declare parents : AbstractSuperAspectWithInterface+ implements TestInterface;
+       
+       public void TestInterface.interfaceMethod () {
+               System.out.println("? void TestITD.interfaceMethod()");
+       }
+}
\ No newline at end of file
diff --git a/tests/bugs153/pr132080/TestInterface.java b/tests/bugs153/pr132080/TestInterface.java
new file mode 100644 (file)
index 0000000..1c831d3
--- /dev/null
@@ -0,0 +1,3 @@
+public interface TestInterface {
+       public void interfaceMethod ();
+}
\ No newline at end of file
diff --git a/tests/bugs153/pr132080/aop-advice.xml b/tests/bugs153/pr132080/aop-advice.xml
new file mode 100644 (file)
index 0000000..64b5548
--- /dev/null
@@ -0,0 +1,11 @@
+<aspectj>
+       <aspects>
+               <aspect name="TestAdvice"/>
+       
+               <concrete-aspect name="ConcreteAspectWithAdvice" extends="AbstractSuperAspect">
+                       <pointcut name="scope" expression="!within(AbstractSuperAspect+)"/>
+        </concrete-aspect>
+       </aspects>
+       <weaver options="-verbose -debug -showWeaveInfo"/>
+</aspectj>
+       
diff --git a/tests/bugs153/pr132080/aop-aroundclosure.xml b/tests/bugs153/pr132080/aop-aroundclosure.xml
new file mode 100644 (file)
index 0000000..1a2113c
--- /dev/null
@@ -0,0 +1,11 @@
+<aspectj>
+       <aspects>
+               <aspect name="TestAroundClosure"/>
+       
+               <concrete-aspect name="ConcreteAspectWithAroundClosure" extends="AbstractSuperAspect">
+                       <pointcut name="scope" expression="!within(AbstractSuperAspect+)"/>
+        </concrete-aspect>
+       </aspects>
+       <weaver options="-verbose -debug -showWeaveInfo -XnoInline"/>
+</aspectj>
+       
diff --git a/tests/bugs153/pr132080/aop-itd.xml b/tests/bugs153/pr132080/aop-itd.xml
new file mode 100644 (file)
index 0000000..9f5c0b4
--- /dev/null
@@ -0,0 +1,14 @@
+<aspectj>
+       <aspects>
+               <aspect name="TestITD"/>
+       
+               <concrete-aspect name="ConcreteAspectWithITD" extends="AbstractSuperAspectWithInterface">
+                       <pointcut name="scope" expression="!within(AbstractSuperAspectWithInterface+)"/>
+        </concrete-aspect>
+       </aspects>
+       
+       <weaver options="-verbose -debug -showWeaveInfo">
+               <!--<dump within="*"/>-->
+       </weaver>
+</aspectj>
+       
index ba987f808b571652f1dba910c93061745b4ee253..8b15846994bc8b9882b8a298ed66e4c1a41d5cd7 100644 (file)
@@ -1,6 +1,6 @@
 <aspectj>
   <weaver>
-    <dump within="*"/>
+    <!--<dump within="*"/>-->
   </weaver>
   <aspects>
     <concrete-aspect name="TestTracing" extends="SimpleTracing">
index bef05f716841475790448d0d6ddd5d3345634d01..caef4be71b2711ebdfeace7df37b8de9bd37bc2e 100644 (file)
@@ -134,6 +134,22 @@ public class Ajc153Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testNPEWithCustomAgent_pr158005() {
          runTest("NPE with custom agent");
   }
+
+  public void testWeaveConcreteSubaspectWithAdvice_pr132080() {
+         runTest("Weave concrete sub-aspect with advice");
+  }
+
+  public void testWeaveConcreteSubaspectWithITD_pr132080() {
+         runTest("Weave concrete sub-aspect with ITD");
+  }
+
+  public void testWeaveConcreteSubaspectWithAroundClosure_pr132080() {
+         runTest("Weave concrete sub-aspect with around closure");
+  }
+
+  public void testWeaveConcreteSubaspectWithCflow_pr132080() {
+         runTest("Weave concrete sub-aspect with cflow");
+  }
   
   public void testNoInvalidAbsoluteTypeNameWarning_pr156904_1() {runTest("ensure no invalidAbsoluteTypeName when do match - 1");}
   public void testNoInvalidAbsoluteTypeNameWarning_pr156904_2() {runTest("ensure no invalidAbsoluteTypeName when do match - 2");}
index 652472843f313a8020c461cf05a7d0bc5a0c370e..9b64b631fe536dddd2c78963e55ea3b872d32e42 100644 (file)
         </ant>
     </ajc-test>
 
+       <ajc-test dir="bugs153/pr132080"
+      title="Weave concrete sub-aspect with advice"
+      keywords="aop.xml">
+        <compile
+               files="HelloWorld.java"
+        >
+        </compile>     
+        <compile files="AbstractSuperAspect.aj"/>
+        <compile files="TestAdvice.aj"/>
+        <run class="HelloWorld" ltw="aop-advice.xml">
+               <stdout>
+                <line text="? ConcreteAspectWithAdvice()"/>
+                <line text="? void HelloWorld.main(String[])"/>
+                <line text="? HelloWorld()"/>
+                <line text="Hello World!"/>
+            </stdout>
+        </run>
+    </ajc-test>
+
+       <ajc-test dir="bugs153/pr132080"
+      title="Weave concrete sub-aspect with ITD"
+      keywords="aop.xml">
+<!--      
+        <compile files="AbstractSuperAspectWithInterface.aj, TestInterface.java" options="-verbose"/>
+        <compile files="HelloWorld.java, TestITD.aj, ConcreteAspectWithITD.aj" options="-verbose">
+            <message line="3" kind="warning" text="this affected type is not exposed to the weaver: AbstractSuperAspectWithInterface"/>
+        </compile>
+        <run class="HelloWorld">
+               <stdout>
+                <line text="? void TestITD.interfaceMethod()"/>
+                <line text="? void HelloWorld.main(String[])"/>
+                <line text="Hello World!"/>
+            </stdout>
+        </run>
+-->        
+        <compile files="HelloWorld.java"/>
+        <compile files="AbstractSuperAspectWithInterface.aj, TestInterface.java"/>
+        <compile files="TestITD.aj">
+            <message line="3" kind="warning" text="this affected type is not exposed to the weaver: AbstractSuperAspectWithInterface"/>
+        </compile>
+        <run class="HelloWorld" ltw="aop-itd.xml">
+               <stdout>
+                <line text="? void TestITD.interfaceMethod()"/>
+                <line text="? void HelloWorld.main(String[])"/>
+                <line text="Hello World!"/>
+            </stdout>
+        </run>
+
+    </ajc-test>
+
+       <ajc-test dir="bugs153/pr132080" title="Weave concrete sub-aspect with around closure" 
+               keywords="aop.xml">
+
+        <compile files="HelloWorld.java"/>
+        <compile files="AbstractSuperAspect.aj"/>
+        <compile files="TestAroundClosure.aj"/>
+        <run class="HelloWorld" ltw="aop-aroundclosure.xml">
+               <stdout>
+                <line text="&rt; ConcreteAspectWithAroundClosure()"/>
+                <line text="&lt; ConcreteAspectWithAroundClosure()"/>
+                <line text="? void HelloWorld.main(String[])"/>
+                <line text="&rt; HelloWorld()"/>
+                <line text="&lt; HelloWorld()"/>
+                <line text="Hello World!"/>
+            </stdout>
+        </run>
+    </ajc-test>
+
+    <ajc-test dir="bugs153/pr149096" title="Weave concrete sub-aspect with cflow">
+               <compile files="SimpleTracing.aj" outjar="out.jar"/>
+               <compile files="TestMain.aj"/>
+               <run class="TestMain" ltw="aop-pr149096.xml"/>
+    </ajc-test>
+    
+
 </suite>
\ No newline at end of file
index 4e4213e199040589ebde5791e4711e7ee8e4c0be..7d52c3afa698689d3e51c7de7e76b2c9f29ddffd 100644 (file)
@@ -418,6 +418,10 @@ public class WeavingAdaptor implements IMessageContext {
                return MessageUtil.error(messageHandler,message);
        }
        
+       protected boolean error (String message, Throwable th) {
+        return messageHandler.handleMessage(new Message(message, IMessage.ERROR, th, null));
+       }
+       
        public String getContextId () {
                return "WeavingAdaptor";
        }