Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing properties defined inside antcall target back to calling target

Tags:

ant

I'm rather new to Ant but I have experienced it's quite good pattern to create generic ant targets which are to be called with antcall task with varying parameters.

My example is compile target, which compiles multiple systems using complex build command which is a bit different for each system. By using pattern described above it's possible not to create copy paste code for that compile command.

My problem here is, that I'm not aware of any way to pass return value (for example the return value of compiler) back to target which called the antcall task. So is my approach pathological and it's simply not possible to return value from antcall task or do you know any workaround?

Thanks,

like image 437
hhamalai Avatar asked Jan 13 '11 13:01

hhamalai


People also ask

What is Antcall target?

When a target is invoked by antcall , all of its dependent targets will also be called within the context of any new parameters. For example. if the target doSomethingElse ; depended on the target init , then the antcall of doSomethingElse will call init during the call.

What is an ant task?

Ant tasks are the units of your Ant build script that actually execute the build operations for your project. Ant tasks are usually embedded inside Ant targets. Thus, when you tell Ant to run a specific target it runs all Ant tasks nested inside that target.


1 Answers

Use antcallback from the ant-contrib jar instead of antcall

<target name="testCallback">
    <antcallback target="capitalize2" return="myKey">
    </antcallback>
    <echo>a = ${myKey}</echo>
</target>

<target name="capitalize2">
    <property name="myKey" value="it works"/> 
</target>

Output:

testCallback:

capitalize2:
     [echo] a = it works

BUILD SUCCESSFUL
like image 135
JoseK Avatar answered Sep 18 '22 13:09

JoseK