Generate Checksum for directories using Ant build command

此生再无相见时 提交于 2019-12-22 09:46:58

问题


I tried to generate the checksum for directory using ant.

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:


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.


来源:https://stackoverflow.com/questions/8599216/generate-checksum-for-directories-using-ant-build-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!