My opinion regarding the disadvantages of this approach: * Antcall has to create a whole new Project in memory in order to work and is therefore an inefficient task * If something invoked via Antcall depends on a target that is also depended on by something depending on the target invoking Antcall then this dependency target will be executed more than once because dependencies are not handled across Antcall invocations * The dependency tree is "interrupted" and graphing tools that can show ant build script structures will not (generally) work correctly and show the whole dependency tree
It might be better to add "if" and "unless" to the standard ant Task to allow for conditional execution, or even add a nested "condition" to the standard ant Task to allow for conditional execution. To provide BC with the standard "execute" method, the condition/if/unless processing would need to happen outside this method. Phil :n. -----Original Message----- From: Sandip Chitale [mailto:[EMAIL PROTECTED] Sent: Sat 28/05/2005 18:56 To: dev@ant.apache.org Cc: Subject: A possible solution for conditional execution of tasks? 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