#131 Incorrect var values on runTarget

closed-invalid
nobody
logic (23)
5
2006-08-16
2005-03-22
Mike Slason
No

When a target is invoked using "runtarget" for a second
time, variables are given the values that they had on
the first runtarget invocation, even if the value was
unset or changed in the meantime.

Here is example code:

<target name="testProj1"
depends="testinit,testProj2" description="testProj1">
<echo message="1.1: testvar = ${testvar}"/>
<var name="testvar" value="var_testProj1"/>
<echo message="1.2: testvar = ${testvar}"/>
<runtarget target="-testcheck"/>
<echo message="1.3: testvar = ${testvar}"/>
</target>
<target name="testProj2" depends="testinit"
description="testProj2">
<echo message="2.1: testvar = ${testvar}"/>
<var name="testvar" value="var_testProj2"/>
<echo message="2.2: testvar = ${testvar}"/>
<runtarget target="-testcheck"/>
<echo message="2.3: testvar = ${testvar}"/>
</target>
<target name="testinit" depends="">
<property file="${build_props}"/>
<taskdef
resource="net/sf/antcontrib/antcontrib.properties"
classpath="${builder_dir}/lib/ant-contrib-1.0b1.jar"/>
</target>

<target name="-testcheck">
<echo message="c1: testvar = ${testvar}"/>
<var name="testvar" unset="true"/>
<echo message="c2: testvar = ${testvar}"/>
</target>

This example produces:

testinit:
testProj2:
2.1: testvar = ${testvar}
2.2: testvar = var_testProj2
-testcheck:
c1: testvar = var_testProj2
c2: testvar = ${testvar}
2.3: testvar = ${testvar}
testProj1:
1.1: testvar = ${testvar}
1.2: testvar = var_testProj1
-testcheck:
c1: testvar = var_testProj2
c2: testvar = ${testvar}
1.3: testvar = ${testvar}
BUILD SUCCESSFUL (total time: 0 seconds)

Discussion

  • Nobody/Anonymous

    Logged In: NO

    This is an unfortunate side effect of runtarget that we cannot
    really overcome right now. RunTarget directly
    calls "executeTarget" on the project. As a result, any
    properties set on in the called target are present when
    the "runtarget" task returns.

    We'll be able to fix this in Ant 1.7, but until then, there's
    really no way to restore the properties as they were before
    the execution of runtarget.

     
  • Matt Inger

    Matt Inger - 2006-08-16
    • status: open --> closed-invalid
     
  • Matt Inger

    Matt Inger - 2006-08-16

    Logged In: YES
    user_id=83032

    this is the expected behavior of the runTarget task. It
    executes the called target in the same project space. In
    order to execute in it's own project space, just use antcall
    instead. This is the only difference between the two.

    I'm closing this as invalid.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks