How to make a property in Ant as mutable

2019-04-14 16:14发布

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

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 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
1条回答
神经病院院长
2楼-- · 2019-04-14 16:56

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

Quote from the docs: In general, use of this task is DISCOURAGED, and the standard Ant Property should be used if possible. Having said that, in real life I use this a lot.

which says a lot, too ;-)

查看更多
登录 后发表回答