使用 Ant 构建命令为目录生成校验和 [英] Generate Checksum for directories using Ant build command

查看:30
本文介绍了使用 Ant 构建命令为目录生成校验和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试为目录生成使用 .

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>

我只想使用 Ant 命令为特定目录生成一个 checksum.我该怎么做?

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

推荐答案

您想使用 totalproperty 属性.根据文档,此属性将保存所有校验和的校验和和文件路径.

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

例如

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

  • 这不是幂等的.每次运行它都会得到一个新值,因为它在新哈希中包含了先前的哈希文件(然后写入了一个新的哈希文件).我建议您将 todir 属性更改为指向其他地方
  • 有意义地命名目标是个好主意.请参阅 Martin Fowler 撰写的这篇精彩文章,了解一些命名思路
  • 如果没有依赖项,则不需要 depends 属性.
  • 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.

这篇关于使用 Ant 构建命令为目录生成校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆