]> source.dussan.org Git - aspectj.git/commitdiff
test and fixes for 152366: support AND in include/exclude/dump
authoraclement <aclement>
Tue, 3 Oct 2006 14:30:21 +0000 (14:30 +0000)
committeraclement <aclement>
Tue, 3 Oct 2006 14:30:21 +0000 (14:30 +0000)
loadtime/src/org/aspectj/weaver/loadtime/definition/DocumentParser.java
tests/ltw/inclExcl/aop-aspectinclexcl.xml [new file with mode: 0644]
tests/ltw/inclExcl/aop-exclude.xml [new file with mode: 0644]
tests/ltw/inclExcl/aop-include.xml [new file with mode: 0644]
tests/ltw/inclExcl/pkg/Main.aj [new file with mode: 0644]
tests/ltw/inclExcl/pkg/sub/Foo.aj [new file with mode: 0644]
tests/ltw/inclExcl/tracing/Tracer.aj [new file with mode: 0644]
tests/ltw/inclExcl/tracing/staticinit/Tracer.aj [new file with mode: 0644]
tests/ltw/inclExcl/tracing/staticinit/sub/Tracer.aj [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/ltw/LTWTests.java
tests/src/org/aspectj/systemtest/ajc150/ltw/ltw-tests.xml

index 2800ebece82b1bfa3463f9fc1f5c1bdeb816862a..2e109527adf95167adea2619361b916e10076fa4 100644 (file)
@@ -193,17 +193,17 @@ public class DocumentParser extends DefaultHandler {
         } else if (ASPECTS_ELEMENT.equals(qName)) {
             m_inAspects = true;
         } else if (INCLUDE_ELEMENT.equals(qName) && m_inWeaver) {
-            String typePattern = attributes.getValue(WITHIN_ATTRIBUTE);
+            String typePattern = getWithinAttribute(attributes);
             if (!isNull(typePattern)) {
                 m_definition.getIncludePatterns().add(typePattern);
             }
         } else if (EXCLUDE_ELEMENT.equals(qName) && m_inWeaver) {
-            String typePattern = attributes.getValue(WITHIN_ATTRIBUTE);
+            String typePattern = getWithinAttribute(attributes);
             if (!isNull(typePattern)) {
                 m_definition.getExcludePatterns().add(typePattern);
             }
         } else if (DUMP_ELEMENT.equals(qName) && m_inWeaver) {
-            String typePattern = attributes.getValue(WITHIN_ATTRIBUTE);
+            String typePattern = getWithinAttribute(attributes);
             if (!isNull(typePattern)) {
                 m_definition.getDumpPatterns().add(typePattern);
             }
@@ -212,12 +212,12 @@ public class DocumentParser extends DefaultHandler {
                m_definition.setDumpBefore(true);
             }
         } else if (EXCLUDE_ELEMENT.equals(qName) && m_inAspects) {
-            String typePattern = attributes.getValue(WITHIN_ATTRIBUTE);
+            String typePattern = getWithinAttribute(attributes);
             if (!isNull(typePattern)) {
                 m_definition.getAspectExcludePatterns().add(typePattern);
             }
         } else if (INCLUDE_ELEMENT.equals(qName) && m_inAspects) {
-            String typePattern = attributes.getValue(WITHIN_ATTRIBUTE);
+            String typePattern = getWithinAttribute(attributes);
             if (!isNull(typePattern)) {
                 m_definition.getAspectIncludePatterns().add(typePattern);
             }
@@ -227,6 +227,10 @@ public class DocumentParser extends DefaultHandler {
         super.startElement(uri, localName, qName, attributes);
     }
 
+       private String getWithinAttribute(Attributes attributes) {
+               return replaceXmlAnd(attributes.getValue(WITHIN_ATTRIBUTE));
+       }
+
     public void endElement(String uri, String localName, String qName) throws SAXException {
         if (CONCRETE_ASPECT_ELEMENT.equals(qName)) {
             m_lastConcreteAspect = null;
diff --git a/tests/ltw/inclExcl/aop-aspectinclexcl.xml b/tests/ltw/inclExcl/aop-aspectinclexcl.xml
new file mode 100644 (file)
index 0000000..5f4c88d
--- /dev/null
@@ -0,0 +1,10 @@
+<aspectj>
+<aspects>
+<aspect name="tracing.Tracer"/>
+<aspect name="tracing.staticinit.Tracer"/>
+<aspect name="tracing.staticinit.sub.Tracer"/>
+<include within="tracing..* AND !tracing.staticinit.sub..*"/>
+<exclude within="tracing..* AND !tracing.staticinit..*"/>
+</aspects>
+</aspectj>
+
diff --git a/tests/ltw/inclExcl/aop-exclude.xml b/tests/ltw/inclExcl/aop-exclude.xml
new file mode 100644 (file)
index 0000000..b13fcf0
--- /dev/null
@@ -0,0 +1,9 @@
+<aspectj>
+<weaver>
+<exclude within="pkg..* AND !pkg.sub..*"/>
+</weaver>
+<aspects>
+<aspect name="tracing.Tracer"/>
+</aspects>
+</aspectj>
+
diff --git a/tests/ltw/inclExcl/aop-include.xml b/tests/ltw/inclExcl/aop-include.xml
new file mode 100644 (file)
index 0000000..afdac0f
--- /dev/null
@@ -0,0 +1,10 @@
+<aspectj>
+<weaver>
+<include within="pkg..* AND !pkg.sub..*"/>
+<dump within="pkg..* AND !pkg.sub..*"/>
+</weaver>
+<aspects>
+<aspect name="tracing.Tracer"/>
+</aspects>
+</aspectj>
+
diff --git a/tests/ltw/inclExcl/pkg/Main.aj b/tests/ltw/inclExcl/pkg/Main.aj
new file mode 100644 (file)
index 0000000..6cf8ae9
--- /dev/null
@@ -0,0 +1,46 @@
+package pkg;
+
+import java.io.File;
+
+public class Main {
+    public static void main(String argz[]) {
+        foo();
+    }
+
+    public static void foo() {
+        (new pkg.sub.Foo()).foo();
+        
+        File dumpDir = new File("_ajdump"); 
+        lsLR(dumpDir);
+        
+        // the LTW harness should clean up _ajdump files!
+        cleanup(dumpDir);
+    }
+    
+    public static void lsLR(File dir) {
+        String[] files = dir.list();
+        if (files == null) return;
+        for (int i=0; i<files.length; i++) {
+               File f = new File(dir, files[i]);
+               if (f.isFile()) {
+                       System.err.println(files[i]);
+               } else {
+                       lsLR(f);
+               }
+        }      
+    }
+    
+    public static void cleanup(File dir) {
+        String[] files = dir.list();
+        if (files == null) return;
+        for (int i=0; i<files.length; i++) {
+               File f = new File(dir, files[i]);
+               if (f.isFile()) {
+                       f.delete();
+               } else {
+                       cleanup(f);
+               }
+        }      
+               dir.delete();
+    }
+}
diff --git a/tests/ltw/inclExcl/pkg/sub/Foo.aj b/tests/ltw/inclExcl/pkg/sub/Foo.aj
new file mode 100644 (file)
index 0000000..f93bcf2
--- /dev/null
@@ -0,0 +1,5 @@
+package pkg.sub;
+
+public class Foo {
+    public void foo() {}
+}
diff --git a/tests/ltw/inclExcl/tracing/Tracer.aj b/tests/ltw/inclExcl/tracing/Tracer.aj
new file mode 100644 (file)
index 0000000..691eefc
--- /dev/null
@@ -0,0 +1,7 @@
+package tracing;
+
+public aspect Tracer {
+    before() : execution(* foo()) {
+        System.err.println(thisJoinPoint);
+    }
+}
diff --git a/tests/ltw/inclExcl/tracing/staticinit/Tracer.aj b/tests/ltw/inclExcl/tracing/staticinit/Tracer.aj
new file mode 100644 (file)
index 0000000..8ceebd2
--- /dev/null
@@ -0,0 +1,7 @@
+package tracing.staticinit;
+
+public aspect Tracer {
+    before() : staticinitialization(pkg..*) {
+        System.err.println(thisJoinPoint);
+    }
+}
diff --git a/tests/ltw/inclExcl/tracing/staticinit/sub/Tracer.aj b/tests/ltw/inclExcl/tracing/staticinit/sub/Tracer.aj
new file mode 100644 (file)
index 0000000..2cc3d62
--- /dev/null
@@ -0,0 +1,7 @@
+package tracing.staticinit.sub;
+
+public aspect Tracer {
+    before() : staticinitialization(pkg..*) {
+        System.err.println("sub: "+thisJoinPoint);
+    }
+}
index cf59b8cb1717eae27e67451c465e151854e368da..31783f6d6eb460c9c184a159c192ce6d3870d069 100644 (file)
@@ -30,8 +30,18 @@ public class LTWTests extends org.aspectj.testing.XMLBasedAjcTestCase {
     return new File("../tests/src/org/aspectj/systemtest/ajc150/ltw/ltw.xml");
   }
   
-
-
+  public void testInclusionAndPattern() {
+    runTest("Inclusion and patterns");                 
+  }
+       
+  public void testExclusionAndPattern() {
+       runTest("Exclusion and patterns");              
+  }
+               
+  public void testAndPatternsAspects() {
+       runTest("And patterns aspects");                
+  }
+                       
        public void test001(){
                runTest("Ensure 1st aspect is rewoven when weaving 2nd aspect");
        }
index 01167c34ed322d501edf2dd93ebf96a72c4e4ca1..120829aabb90f1b67120db38473f85517c585d10 100644 (file)
                </stdout>
         </ant>
     </ajc-test>
+      
+       <ajc-test dir="ltw/inclExcl" title="Inclusion and patterns" keywords="ltw">
+        <compile
+               files="pkg\sub\Foo.aj, pkg\Main.aj"
+               options="-outjar base.jar"
+        />
+        <compile
+               files="tracing/Tracer.aj"
+        />
+        <run class="pkg.Main" ltw="aop-include.xml">
+            <stderr>
+                <line text="execution(void pkg.Main.foo())"/>
+                <line text="Main.class"/>
+            </stderr>
+        </run>
+    </ajc-test>
+       <ajc-test dir="ltw/inclExcl" title="Exclusion and patterns" keywords="ltw">
+        <compile
+               files="pkg\sub\Foo.aj, pkg\Main.aj"
+               options="-outjar base.jar"
+        />
+        <compile
+               files="tracing/Tracer.aj"
+        />
+        <run class="pkg.Main" ltw="aop-exclude.xml">
+            <stderr>
+                <line text="execution(void pkg.sub.Foo.foo())"/>
+            </stderr>
+        </run>
+    </ajc-test>    
+       <ajc-test dir="ltw/inclExcl" title="And patterns aspects" keywords="ltw">
+        <compile
+               files="pkg\sub\Foo.aj, pkg\Main.aj"
+               options="-outjar base.jar"
+        />
+        <compile
+               files="tracing/Tracer.aj, tracing/staticinit/Tracer.aj, tracing/staticinit/sub/Tracer.aj"
+        />
+        <run class="pkg.Main" ltw="aop-aspectinclexcl.xml">
+            <stderr>
+                <line text="staticinitialization(pkg.Main.&lt;clinit&gt;)"/>
+                <line text="staticinitialization(pkg.sub.Foo.&lt;clinit&gt;)"/>
+            </stderr>
+        </run>
+    </ajc-test>       
     
     
\ No newline at end of file