Ant release script - ant

Please see the blow script for doing the backup of current ear and replacing it with new version.
<move todir="/usr/local/jboss/server/default/ear_bk/" includeEmptyDirs="yes" verbose="true">
<fileset dir="/usr/local/jboss/release/server/default/deploy/tgr_10_10L_0036.ear" >
<include name="**/*" />
</fileset>
</move>
<copy todir="/usr/local/jboss/server/default/deploy/">
<fileset dir="/usr/local/jboss/release/server/default/deploy/tgr_10_10L_0037.ear"/>
</copy>
</target>
Issue:
1) Only the content of the tgr_10_10L_0036.ear is moved to ear_bk. How to move the tgr_10_10L_0036.ear?.
2) How to copy the complete tgr_10_10L_0037.ear directory to usr/local/jboss/server/default/deploy/ instead only the content ?

Simple quick fix is providing tgr_10_10L_0037.ear in todir
<copy todir="/usr/local/jboss/server/default/deploy/tgr_10_10L_0037.ear/">
<fileset dir="/usr/local/jboss/release/server/default/deploy/tgr_10_10L_0037.ear"/>
</copy>
for this you need to create tgr_10_10L_0037.ear before copying files
<mkdir dir="/usr/local/jboss/server/default/deploy/tgr_10_10L_0037.ear/"/>

Related

How to copy a files to a particular dir using ant?

i need to copy test.bat into the bin folder
i worte a code in build.xml such that it should copy a file from bin/test.bat to dist/intall/windows/
but it not copying
project structure
project
|-dist-install-windows-bin
|-etc-bin-test.bat
|-src-build.xml
<target name="copy">
<copy todir="./dist/install/windows/bin">
<fileset dir=".">
<include name="etc/bin/test.bat"/>
</fileset>
</copy>
</target>
Give parent directory as "dir" attribute
<fileset dir="..">
<include name="etc/bin/test.bat"/>
</fileset>

Update fileset using ant dynamically

I would like to create a jar file dynamically depending on selected java modules
Here is the part of the ant script which does that.
<property name="modules.selected" value="A,C,F" />
<for list="${modules.selected}" param="module">
<sequential>
<echo>Module chosen ${basedir}/#{module}/src</echo>
<copy todir="${build.dir.src}" overwrite="true">
<fileset dir="${basedir}/#{module}/src">
<include name="**/*.${src.valid.exts}" />
</fileset>
</copy>
</sequential>
</for>
In the above script I am selecting a module and then constructing a directory and copying all the modules present in the directory to a location (build/src).
But I really dont like the logic mentioned above would like to change to include all the required modules in a fileset and use the populated fileset to copy.
Here is the logic I am looking for
<fileset id="required-modules" dir="${basedir}/#{module}/src">
<for list="${modules.selected}" param="module">
<sequential>
<echo>Module chosen ${basedir}/#{module}/src</echo>
<include name="**/*.${src.valid.exts}" />
</sequential>
</for>
</fileset>
<copy todir="${build.dir.src}" overwrite="true">
<fileset refid="required-modules" />
</copy>
Could anyone update the above script to make it work.

How do I use Ant to copy a folder?

I'm trying to copy a directory using the Ant copy task.
I am a newbie at Ant; my current solution is:
<copy todir="${release_dir}/lib">
<fileset dir="${libpath}" />
</copy>
I'm wondering if there is a better and shorter way to accomplish the same thing?
First of all, those are the examples from Ant documentation:
Copy a directory to another directory
<copy todir="../new/dir">
<fileset dir="src_dir"/>
</copy>
Copy a set of files to a directory
<copy todir="../dest/dir">
<fileset dir="src_dir">
<exclude name="**/*.java"/>
</fileset>
</copy>
<copy todir="../dest/dir">
<fileset dir="src_dir" excludes="**/*.java"/>
</copy>
Copy a set of files to a directory, appending .bak to the file name on the fly
<copy todir="../backup/dir">
<fileset dir="src_dir"/>
<globmapper from="*" to="*.bak"/>
</copy>
Secondly, here is the whole documentation about copy task.
Just because the docs were not very clear to me, and because the time I spent can serve others:
The docs say that this "copies a directory (dir1) to another directory (dest)":
<copy todir="../new/dest">
<fileset dir="src/dir1"/>
</copy>
Actually, this does not mean "copy dir1 inside dest", but rather "copy the contents of dir1 inside dest".
(In general, in Ant, the "root dir" of a filesets -as well at the todir attribute- is not considered as being part of the set itself.)
To place the directory dir1 inside dest one has several alternatives (none totally satisfying to me - and I'd imagined that the new DirSet would help here, but no)
<copy todir="../new/dest/dir1">
<fileset dir="src/dir1"/>
</copy>
or
<copy todir="../new/dest">
<fileset dir="src" includes="dir1/**"/>
</copy>
See also here and here.
From http://ant.apache.org/manual/Tasks/copy.html:
<copy todir="../new/dir">
<fileset dir="src_dir"/>
</copy>
This will do it:
<copy todir="directory/to/copy/to">
<fileset dir="directory/to/copy/from"/>
</copy>
The ant manual is your friend: Ant Manual, in this case: Copy Task

How can I process only files that have changed?

At the moment I'm doing this:
<delete dir="${RSA.dir}/file1" />
<copy todir="${RSA.dir}/file1" >
<fileset dir="${CLEARCASE.dir}/file1" />
</copy>
and repeating the same thing for other files - but it takes a long time.
I only want to delete and copy files that have been updated, with their modified date in clearcase later than that in RSA.
How can I do that?
Look into the sync task.
If you want to do it based on file contents, and ignore the timestamp, I think this macro will do that:
<macrodef name="mirror" description="Copy files only if different; remove files that do not exist in dir. This works similiar to robocopy /MIR." >
<attribute name="dir"/>
<attribute name="todir"/>
<sequential>
<copy overwrite="true" todir="#{todir}">
<fileset dir="#{dir}">
<different targetdir="${todir}"/>
</fileset>
</copy>
<delete includeemptydirs="true">
<fileset dir="#todir}">
<present targetdir="${dir}" present="srconly"/>
</fileset>
</delete>
</sequential>
</macrodef>
You need to use a selector on a FileSet. Something like this:
<fileset dir="${your.working.dir}/src/main" includes="**/*.java">
<different targetdir="${clean.clearcase.checkout}/src/main"
ignoreFileTimes="false"
ignoreContents="true" />
</fileset>
That compares your working dir to a clean checkout you have elsewhere, and returns the files whose last modified times have changed. You can use the fileset as the argument for a <delete> or a <copy>.

Ant: copy the same fileset to multiple places

I need an Ant script that will copy one folder to several other places. As a good obedient programmer, I want not to repeat myself. Is there any way of taking a fileset like this:
<copy todir="${target}/path/to/target/1">
<fileset dir="${src}">
<exclude name='**/*svn' />
</fileset>
</copy>
And storing the fileset in a variable so it can be re-used?
Declare an id attribute on the fileset and then reference it in each copy task.
For example:
<project name="foo">
<fileset id="myFileSet" dir="${src}">
<exclude name='**/*svn' />
</fileset>
...
<target name="copy1">
<copy todir="${target}/path/to/target/1">
<fileset refid="myFileSet"/>
</copy>
</target>
<target name="copy2">
<copy todir="${target}/path/to/target/2">
<fileset refid="myFileSet"/>
</copy>
</target>
</project>
Rich's answer is probably better for your specific problem, but the generic way of reusing code in Ant is a <macrodef>.
<macrodef name="copythings">
<attribute name="todir"/>
<sequential>
<copy todir="#{todir}">
<fileset dir="${src}">
<exclude name='**/*svn' />
</fileset>
</copy>
</sequential>
</macrodef>
<copythings todir="/path/to/target1"/>
<copythings todir="/path/to/target2"/>
Upvoted first answer already, but you can also use a mapper to copy to multiple destinations.

Resources