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*" />
        <!-- rename 2 libs -->
        <move todir="${release.dir}" includeemptydirs="false">
            <fileset dir="${release.dir}">
              <include name="MyUtil*.jar"/>
            <mapper type="regexp" from="(MyUtil).*(.jar)"  to="MyUtil.jar"/>
        <move todir="${release.dir}" includeemptydirs="false">
            <fileset dir="${release.dir}">
              <include name="DOMHelper*.jar"/>
            <mapper type="regexp" from="(DOMHelper).*(.jar)"  to="DOMHelper.jar"/>

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.

0 Poster un commentaire

Inscrivez-vous au blog

Soyez prévenu par email des prochaines mises à jour