ANT - Rename files
Today, I would like to present a simple way to rename a specific file with ANT. Let's say we delete and re-create a release directory. We copy in it files, one or several of these have to be renamed. A goog solution is to make use of the move tag of ant:
<property name="release.dir" value="release" />
<!-- Target RELEASE -->
<target name="release" depends="jar">
<delete dir="${release.dir}" />
<mkdir dir="${release.dir}" />
<!-- build a release folder -->
<copy todir="${release.dir}" overwrite="true" >
<fileset dir="libs" excludes="junit*"/>
<fileset dir="${basedir}" includes="*.properties"/>
<fileset dir="docs" includes="Integration*" />
</copy>
<!-- rename 2 libs -->
<move todir="${release.dir}" includeemptydirs="false">
<fileset dir="${release.dir}">
<include name="MyUtil*.jar"/>
</fileset>
<mapper type="regexp" from="(MyUtil).*(.jar)" to="MyUtil.jar"/>
</move>
<move todir="${release.dir}" includeemptydirs="false">
<fileset dir="${release.dir}">
<include name="DOMHelper*.jar"/>
</fileset>
<mapper type="regexp" from="(DOMHelper).*(.jar)" to="DOMHelper.jar"/>
</move>
</target>
A good reason for that: I generate an archive with the name Name<Date>-b<BuildNumber>_<version>.jar. For example, I obtain the archive named: myJar20100305-b117_1.13.jar. Yet, I have to deliver that archive. I can't assume to update all the scripts that make use of this archive, only because its release and date numbers have changed. I don't have to. So I want to always release an archive with the name myJar.jar. That jar could contain a simple file with its revision_number so that I can verify at any moment the current version.
In that case, the Jar could propose in its help a --version option that reads that current release number. It seems that this approach is largely employed since years.
<property name="release.dir" value="release" />
<!-- Target RELEASE -->
<target name="release" depends="jar">
<delete dir="${release.dir}" />
<mkdir dir="${release.dir}" />
<!-- build a release folder -->
<copy todir="${release.dir}" overwrite="true" >
<fileset dir="libs" excludes="junit*"/>
<fileset dir="${basedir}" includes="*.properties"/>
<fileset dir="docs" includes="Integration*" />
</copy>
<!-- rename 2 libs -->
<move todir="${release.dir}" includeemptydirs="false">
<fileset dir="${release.dir}">
<include name="MyUtil*.jar"/>
</fileset>
<mapper type="regexp" from="(MyUtil).*(.jar)" to="MyUtil.jar"/>
</move>
<move todir="${release.dir}" includeemptydirs="false">
<fileset dir="${release.dir}">
<include name="DOMHelper*.jar"/>
</fileset>
<mapper type="regexp" from="(DOMHelper).*(.jar)" to="DOMHelper.jar"/>
</move>
</target>
A good reason for that: I generate an archive with the name Name<Date>-b<BuildNumber>_<version>.jar. For example, I obtain the archive named: myJar20100305-b117_1.13.jar. Yet, I have to deliver that archive. I can't assume to update all the scripts that make use of this archive, only because its release and date numbers have changed. I don't have to. So I want to always release an archive with the name myJar.jar. That jar could contain a simple file with its revision_number so that I can verify at any moment the current version.
In that case, the Jar could propose in its help a --version option that reads that current release number. It seems that this approach is largely employed since years.
Retour aux articles de la catégorie Computer sciences -