Generating MD5 for files in an ant-contrib for loop in ANT

1.2k views Asked by At

I am selecting set of files using file set and then using them to generate the checksum of all the files in the selected fileset

here is my script

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="MyTask1" basedir="." default="jar">
    <property name="cms.dir" value="D:\Test" />
    <property name="comma" value="," />
    <taskdef resource="net/sf/antcontrib/antlib.xml"/>
    <target name="A">
        <fileset id="src.files" dir="${cms.dir}" casesensitive="yes">
            <include name="**/*.uim"/>
            <include name="**/*.properties"/>
            <include name="**/*.txt"/>
        </fileset>
        <pathconvert pathsep="${line.separator}" property="sounds" refid="src.files">
            <!-- To get the names of the files only then use mapper-->
            <!--    <mapper type="flatten" />-->
        </pathconvert>
        <delete file="sounds.txt"/>
        <for list="${sounds}" delimiter="${line.separator}" param="mod">
            <sequential>
                <checksum file="@{mod}" property="MD5_Value"/>
                <echo file="sounds.txt"    append="true">@{mod}${comma}${MD5_Value}${line.separator}</echo>             
            </sequential>
        </for>
        <!--<checksum file="Test.txt" property="foobarMD5"/>-->
        <!--<echo file="sounds.txt">${foobarMD5}</echo>-->
    </target>
</project>

However its failing and its generating duplicate MD5 value here is my output

D:\Test\Test1.txt,6d326741a99efbcda928e5096b43cb9a D:\Test\Test2.txt,6d326741a99efbcda928e5096b43cb9a

Any help ...

1

There are 1 answers

0
Mark O'Connor On

The checksum task can process filesets...

<checksum>
  <fileset dir=".">
    <include name="foo*"/>
  </fileset>
</checksum>

Lot simpler than using the for task, which is not part of standard ANT.