#30 foreach ignores inheritall="false"

closed-accepted
None
5
2004-01-16
2003-05-09
Anonymous
No

The following ant script doesn't work like I would expect:

<?xml version="1.0" encoding="UTF-8"?>

<project name="test" basedir="." default="print">

<property name="test1" value="one"/>
<property name="test2" value="two"/>
<property name="test3" value="three"/>
<property name="alphalist" value="a,b,c"/>

<target name="-loadexttasks">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
</target>

<target name="-print">
<echo message="test1=${test1}"/>
<echo message="test2=${test2}"/>
<echo message="test3=${test3}"/>
<echo message="${line}"/>
</target>

<target name="-printall">
<foreach list="${alphalist}"
target="-print"
param="line"
inheritall="false"
inheritrefs="false"/>
</target>

<target name="print" depends="-loadexttasks,-printall"/>

</project>

results in the following output:

-loadexttasks:

-printall:

-print:
[echo] test1=one
[echo] test2=two
[echo] test3=three
[echo] a

-print:
[echo] test1=one
[echo] test2=two
[echo] test3=three
[echo] b

-print:
[echo] test1=one
[echo] test2=two
[echo] test3=three
[echo] c

Since inheritall="false" I would expect that test1, test2 and test3
should not be printed with the correct values.

I only care because I have a big build.xml file with a lot of properties
and I don't want to pass all of them to the target that <foreach> calls
every time (slows things down). I want to control which properties
are passed to the target with <param> nested elements.

I'm running ant-contrib-0.3 with Ant 1.5.3

From the attached debug output you its apparent that all project
properties are passed in via the antcall/ant sequence:

-printall:
+Task: foreach
+Task: antcall
+Task: ant
+User task: propertyfile

<snip>

Setting ro project property: ant.file -> /home/hildenl/cv/test.xml
Setting ro project property: ant.project.name -> test
Setting ro project property: ant.version -> Apache Ant version 1.5.3
compiled on April 22 2003
Setting ro project property: line -> a
[antcall] calling target -print in build file /home/hildenl/cv/test.xml
Setting ro project property: ant.file -> /home/hildenl/cv/test.xml
parsing buildfile /home/hildenl/cv/test.xml with URI =
file:/home/hildenl/cv/test.xml
Setting ro project property: ant.project.name -> test
Adding reference: test -> org.apache.tools.ant.Project@5369d8b5
Project base dir set to: /home/hildenl/cv
+Task: property
Setting project property: test1 -> one
+Task: property
Setting project property: test2 -> two
+Task: property
Setting project property: test3 -> three
+Task: property
Setting project property: alphalist -> a,b,c
+Target: -loadexttasks
+Task: taskdef
+Target: -print
+Task: echo
+Task: echo
+Task: echo
+Task: echo
+Target: -printall
+Task: foreach
+Target: print
Build sequence for target `-print' is [-print]
Complete build sequence is [-print, -printall, -loadexttasks, print]

-print:
[echo] test1=one
[echo] test2=two
[echo] test3=three
[echo] a

Discussion

  • Nobody/Anonymous

    debug log

     
  • Matt Inger

    Matt Inger - 2004-01-15
    • assigned_to: nobody --> mattinger
     
  • Matt Inger

    Matt Inger - 2004-01-16
    • status: open --> closed-accepted
     
  • Matt Inger

    Matt Inger - 2004-01-16

    Logged In: YES
    user_id=83032

    as of this point in time, inheritall is working correctly, as
    verified by the following test case:
    <target name="do.echo">
    <echo
    message="inherited.property=${inherited.property}" />
    </target>

    <target name="my.test">
    <property name="inherited.property" value="abc" />
    <foreach list="1" target="do.echo" inheritall="true"
    param="val" />

    </target>

    This outputs:
    inherited.property=abc

    If the inheritall flag is changed to false, it outputs:

    inherited.property=${inherited.property}

     

Log in to post a comment.