2

我目前正在尝试在 ANT 中使用长度任务,更具体地说是制作条件长度​​任务。

如果文件大于设定的长度,我想将消息标记到当前存在的文件,如下所示:

<project name="ant" default="check-filesize">
<target name="check-filesize">
    <length mode="all" property="fs.length.bytes" when="gt" length="100">
    <fileset dir="size" includes="*"/>
    </length>
    <echo>sorry your file set is to large</echo>
</target>
</project>

我已经编写了代码来打印目录中所有文件的大小,但我没有将其包含在此处以保持简短。

如果长度不允许回显标签,我可以用另一种方式执行此操作吗?如果没有人知道 when 标签的作用?显然,我只希望在违反条件时发生回声

提前谢谢了

4

2 回答 2

2

我发现了一种不使用外部库的方法,但感谢您的帮助。这里是如何:

<project name="ant" default="check-filesize">
<target name="check-filesize">
  <fail message="Your File Exceeds Limitations Please Operator For Full Size Of Data Set>
    <condition>
      <length length="1000" when="gt" mode="all" property="fs.length.bytes">
         <fileset dir="size" includes="*"/>
      </length>
    </condition>
   </fail>
 </target>
 </project>
于 2013-04-24T07:50:36.800 回答
0

这是一种使用 Ant 的内置任务有条件地回显语句的方法:

<project name="ant-length" default="check-filesize">
    <target name="check-filesize" depends="get-length, echo-if-large"/>

    <target name="get-length">
        <condition property="fs.length.too.large">
            <length mode="all" when="gt" length="100">
                <fileset dir="size" includes="*"/>
            </length>
        </condition>
    </target>

    <target name="echo-if-large" if="fs.length.too.large">
        <echo>sorry your file set is too large</echo>
    </target>
</project>

第三方Ant-Contrib 库有一项<if>任务可以简化这一点。

于 2013-04-22T14:51:30.383 回答