ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sandip Chitale <Sandip.Chit...@Sun.COM>
Subject A possible solution for conditional execution of tasks?
Date Sat, 28 May 2005 17:56:16 GMT
To conditionally execute a step in Ant one has to resort to setting up a 
target structure like this:

:
<target name="predicate">
   <condition property="condition-satisfied">
       <available .../>
   :
   </condition>
</target>

<target name="conditional-step" if="condition-satisfied">
   <!-- conditional tasks here -->
   :
   :
</target>

<target name="conditional" depends="predicate, conditional-step"/>

<target name="main" depends="conditional">
   :
   :
</target>
:

This is because of several reasons:

    * The ant tasks do not have something like *if* attribute.
    * One cannot get away with only two targets instead of three because
      the dependencies are executed before the dependent. Using the
      above example it is not possible to do what target predicate does
      in the main target and avoid using the predicate target.
    * Ensure order of execution

However, I tried a solution making use of antcall task and it worked. It 
works as follows:

:
<target name="conditional-step" if="condition-satisfied">
   <!-- conditional tasks here -->
   :
   :
</target>

<target name="main" depends="conditional-step">
:
   <condition property="condition-satisfied">
       <available .../>
   :
   </condition>
   <antcall target="condition-satisfied"/>
   :
</target>

The advantage of this approach is to quickly have some tasks execute 
conditionally by putting them in a target and calling that target using 
antcall after setting some property.

And it seemed to work. My question is - is there a problem using this 
approach? Why or why isn't this a preferred approach?

Thanks in advance,
Sandip


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message