如何使 Ant 中的属性可变 [英] How to make a property in Ant as mutable

查看:29
本文介绍了如何使 Ant 中的属性可变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用蚂蚁条件任务来检查文件是否存在和目录是否存在,下面是我的代码

I'm using ant condition task to check a file existence and directory existence and below is my code

<project name="makeitmutable" basedir="." default="main">
  <target name="main">
     <condition property="folderexists?" value="Yeah" else="Nope">
       <and>
          <available file="folderexistance" type="dir"/>
          <available file="a.zip" type="file"/>
      </and>
     </condition>
     <echo>before deleting "folderexistance" folder  property folderexists?=${folderexists?}</echo>
     <delete dir="folderexistance"/>
     <!--after delete-->
      <condition property="folderexists?" value="Yeah" else="Nope">
       <and>
          <available file="folderexistance" type="dir"/>
          <available file="a.zip" type="file"/>
      </and>
     </condition>
     <!--how to make below line to print Nope ?-->
   <echo>After deleting "folderexistance" folder  property folderexists?=${folderexists?}</echo>
  </target>
</project>

我的属性文件夹的输出值是否存在?即使删除目录后仍然保持不变,即两次没有

My output value of the property folderexists? remains same even after deleting the directory,i.e.., Nope two times

我知道 ant 属性一旦设置就无法更改,并且该解决方案的替代方案是我们可以使用

I knew that ant properties are immutable once set cannot be changed,and also an alternative to this solution is we can use

<antcall>

task 并调用主目标.

task and call the main target.

有没有办法使该目标内的属性像上述情况一样可变,我正在寻找其他可能性来解决这个问题,对于此类问题,更好的编程实践是什么.

Is there a way to make the property mutable within that target as in the above scenario,I'm looking for other possibilities to resolve this, what's the better programming practice for this type of problem.

推荐答案

正如您所说,属性是不可变的.唯一的其他选择是使用来自 ant 的 var 任务- 贡献.

As you said, properties are immutable. The only other option is to use the var task from ant-contrib.

引自文档:一般情况下,不鼓励使用此任务,如果可能,应使用标准的 Ant 属性. 话虽如此,在现实生活中我使用这个很多.

这也说了很多;-)

这篇关于如何使 Ant 中的属性可变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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