2

My problem is;
When I call an antcallback function more than one, It returns the same value always. Check out the following code :

<project name="AntCallBack" default="testFnc" basedir=".">
   <taskdef resource="net/sf/antcontrib/antcontrib.properties" />

   <target name="acbFnc" description="Sub Function" >
      <echo message="[acbFnc] started"/>
      <property name="out.file" value="${in.file}"/>
      <echo message="[acbFnc] ended."/>
   </target>

   <target name="testFnc" description="Main" >

        <antcallback target="acbFnc" return="out.file" >
            <param name="in.file" value="TEST-1" />
        </antcallback>
        <echo message="CALL - 1 : out.file : ${out.file}" />

        <antcallback target="acbFnc" return="out.file" >
            <param name="in.file" value="TEST-2" />
        </antcallback>
        <echo message="CALL - 2 : out.file : ${out.file}" />

    </target>
</project>

The result is :

$ /home/apache-ant-1.9.4/bin/ant -f AntCallBackTest.xml
Buildfile: AntCallBackTest.xml

testFnc:

acbFnc:
     [echo] [acbFnc] started
     [echo] [acbFnc] ended.
     [echo] CALL - 1 : out.file : TEST-1

acbFnc:
     [echo] [acbFnc] started
     [echo] [acbFnc] ended.
     [echo] CALL - 2 : out.file : TEST-1

BUILD SUCCESSFUL
Total time: 0 seconds

As you see I sent "param name="in.file" value="TEST-1" " in first call,
And I sent "param name="in.file" value="TEST-2" " in second call,
But It always returned the first value :
[echo] CALL - 1 : out.file : TEST-1
[echo] CALL - 2 : out.file : TEST-1

What am I doing wrong?
Thanks in advance

thekbb
  • 7,668
  • 1
  • 36
  • 61
akdora
  • 893
  • 1
  • 9
  • 19
  • You're using ant like a scripting language, which it isn't. Ant doesn't have variables or functions. You're going to have a better time if you change build tools or let ant be ant and replace your target that you're using like a function with a [macro](http://ant.apache.org/manual/Tasks/macrodef.html) – thekbb May 13 '14 at 19:24
  • @thekbb thx for answer. I will consider the design with using macro. I am newbie in Ant. – akdora May 14 '14 at 14:24

1 Answers1

3

I found the solution :
I have to unset the variable before second call with :

<var name="out.file" unset="true"/>

I mean, it should be like this :

<target name="testFnc" description="Main" >

    <antcallback target="acbFnc" return="out.file" >
        <param name="in.file" value="TEST-1" />
    </antcallback>
    <echo message="CALL - 1 : out.file : ${out.file}" />

    <var name="out.file" unset="true"/>

    <antcallback target="acbFnc" return="out.file" >
        <param name="in.file" value="TEST-2" />
    </antcallback>
    <echo message="CALL - 2 : out.file : ${out.file}" />

</target>
akdora
  • 893
  • 1
  • 9
  • 19