How to make a property in Ant as mutable

坚强是说给别人听的谎言 提交于 2019-12-21 22:10:22

问题


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.


回答1:


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 ;-)



来源:https://stackoverflow.com/questions/8789756/how-to-make-a-property-in-ant-as-mutable

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