-1

I am calling one target(targetCalled) from some other target(targetCaller), as follows:

<target depends="local.init" 
   description="creating application jar file of the classes dir"
    name="run_check_server_client_jar_gen">

    <antcall target="run_check_server_client_jar_callExec"/>
    <if>
        <isset property="result"/>
        <then>
             <echo>Result: ${result}</echo>
        </then>
        <else>
            <echo>Propert result is not set yet !! </echo>
        </else>
    </if>
</target>

Now I call one exec from targetCalled as follows:

<target depends="local.init" 
    description="Running check for all classes in 
            client jar should also be present in server jar"
            name="run_check_server_client_jar_callExec">
    <exec executable="/bin/bash" resultproperty="${result}" failonerror="false">
        <arg value="count_client_server_inner_classes.sh"/>
        <arg value="gjf1common_client_classes.jar"/>
        <arg value="gjf1common_classes.jar"/>
    </exec>
    <if>
        <isset property="result"/>
        <then>
            <echo>Inside::Result: ${result}</echo>
        </then>
        <else>
            <echo>Inside::Property result is not set yet !!!! </echo>
        </else>
    </if>
</target>

In my count_client_server_inner_classes.sh, i am exiting the status as: exit "$result" it is giving me ": numeric argument required"

i want that executable should return me a string, is that possible ??

I want to use this returned value in my targetCalled and targetCaller. but when i am echoing the result property.. it is giving me 255. Can anybody points out where i am going wrong ?

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
Mayur Sharma
  • 65
  • 2
  • 5
  • 17

1 Answers1

0

Ant isn't a scripting language. It's not a very good way to describe a build - but it's an awful scripting language. Trying to script in ant with pseudo-function calls and if/else like this is going to suck. In generally, stay away from if/else - if you find you need them you likely want to reevaluate your tool choice. Avoid antcall at all costs - it spins up a new jvm and makes for some crazy spaghetti - use depends to control the execution flow between targets.

To answer one of your question - the result property is always going to be the exit code, in the case of bash it's always goign to be an int 0-255.

The interesting part is in the bash script... post that. It's returning 255, which is a special code - means it's out of range. I suspect you're having it return a string?

You could simplify the whole mess by simply failing on error:

<target name="run-check-server-client-jar-gen" depends="local-init" 
   description="creating application jar file of the classes dir"> 
    <exec executable="/bin/bash" failonerror="true">
        <arg value="count_client_server_inner_classes.sh"/>
        <arg value="gjf1common_client_classes.jar"/>
        <arg value="gjf1common_classes.jar"/>
    </exec>     
</target>

If you really must give custom error status you can set the result property as you where and then you could:

<target name="run-check-server-client-jar-gen" depends="local-init" 
   description="creating application jar file of the classes dir"> 
    <exec executable="/bin/bash" resultproperty="${return.code}">
        <arg value="count_client_server_inner_classes.sh"/>
        <arg value="gjf1common_client_classes.jar"/>
        <arg value="gjf1common_classes.jar"/>
    </exec>     
    <fail message="crazy shell script madness terminated abnormally.">
        <condition>
            <isfailure code="${return.code}"/>
        </condition>
    </fail>
</target>

I admit I didn't actually run the snippets above, you may have to massage a bit, but I'm pretty sure they'll go. another editorial note on style: targets generally use - rather than _ or . to delimit word, where properties use .

thekbb
  • 7,668
  • 1
  • 36
  • 61