]> source.dussan.org Git - aspectj.git/commitdiff
bug 53209 - inpathDirCopyFilter tests
authorwisberg <wisberg>
Tue, 22 Mar 2005 21:04:27 +0000 (21:04 +0000)
committerwisberg <wisberg>
Tue, 22 Mar 2005 21:04:27 +0000 (21:04 +0000)
taskdefs/testdata/inpathDirs/InpathAspect.java [new file with mode: 0644]
taskdefs/testdata/inpathDirs/inpathDirOne/pack/Pack.class [new file with mode: 0644]
taskdefs/testdata/inpathDirs/inpathDirOne/pack/includeme [new file with mode: 0644]
taskdefs/testdata/inpathDirs/inpathDirOne/pack/something.txt [new file with mode: 0644]
taskdefs/testdata/inpathDirs/inpathDirTwo/Default.class [new file with mode: 0644]
taskdefs/testdata/inpathDirs/inpathDirTwo/copyMe.htm [new file with mode: 0644]
taskdefs/testdata/inpathDirs/inpathDirTwo/doNotCopy [new file with mode: 0644]
taskdefs/testdata/inpathDirs/inpathDirTwo/skipTxtFiles.txt [new file with mode: 0644]
taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java

diff --git a/taskdefs/testdata/inpathDirs/InpathAspect.java b/taskdefs/testdata/inpathDirs/InpathAspect.java
new file mode 100644 (file)
index 0000000..5929fab
--- /dev/null
@@ -0,0 +1,7 @@
+
+public aspect InpathAspect {
+    after() returning : staticinitialization(Default)
+        || staticinitialization(pack.Pack) {
+        System.out.println("initialized " + thisJoinPoint);
+    }
+}
\ No newline at end of file
diff --git a/taskdefs/testdata/inpathDirs/inpathDirOne/pack/Pack.class b/taskdefs/testdata/inpathDirs/inpathDirOne/pack/Pack.class
new file mode 100644 (file)
index 0000000..6821e20
Binary files /dev/null and b/taskdefs/testdata/inpathDirs/inpathDirOne/pack/Pack.class differ
diff --git a/taskdefs/testdata/inpathDirs/inpathDirOne/pack/includeme b/taskdefs/testdata/inpathDirs/inpathDirOne/pack/includeme
new file mode 100644 (file)
index 0000000..5e40c08
--- /dev/null
@@ -0,0 +1 @@
+asdf
\ No newline at end of file
diff --git a/taskdefs/testdata/inpathDirs/inpathDirOne/pack/something.txt b/taskdefs/testdata/inpathDirs/inpathDirOne/pack/something.txt
new file mode 100644 (file)
index 0000000..d6d9d34
--- /dev/null
@@ -0,0 +1 @@
+blah
\ No newline at end of file
diff --git a/taskdefs/testdata/inpathDirs/inpathDirTwo/Default.class b/taskdefs/testdata/inpathDirs/inpathDirTwo/Default.class
new file mode 100644 (file)
index 0000000..84cb191
Binary files /dev/null and b/taskdefs/testdata/inpathDirs/inpathDirTwo/Default.class differ
diff --git a/taskdefs/testdata/inpathDirs/inpathDirTwo/copyMe.htm b/taskdefs/testdata/inpathDirs/inpathDirTwo/copyMe.htm
new file mode 100644 (file)
index 0000000..124ceef
--- /dev/null
@@ -0,0 +1 @@
+<html><head><title>copyMe</title></head><body>copyMe</body></html>
\ No newline at end of file
diff --git a/taskdefs/testdata/inpathDirs/inpathDirTwo/doNotCopy b/taskdefs/testdata/inpathDirs/inpathDirTwo/doNotCopy
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/taskdefs/testdata/inpathDirs/inpathDirTwo/skipTxtFiles.txt b/taskdefs/testdata/inpathDirs/inpathDirTwo/skipTxtFiles.txt
new file mode 100644 (file)
index 0000000..5e40c08
--- /dev/null
@@ -0,0 +1 @@
+asdf
\ No newline at end of file
index ee5be7103c572b64b760d6f06be1c45d0791ec1a..b8ebf9655e6e3ff7f2704bb61a8ce6c14dada33e 100644 (file)
@@ -23,6 +23,8 @@ import org.aspectj.util.*;
 import java.io.*;
 import java.io.File;
 import java.util.Arrays;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
 
 import junit.framework.TestCase;
 
@@ -197,7 +199,94 @@ public class AjcTaskTest extends TestCase {
                assertTrue(file + ".canRead() passed", !file.canRead());
        }
 
-       private void checkRun(AjcTask task, String exceptionString) {
+    public void testInpathDirCopyFilter() {
+        // inpathDirCopyFilter works with output directory
+        File destDir = getTempDir();
+        assertTrue(
+            "unable to create " + destDir,
+            destDir.canRead() || destDir.mkdirs());
+        AjcTask task = getTask(NOFILE, destDir);        
+        Project p = task.getProject();
+        Path indirs = new Path(p);
+        File dir = new File(testdataDir, "inpathDirs").getAbsoluteFile();
+        indirs.addExisting(new Path(p, new File(dir, "inpathDirOne").getAbsolutePath()));
+        indirs.addExisting(new Path(p, new File(dir, "inpathDirTwo").getAbsolutePath()));
+        task.setInpath(indirs);
+        task.setInpathDirCopyFilter("doNotCopy,**/*.txt");
+        
+        File file = new File(destDir, "Default.java").getAbsoluteFile();
+        assertTrue(file + ".canRead() prematurely", !file.canRead());
+        checkRun(task, null);
+
+        // got expected resources
+        File pack = new File(destDir, "pack");
+        file = new File(pack, "includeme").getAbsoluteFile();
+        assertTrue(file + ".canRead() failed", file.canRead());
+        file = new File(pack, "Pack.class").getAbsoluteFile();
+        assertTrue(file + ".canRead() failed", file.canRead());
+        file = new File(destDir, "copyMe.htm").getAbsoluteFile();
+        assertTrue(file + ".canRead() failed", file.canRead());
+        file = new File(destDir, "Default.class").getAbsoluteFile();
+        assertTrue(file + ".canRead() failed", file.canRead());
+
+        // didn't get unexpected resources
+        file = new File(pack, "something.txt");
+        assertTrue(file + ".canRead() passed", !file.canRead());
+        file = new File(destDir, "doNotCopy");
+        assertTrue(file + ".canRead() passed", !file.canRead());
+        file = new File(destDir, "skipTxtFiles.txt");
+        assertTrue(file + ".canRead() passed", !file.canRead());
+    }
+    
+    public void testInpathDirCopyFilterWithJar() throws IOException {
+        // inpathDirCopyFilter works with output jar
+        File destDir = getTempDir();
+        assertTrue(
+            "unable to create " + destDir,
+            destDir.canRead() || destDir.mkdirs());
+        AjcTask task = getTask(NOFILE, null);        
+        File destJar = new File(destDir, "testInpathDirCopyFilterWithJar-out.jar");
+        task.setOutjar(destJar);
+        Project p = task.getProject();
+        Path indirs = new Path(p);
+        File dir = new File(testdataDir, "inpathDirs").getAbsoluteFile();
+        indirs.addExisting(new Path(p, new File(dir, "inpathDirOne").getAbsolutePath()));
+        indirs.addExisting(new Path(p, new File(dir, "inpathDirTwo").getAbsolutePath()));
+        task.setInpath(indirs);
+        task.setInpathDirCopyFilter("doNotCopy,**/*.txt,**/*.class");
+        
+        checkRun(task, null);
+
+        JarFile jarFile = new JarFile(destJar);
+        String[] expected = {"copyMe.htm", "pack/includeme", 
+                "pack/Pack.class", "Default.class"};
+        String[] unexpected = {"doNotCopy", "skipTxtFiles.txt", "pack/something.txt"};
+        for (int i = 0; i < expected.length; i++) {
+            JarEntry entry = jarFile.getJarEntry(expected[i]);
+            assertTrue(expected[i] + " not found", null != entry);
+        }
+        for (int i = 0; i < unexpected.length; i++) {
+            JarEntry entry = jarFile.getJarEntry(unexpected[i]);
+            assertTrue(unexpected[i] + " found", null == entry);
+        }
+    }
+
+    public void testInpathDirCopyFilterError() {
+        // inpathDirCopyFilter fails with no output directory or jar iff specified
+        AjcTask task = getTask(NOFILE, null);        
+        Project p = task.getProject();
+        Path indirs = new Path(p);
+        File dir = new File(testdataDir, "inpathDirs").getAbsoluteFile();
+        indirs.addExisting(new Path(p, new File(dir, "inpathDirOne").getAbsolutePath()));
+        indirs.addExisting(new Path(p, new File(dir, "inpathDirTwo").getAbsolutePath()));
+        task.setInpath(indirs);
+        task.setInpathDirCopyFilter("doNotCopy,**/*.txt,**/*.class");
+
+        // expecting error
+        checkRun(task, "inpathDirCopyFilter");
+    }
+
+    private void checkRun(AjcTask task, String exceptionString) {
                try {
                        task.execute();
                        assertTrue(null == exceptionString);