From 7f63882e35c3a5c7c8f92d5214ea78ca3dda9953 Mon Sep 17 00:00:00 2001 From: wisberg Date: Fri, 29 Aug 2003 18:00:30 +0000 Subject: [PATCH] sourceRootCopyFilter test --- taskdefs/testdata/sourceroot/Default.java | 7 +++ taskdefs/testdata/sourceroot/doNotCopy | 0 taskdefs/testdata/sourceroot/pack/Pack.java | 7 +++ taskdefs/testdata/sourceroot/pack/includeme | 1 + .../testdata/sourceroot/pack/something.txt | 1 + taskdefs/testdata/sourceroot/skipTxtFiles.txt | 1 + .../tools/ant/taskdefs/AjcTaskTest.java | 52 +++++++++++++++---- 7 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 taskdefs/testdata/sourceroot/Default.java create mode 100644 taskdefs/testdata/sourceroot/doNotCopy create mode 100644 taskdefs/testdata/sourceroot/pack/Pack.java create mode 100644 taskdefs/testdata/sourceroot/pack/includeme create mode 100644 taskdefs/testdata/sourceroot/pack/something.txt create mode 100644 taskdefs/testdata/sourceroot/skipTxtFiles.txt diff --git a/taskdefs/testdata/sourceroot/Default.java b/taskdefs/testdata/sourceroot/Default.java new file mode 100644 index 000000000..f2770d14d --- /dev/null +++ b/taskdefs/testdata/sourceroot/Default.java @@ -0,0 +1,7 @@ + + +public class Default { + public static void main(String[] args) { + pack.Pack.method(); + } +} \ No newline at end of file diff --git a/taskdefs/testdata/sourceroot/doNotCopy b/taskdefs/testdata/sourceroot/doNotCopy new file mode 100644 index 000000000..e69de29bb diff --git a/taskdefs/testdata/sourceroot/pack/Pack.java b/taskdefs/testdata/sourceroot/pack/Pack.java new file mode 100644 index 000000000..6db0049b0 --- /dev/null +++ b/taskdefs/testdata/sourceroot/pack/Pack.java @@ -0,0 +1,7 @@ + +package pack; + +public class Pack { + public static void method() { + } +} \ No newline at end of file diff --git a/taskdefs/testdata/sourceroot/pack/includeme b/taskdefs/testdata/sourceroot/pack/includeme new file mode 100644 index 000000000..5e40c0877 --- /dev/null +++ b/taskdefs/testdata/sourceroot/pack/includeme @@ -0,0 +1 @@ +asdf \ No newline at end of file diff --git a/taskdefs/testdata/sourceroot/pack/something.txt b/taskdefs/testdata/sourceroot/pack/something.txt new file mode 100644 index 000000000..d6d9d34ca --- /dev/null +++ b/taskdefs/testdata/sourceroot/pack/something.txt @@ -0,0 +1 @@ +blah \ No newline at end of file diff --git a/taskdefs/testdata/sourceroot/skipTxtFiles.txt b/taskdefs/testdata/sourceroot/skipTxtFiles.txt new file mode 100644 index 000000000..5e40c0877 --- /dev/null +++ b/taskdefs/testdata/sourceroot/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 f7936d1e9..3186e8df4 100644 --- a/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java +++ b/taskdefs/testsrc/org/aspectj/tools/ant/taskdefs/AjcTaskTest.java @@ -146,22 +146,58 @@ public class AjcTaskTest extends TestCase { AjcTask task = getTask("default.lst"); checkRun(task, null); + // copyInJars now just emits warning b/c unused task = getTask("default.lst", null); task.setCopyInjars(true); - checkRun(task, "copyInjars"); + checkRun(task, null); + // sourceRootCopyFilter requires destDir task = getTask("default.lst", null); - task.setSourceRootCopyFilter("*.java"); + task.setSourceRootCopyFilter("**/*.java"); checkRun(task, "sourceRoot"); } + public void testSourceRootCopyFilter () { + // sourceRootCopyFilter works.. + File destDir = getTempDir(); + assertTrue("unable to create " + destDir, + destDir.canRead() || destDir.mkdirs()); + AjcTask task = getTask("sourceroot", destDir); + task.setSourceRootCopyFilter("doNotCopy,**/*.txt"); + File file = new File(destDir, "Default.java").getAbsoluteFile(); + assertTrue(file + ".canRead() prematurely", !file.canRead()); + checkRun(task, null); + // got expected resources + assertTrue(file + ".canRead() failed", file.canRead()); + File pack = new File(destDir, "pack"); + file = new File(pack, "Pack.java").getAbsoluteFile(); + assertTrue(file + ".canRead() failed", file.canRead()); + file = new File(pack, "includeme").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()); + } + private void checkRun(AjcTask task, String exceptionString) { try { task.execute(); assertTrue(null == exceptionString); } catch (BuildException e) { - if(-1 == e.getMessage().indexOf(exceptionString)) { - assertEquals(exceptionString, e.getMessage()); + if (null == exceptionString) { + assertTrue("unexpected " + e.getMessage(), false); + } else { + String m = e.getMessage(); + if (null == m) { + assertTrue("not " + exceptionString, false); + } else if (-1 == m.indexOf(exceptionString)) { + assertEquals(exceptionString, e.getMessage()); + } } } @@ -266,18 +302,14 @@ public class AjcTaskTest extends TestCase { task.setArgfiles(new Path(task.getProject(), path)); } } else if ((input.endsWith(".java") || input.endsWith(".aj"))) { - // not working FilenameSelector fns = new FilenameSelector(); fns.setName(input); task.addFilename(fns); } else { - File dir = new File(input); - if (dir.canRead() && dir.isDirectory()) { - task.setSourceRoots(new Path(task.getProject(), input)); - } + String path = testdataDir + File.separator + input; + task.setSourceRoots(new Path(task.getProject(), path)); } task.setClasspath(new Path(p, "../lib/test/aspectjrt.jar")); - //task.setVerbose(true); return task; } -- 2.39.5