ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thirumala.Th...@fairchildsemi.com
Subject RE: Error Handling
Date Wed, 19 May 2004 19:52:35 GMT
Hi Doug/All,

This helped me lot. I coded my job exactly similar way and is working 
fine.

I have one more problem, i.e in my requirement I have to send an email 
with the console log message to everyone saying that build is where 
successful or failed. 

So as per the below email pls. map my targets as follows:

normalTarget    = build_dev
failTarget            = sendFailEmail
successTarget = sendSuccessEmail

In "build_dev" target I am generating log file and I am attaching that 
file in the "send*Email" targets. So,if the build is success it is 
attaching the full log file fine, but when build is failed it is able 
attach the log file only with the content before it got failed, that means 
it is not captuing [trycatch] block error message in the log file. How 
could we solve this problem? My major requirement to send the mail is to 
see the error message where does it failed/what is the problem.

Pls. advice if there is any better way to handle this problem... I would 
appreciate your earliest response.

Regards,
Thiru





"Daniels, Doug" <Doug.Daniels@gdc4s.com>
05/19/2004 10:01 AM

 
        To:     Thirumala Thoka/Corporate/FSC@Fairchild, user@ant.apache.org
        cc: 
        Subject:        RE: Error Handling


You can use the ant-contrib (http://ant-contrib.sourceforge.net/) <trycatch> task (http://ant-contrib.sourceforge.net/tasks/trycatch.html),
"Trytask is a wrapper that lets you run a set of tasks and optionally 
run a different set of tasks if the first set fails and yet another set 
after the first one has finished."

For example:

<target name="taskFailCheck">
<trycatch property="taskFailed" reference="errorRef">
  <try>
    <antcall target="normalTarget" />
  </try>

  <catch>
    <echo>Error caught: ${errorRef}</echo>
  </catch>

  <finally>
    <echo>Check if we failed and perform task otherwise perform other 
task.</echo>

    <if> <isset property="taskFailed" /> <then>
 
       <antcall target="failTarget" />

    </then>

<!-- otherwise perform succesful task -->
    <else>

       <antcall target="successTarget" />

    </else>
    </if>

  </finally>
</trycatch>
</target>

You just replace the normalTarget, failTarget, and successTarget with your 
targets, you could also just check the taskFailed property in the other 
targets themselves, for example:

<target name="successTarget" unless="taskFailed">

or

<target name="failedTarget" if="taskFailed">

then you'd have a target setup like this to setup the order:

<target name="masterTarget" depends="taskFailCheck, successTarget, 
failedTarget"/>

This task would run your trycatch then it would run either the 
successTarget or the failedTarget depending on the success and failure of 
the normalTarget target.


To use ant-contrib tasks. First Download the ant-contrib tasks jar and 
then at the top of your build file you must declare the ant-contrib tasks:
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
  <classpath>
    <pathelement location="/usr/share/java/lib/ant-contrib-0.3.jar"/>
  </classpath>
</taskdef>



-----Original Message-----
From: Thirumala.Thoka@fairchildsemi.com
[mailto:Thirumala.Thoka@fairchildsemi.com]
Sent: Monday, May 17, 2004 4:58 PM
To: dev@ant.apache.org
Subject: Error Handling


Hi All,

How do we capture the error on ANT target, if it does success do one thing 

otherwise do other thing. So, basically how do we code this requirement.

I did little bit of try with "failureonerror", "haltonerror" attributes 
but it's not accepting those attributes at all.
I would appreciate your ealiest response. Pls. do ask me if you need more 
details about the question.

Regards,
Thiru




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