I am trying to use ant to copy files from sourceDir to destDir, and I also don't want to copy some files, I keep the file names I want to exclude in file: excludelist.txt. How could I implements this is an ant target ?
Use copy task with nested fileset using nested exludesfile.
From ant manual FileSet :
excludesfile => the name of a file; each line of this file is taken to
be an exclude pattern.
snippet :
<target name="foo">
<copy todir="path/to/destDir">
<fileset dir="path/to/sourceDir">
<excludesfile name="excludelist.txt"/>
</fileset>
</copy>
</target>
Related
I want to use ant script to copy a file to directory which is not path is fixed but last folder name is not fixed.
Path D:\Home\Config\plugins\1780.
The last folder name (1780) it changes randomly and is not fixed.
I want to copy a war file in to that folder.
How can I do it.
Thanks,
Prashant
You should iterate (once) over plugins subdirectories and copy to the (only?) entry.
<target name="run">
<foreach target="loop" param="loop.param">
<dirset dir="D:\Home\Config\plugins" />
</foreach>
</target>
<target name="loop">
<copy todir="$loop.param">
...
</copy>
</target>
I have the following fileset in my Apache Ant build file (BuildFilesetXML.xml):
<fileset id="XMLFileset" dir="mydir/myxml">
<include name="**/1.xml"/>
<include name="**/2.xml"/>
</fileset>
I want to create dynamically in a different build file (BuildFilesetLog.xml) (do not know the contents of "XMLFileset" in my 2nd build file) a new fileset named "LOGFileset" that will have the same contents of "XMLFileset" but with names renamed to .log. So, in runtime it will have the same structure as the following fileset:
<fileset id="LOGFileset">
<include name="**/1.log"/>
<include name="**/2.log"/>
</fileset>
Can this be done in Ant?
Thanks
No, but some tasks support mappers. For an example see the following answer:
Change directory of FileList when referencing it
I want to copy a jar file from ../source,but I am not sure where it exactly is,it can be anywhere in any subdirectory but it is there. I am writing this code
<target name="CopyingFromSource" depends="clean">
<copy file="../source/org.springframework-spring-support-2.0.8.jar" todir="../result"/>
</target>
but is showing me can't find org.springframework-spring-support-2.0.8.jar Can you please tell me how to copy it?
It is present anywhere either immediately in /source or in any subdirectory.
Use copy task with nested fileset like that :
<project>
<copy todir="../result">
<fileset dir="/home/gilreb/temp" includes="**/org.springframework-spring-support-2.0.8.jar" id="foobar"/>
</copy>
</project>
see Ant manual copy task and Ant manual fileset for turther details.. i.e. if you need to copy the flat file only and not it's whole path you need to use :
<copy todir="../result" flatten="true">
...
</copy>
Suppose I have a directory structure like the following
/a/b/testB.xml
/a/c/testC.xml
/a/testD.xml
and I want to copy everything inside /a to /build
so that I will have
/build/b/testB.xml
/build/c/testC.xml
/build/testD.xml
What ant command should I use? I have tried using fileset and it looks like that it only copies the files that are specified in the includes to the todir directory.
Try this:
<copy todir="build">
<fileset dir="a">
<include name="**/*"/>
</fileset>
</copy>
The docs on FileSet are here.
It's really easy to select a file with a specific filename, or filetype using fileset in ANT, however I have yet not figured out how to write a fileset that remove all files with a filename beginning with a dot, such as .builtpath, and .hgignore, but excluding .htaccess;
Here's my current file:
<delete includeemptydirs="true">
<fileset dir="${temp.dir}/fromRepo">
<exclude name=".htaccess"/>
<include name="**/*" /> <!-- How to select files starting with .?!-->
</fileset>
</delete>
Suggest you try:
<delete includeemptydirs="true">
<fileset dir="${temp.dir}/fromRepo">
<exclude name="**/.htaccess"/>
</fileset>
</delete>
If you don't specify any wildcard - as in ".htaccess" then that rule will only match the exact file name, i.e., '.htaccess' in the top-level directory of the fileset. Prepending the directory wildcard ** to .htaccess will tell Ant to exclude from the delete all files called '.htaccess' found under the directory hierarchy of the fileset.
There's an implicit include of all files if you don't specify any include rule - so no need to specify the 'global' include.
One thing to watch out for - setting includeemptydirs true will remove any empty directories when using a fileset with the delete task. A directory will only be considered empty if it doesn't contain any files. In other words: directories containing a file called '.htaccess' will not be deleted, but those with a '.htaccess' file will not be deleted - hope that's what you need.