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.


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

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

Will yield:

     [echo] pre1

     [echo] innerpre1

     [echo] pre2

     [echo] test-before

     [echo] innerpre2

     [echo] c
     [echo] test-after


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  name="testafter">
       <echo message="test-after"/>

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

Taken from Myrmidon 

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