Bug 12292

Summary: [PATCH] enable <depends target=""/> tag inside targets
Product: Ant Reporter: Nicola Ken Barozzi <nicolaken>
Component: CoreAssignee: Ant Notifications List <notifications>
Status: NEW ---    
Severity: enhancement Keywords: PatchAvailable
Priority: P3    
Version: 1.7.0   
Target Milestone: ---   
Hardware: Other   
OS: other   
Attachments: depends.zip; contains the files that were changed and a new Depends.java class

Description Nicola Ken Barozzi 2002-09-04 11:46:45 UTC
It enables to use  <depends target=""/> tag inside targets, not only in the
depends attribute.

Example:

<?xml version="1.0"?>
<project default="test" basedir="." name="test">
    	
    <target  name="pre1">
       <echo message="pre1"/>
    </target>

    <target  name="pre2">
       <echo message="pre2"/>
    </target>
    
    <target  name="test" depends="pre1,innerpre1,test2">
    </target>
    
    <target  name="test2" depends="pre1,pre2">
       <echo message="test-before"/>
       <depends target="c"/>
<!--   <depends target="test"/>  -->
       <echo message="test-after"/>
    </target>
        
    <target  name="c" depends="innerpre1,innerpre2">
       <echo message="c"/>
    </target>
    
    <target  name="innerpre1">
       <echo message="innerpre1"/>
    </target>
    
    <target  name="innerpre2">
       <echo message="innerpre2"/>
    </target>
    
</project>

Will yield:

pre1:
     [echo] pre1

innerpre1:
     [echo] innerpre1

pre2:
     [echo] pre2

test2:
     [echo] test-before

innerpre2:
     [echo] innerpre2

c:
     [echo] c
     [echo] test-after

test:

BUILD SUCCESSFUL
Total time: 1 second

@todo check the if-unless-etc stuff.
Comment 1 Nicola Ken Barozzi 2002-09-04 11:57:36 UTC
Created attachment 2913 [details]
depends.zip; contains the files that were changed and a new Depends.java class
Comment 2 Conor MacNeill 2003-01-29 13:46:30 UTC
What is the use case? I'm not sure why this would be a good thing. It would seem
to make the dependency graph no longer obvious. In the example shown, the output
of "test-after" is misleadingly asssociated with the "c" target.
Comment 3 Nicola Ken Barozzi 2003-01-29 14:16:54 UTC
The use case is that of syntax sugar.

Instead of using it, one could simply split the target in many pieces and add
dependencies on those, but this many times makes the build really hard to read
and maintain.

In this case it's simple:

    <target  name="test2" depends="pre1, pre2, c, testafter">
       <echo message="test-before"/>
    </target>

    <target  name="testafter">
       <echo message="test-after"/>
    </target>

So users use <antcall> for it, with the associated new-project overhead etc.

Taken from Myrmidon 
http://ant.apache.org/myrmidon/differences.html

" As well as the depends attribute of the Target there is a new <depends> task
that allows you to evaluate dependencies inside a target just like executing a
normal task. This change was made as previously users have tried to achieve this
behaviour by using antcall. However you had to add if attributes to the common
targets to make sure that they were not evaluated multiple times. This was
difficult and error prone. Building it into the tool helps directly supports
this usecase."

As for the misleading target association, it's a bug 8-)