From 8766cadf5e70cf564ebc6699e48e3b2b7f20ad0a Mon Sep 17 00:00:00 2001 From: wisberg Date: Tue, 22 Mar 2005 21:04:27 +0000 Subject: [PATCH] bug 53209 - inpathDirCopyFilter tests --- .../testdata/inpathDirs/InpathAspect.java | 7 ++ .../inpathDirs/inpathDirOne/pack/Pack.class | Bin 0 -> 235 bytes .../inpathDirs/inpathDirOne/pack/includeme | 1 + .../inpathDirOne/pack/something.txt | 1 + .../inpathDirs/inpathDirTwo/Default.class | Bin 0 -> 300 bytes .../inpathDirs/inpathDirTwo/copyMe.htm | 1 + .../inpathDirs/inpathDirTwo/doNotCopy | 0 .../inpathDirs/inpathDirTwo/skipTxtFiles.txt | 1 + .../tools/ant/taskdefs/AjcTaskTest.java | 91 +++++++++++++++++- 9 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 taskdefs/testdata/inpathDirs/InpathAspect.java create mode 100644 taskdefs/testdata/inpathDirs/inpathDirOne/pack/Pack.class create mode 100644 taskdefs/testdata/inpathDirs/inpathDirOne/pack/includeme create mode 100644 taskdefs/testdata/inpathDirs/inpathDirOne/pack/something.txt create mode 100644 taskdefs/testdata/inpathDirs/inpathDirTwo/Default.class create mode 100644 taskdefs/testdata/inpathDirs/inpathDirTwo/copyMe.htm create mode 100644 taskdefs/testdata/inpathDirs/inpathDirTwo/doNotCopy create mode 100644 taskdefs/testdata/inpathDirs/inpathDirTwo/skipTxtFiles.txt diff --git a/taskdefs/testdata/inpathDirs/InpathAspect.java b/taskdefs/testdata/inpathDirs/InpathAspect.java new file mode 100644 index 000000000..5929fab56 --- /dev/null +++ b/taskdefs/testdata/inpathDirs/InpathAspect.java @@ -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 index 0000000000000000000000000000000000000000..6821e2017fc47961df3c215d60c9903e4a252add GIT binary patch literal 235 zcmZXNy9&Zk5JYG5G%-F}3ky3HG(R9Vf|aPC*xw`YbXIXL*L4=iaxa3EiIvIfR73=K zSJY)Fm$9PGR)ptiBCf)N0h7Unfv+f`tGJ(v{OE6jM1~ax(70QT2JV8%YVp-)Cw6mu c2i&qbP{k5pqf!yZzC z{+|&>>!90W<;qAHyxQ_5zhmIdY8RiI1&(=j1vv>wvKTf04!IK7{^copyMecopyMe \ No newline at end of file diff --git a/taskdefs/testdata/inpathDirs/inpathDirTwo/doNotCopy b/taskdefs/testdata/inpathDirs/inpathDirTwo/doNotCopy new file mode 100644 index 000000000..e69de29bb diff --git a/taskdefs/testdata/inpathDirs/inpathDirTwo/skipTxtFiles.txt b/taskdefs/testdata/inpathDirs/inpathDirTwo/skipTxtFiles.txt new file mode 100644 index 000000000..5e40c0877 --- /dev/null +++ b/taskdefs/testdata/inpathDirs/inpathDirTwo/skipTxtFiles.txt @@ -0,0 +1 @@ +asdf \ No newline at end of file diff --git a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java index ee5be7103..b8ebf9655 100644 --- a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java +++ b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java @@ -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); -- 2.39.5