1

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 ...

thekbb
  • 7,668
  • 1
  • 36
  • 61
Deepak_Sharma
  • 61
  • 2
  • 10
  • 1
    Ant properties are immutable. Once a property has been set (MD5_Value in your case), it can't be set to anything else. The first invocation sets MD5_Value as you see it above, and the subsequent ones don't do anything. You'll need to figure out a way to print the value or store it in a different property on each invocation. Maybe property="MD5_@{mod}"? – David Dec 03 '13 at 19:26
  • When you use the antcontrib `` loop, you may have to use either [`local`](http://ant.apache.org/manual/Tasks/local.html) task (since Ant 1.8) to localize property values in the current scope, or use the Ant-Contrib's [`var`](http://ant-contrib.sourceforge.net/tasks/tasks/variable_task.html) to allow you to redefine property values. As [Mark O'Connor](http://stackoverflow.com/a/20364160/368630) pointed out, the `` task may be exactly what you're looking for. – David W. Dec 04 '13 at 21:33

1 Answers1

3

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.

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185