Generate Checksum for directories using Ant build

2019-05-14 14:59发布

I tried to generate the for directory using .

I have tried the below command, but it generates recursively inside each folder for each file.

<target name="default" depends="">
    <echo message="Generating Checksum for each environment" />
    <checksum todir="${target.output.dir}" format="MD5SUM" >
        <fileset dir="${target.output.dir}" />
    </checksum>
</target>

I just want to generate one checksum for particular directory using Ant command. How do I do that?

1条回答
霸刀☆藐视天下
2楼-- · 2019-05-14 15:26

You want to use the totalproperty attribute. As per the documentation this property will hold a checksum of all the checksums and file paths.

e.g.

<target name="hash">
  <checksum todir="x" format="MD5SUM" totalproperty="sum.of.all">
    <fileset dir="x"/>
  </checksum>
  <echo>${sum.of.all}</echo>
</target>

Some other general notes.

  • This is not idempotent. Each time you run it you will get a new value because it includes the previous hash file in the new hash (and then writes a new hash file). I suggest that you change the todir attribute to point elsewhere
  • It's a good idea to name your targets meaningfully. See this great article by Martin Fowler for some naming ideas
  • You don't need the depends attribute if there's no dependency.
查看更多
登录 后发表回答