ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jan.Mate...@rzf.fin-nrw.de
Subject RE: Return codes from custom Ant tasks.
Date Wed, 03 Dec 2003 07:41:11 GMT
There is no standard way for returning values from tasks.
Therefore the usual way is via properties. 
    <mytask resultproperty="propname"/>
Then you set the property inside your execute method.
    public void execute() {
        // ...
        getProject().setNewProperty(resultproperty, "the-value");
    }
But properties are immutable ... so multiple calls would have some
problems:

    <mytask resultproperty="result"/>
    <echo>result should be 1: ${result}</echo>
    <mytask resultproperty="result"/>
    <echo>result should be 2: ${result}</echo>   <!-- will be 1 -->

Workaround at the moment is using <antcall>. That will create a 
new property-namespace, but
- it costs time
- the result is NOT transfered to the callee


This problem raises if you use <macrodef> (Ant 1.6). So on the dev list
there is a hot discussion on introducing <local> for local properties.
But no final decision yet.



Jan



> -----Original Message-----
> From: Cyril Sagan [mailto:Cyril.Sagan@sas.com]
> Sent: Wednesday, December 03, 2003 2:42 AM
> To: user@ant.apache.org
> Subject: Return codes from custom Ant tasks.
> 
> 
> I'm hoping to get status information returned from a custom 
> Ant task.  Given that Task.execute()'s return type is void, 
> I'm thinking the only recourse I have is to set a property to 
> "pass status" back to the caller.
> 
> Seems like there has got to be a better way, any suggestion/ideas?
> 
> I couldn't find any mention of this in the FAQ.
> 
> Thanks.
> 
> --Cyril Sagan
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message