git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278508 13f79535-47bb-0310-9956-ffa450edef68master
@@ -121,7 +121,76 @@ a=b= | |||
</copy> | |||
</target> | |||
<!-- | |||
<typedef name="resource" classname="org.apache.tools.ant.types.Resource"/> | |||
<typedef name="resources" classname="org.apache.tools.ant.types.resources.Resources"/> | |||
--> | |||
<target name="testFileResourcePlain" depends="testResource.prepare"> | |||
<copy todir="${to.dir}"> | |||
<resources> | |||
<file file="${from.dir}/file1.txt"/> | |||
<file file="${from.dir}/file2.txt"/> | |||
<file file="${from.dir}/file3.txt"/> | |||
</resources> | |||
</copy> | |||
</target> | |||
<target name="testFileResourceWithMapper" depends="testResource.prepare"> | |||
<copy todir="${to.dir}"> | |||
<resources> | |||
<file file="${from.dir}/file1.txt"/> | |||
<file file="${from.dir}/file2.txt"/> | |||
<file file="${from.dir}/file3.txt"/> | |||
</resources> | |||
<regexpmapper from="^(.*)\.txt$$" to="\1.txt.bak"/> | |||
</copy> | |||
</target> | |||
<property name="to.dir" value="copy-todir-tmp"/> | |||
<property name="from.dir" value="copy-todir-tmp"/> | |||
<target name="testResource.prepare"> | |||
<mkdir dir="${from.dir}"/> | |||
<concat destfile="${to.dir}/file1.txt">This is file 1</concat> | |||
<concat destfile="${to.dir}/file2.txt">This is file 2</concat> | |||
<concat destfile="${to.dir}/file3.txt">This is file 3</concat> | |||
<concat destfile="${to.dir}/fileNR.txt">This is file @nr@</concat> | |||
</target> | |||
<target name="testFileResourceWithFilter" depends="testResource.prepare"> | |||
<copy todir="${to.dir}"> | |||
<resources> | |||
<file file="${from.dir}/fileNR.txt"/> | |||
</resources> | |||
<filterset> | |||
<filter token="NR" value="42"/> | |||
</filterset> | |||
</copy> | |||
</target> | |||
<target name="testResourcePlain"> | |||
</target> | |||
<target name="testResourcePlainWithMapper"> | |||
</target> | |||
<target name="testResourcePlainWithFilter"> | |||
</target> | |||
<target name="testOnlineResources"> | |||
</target> | |||
<target name="testPathAsResource"> | |||
<copy todir="${to.dir}"> | |||
<path> | |||
<fileset dir="${from.dir}"/> | |||
</path> | |||
</copy> | |||
</target> | |||
<target name="cleanup"> | |||
<delete file="copytest1.tmp"/> | |||
@@ -135,7 +204,7 @@ a=b= | |||
<delete dir="copytest1dir"/> | |||
<delete quiet="yes" file="copy.filter.out"/> | |||
<delete quiet="yes" file="copy.filter.inp"/> | |||
<delete dir="${to.dir}"/> | |||
</target> | |||
</project> |
@@ -31,6 +31,10 @@ import org.apache.tools.ant.types.FileSet; | |||
import org.apache.tools.ant.types.FilterSet; | |||
import org.apache.tools.ant.types.FilterChain; | |||
import org.apache.tools.ant.types.FilterSetCollection; | |||
import org.apache.tools.ant.types.Resource; | |||
import org.apache.tools.ant.types.Path; | |||
import org.apache.tools.ant.types.ResourceCollection; | |||
import org.apache.tools.ant.types.resources.Resources; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.apache.tools.ant.util.FileNameMapper; | |||
import org.apache.tools.ant.util.IdentityMapper; | |||
@@ -274,7 +278,42 @@ public class Copy extends Task { | |||
public void addFileset(FileSet set) { | |||
filesets.addElement(set); | |||
} | |||
/* JHM: It would be the finest solution to use this method directly. | |||
* But if I understood the IntrospectionHelper(final Class bean) | |||
* right - especially line 258ff (the last "else if" statement), | |||
* I must have a <b>class</b> with an no-arg constructor. But I only | |||
* have an interface. :-( | |||
* So I have to add the three methods ... But I can reuse this | |||
* method :-) | |||
* | |||
*/ | |||
public void add(ResourceCollection res) { | |||
//TODO: implement resources | |||
} | |||
/** | |||
* Adds a <code>path</code> element as a nested ResourceCollection. | |||
* @param path | |||
*/ | |||
public void addPath(Path path) { | |||
//add((ResourceCollection)path); | |||
} | |||
/** | |||
* Adds a Resource element as a nested ResourceCollection. | |||
* @param path | |||
* / | |||
public void add(Resource res) { | |||
add((ResourceCollection)res); | |||
} | |||
/** | |||
* Adds a <code>resources</code> element as a nested ResourceCollection. | |||
* @param path | |||
* / | |||
public void add(Resources res) { | |||
add((ResourceCollection)res); | |||
} | |||
*/ | |||
/** | |||
* Define the mapper to map source to destination files. | |||
* @return a mapper to be configured. | |||
@@ -82,7 +82,6 @@ nice=org.apache.tools.ant.taskdefs.Nice | |||
libraries=org.apache.tools.ant.taskdefs.repository.Libraries | |||
length=org.apache.tools.ant.taskdefs.Length | |||
clone=org.apache.tools.ant.taskdefs.Clone | |||
copypath=org.apache.tools.ant.taskdefs.CopyPath | |||
diagnostics=org.apache.tools.ant.taskdefs.DiagnosticsTask | |||
# optional tasks | |||
@@ -220,3 +219,4 @@ deltree=org.apache.tools.ant.taskdefs.Deltree | |||
rename=org.apache.tools.ant.taskdefs.Rename | |||
WsdlToDotnet=org.apache.tools.ant.taskdefs.optional.dotnet.WsdlToDotnet | |||
style=org.apache.tools.ant.taskdefs.XSLTProcess | |||
copypath=org.apache.tools.ant.taskdefs.CopyPath |
@@ -20,6 +20,7 @@ package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileTest; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import java.io.File; | |||
import java.io.FileReader; | |||
import java.io.IOException; | |||
/** | |||
@@ -146,4 +147,63 @@ public class CopyTest extends BuildFileTest { | |||
expectBuildException("testMissingDirBail", "not-there doesn't exist"); | |||
assertTrue(getBuildException().getMessage().endsWith(" not found.")); | |||
} | |||
public void _testFileResourcePlain() { | |||
executeTarget("testFileResourcePlain"); | |||
File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file1.txt"); | |||
File file2 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file2.txt"); | |||
File file3 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file3.txt"); | |||
assertTrue(file1.exists()); | |||
assertTrue(file2.exists()); | |||
assertTrue(file3.exists()); | |||
} | |||
public void _testFileResourceWithMapper() { | |||
executeTarget("testFileResourceWithMapper"); | |||
File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file1.txt.bak"); | |||
File file2 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file2.txt.bak"); | |||
File file3 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file3.txt.bak"); | |||
assertTrue(file1.exists()); | |||
assertTrue(file2.exists()); | |||
assertTrue(file3.exists()); | |||
} | |||
public void _testFileResourceWithFilter() { | |||
executeTarget("testFileResourceWithFilter"); | |||
File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/fileNR.txt"); | |||
assertTrue(file1.exists()); | |||
try { | |||
String file1Content = FILE_UTILS.readFully(new FileReader(file1)); | |||
assertEquals(file1Content, "This is file 42"); | |||
} catch (IOException e) { | |||
// no-op: not a real business error | |||
} | |||
} | |||
public void _testPathAsResource() { | |||
executeTarget("testPathAsResource"); | |||
File file1 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file1.txt.bak"); | |||
File file2 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file2.txt.bak"); | |||
File file3 = new File(getProjectDir(), getProject().getProperty("to.dir")+"/file3.txt.bak"); | |||
assertTrue(file1.exists()); | |||
assertTrue(file2.exists()); | |||
assertTrue(file3.exists()); | |||
} | |||
public void _testResourcePlain() { | |||
executeTarget("testResourcePlain"); | |||
} | |||
public void _testResourcePlainWithMapper() { | |||
executeTarget("testResourcePlainWithMapper"); | |||
} | |||
public void _testResourcePlainWithFilter() { | |||
executeTarget("testResourcePlainWithFilter"); | |||
} | |||
public void _testOnlineResources() { | |||
executeTarget("testOnlineResources"); | |||
} | |||
} |