You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Jan Schroeder <ja...@gmx.net> on 2003/10/03 16:38:27 UTC

failonerror; general solution

There are a few new entries in bugzilla regarding handling of 
BuildExceptions.
    http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23540
    http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23581

Also, some tasks already implement some "failonerror" attribute (e.g. 
<java>).

What about creating a container task instead.
Like:

<nofail failureproperty="part.failed">
    <patch .../>
    <echo ../>
    <antcall />
</nofail>

That way all tasks automatically have something like "failonerror" + you 
actually know if the part failed and can take an appropriate build path 
from here on.


Jan


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: failonerror; general solution

Posted by Dale Anson <da...@smartpennies.com>.
Hi Peter,

Yes, I can do that. I just read through the antlib docs after I saw your 
message (I hadn't really looked at them before), that's some nice stuff!

Dale


peter reilly wrote:
> On Friday 03 October 2003 16:34, Dale Anson wrote:
> 
>>FYI, I'll be posting a new antelope distribution to sourceforge this
>>weekend that has been updated for Ant 1.6.
>>
>>Dale
> 
> 
> Hi, Dale,
> 
> Would you be able to put in an antlib descriptor
> in the new antelope distribution.
> 
> make a file called antlib.xml in the
> same directory as antelope.tasks (ise/antelope/tasks) 
> containing:
> <antlib>
>   <taskdef name="antcallback" classname="ise.antelope.tasks.AntCallBack"/>
>   <taskdef name="antfetch" classname="ise.antelope.tasks.AntFetch"/>
>   <taskdef name="assert" classname="ise.antelope.tasks.Assert"/>
> ... etc
> </antlib>
> 
> Doing this means that if the antelope jar is in the core classpath
> (in ${ant.home}/lib for example) one can use the namespace
> short-cut to load them;
> 
> <project xmlns:antelope="antlib:ise.antelope.tasks">
>   <antelope:try messageproperty="failed">
>     <fail>This should fail</fail>
>     <echo>This will not be reached</echo>
>     <antelope:catch>
>       <echo>failed is ${failed}</echo>
>     </antelope:catch>
>   </antelope:try>
> </project>
>  
> Peter
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: failonerror; general solution

Posted by peter reilly <pe...@corvil.com>.
On Friday 03 October 2003 16:34, Dale Anson wrote:
>
> FYI, I'll be posting a new antelope distribution to sourceforge this
> weekend that has been updated for Ant 1.6.
>
> Dale

Hi, Dale,

Would you be able to put in an antlib descriptor
in the new antelope distribution.

make a file called antlib.xml in the
same directory as antelope.tasks (ise/antelope/tasks) 
containing:
<antlib>
  <taskdef name="antcallback" classname="ise.antelope.tasks.AntCallBack"/>
  <taskdef name="antfetch" classname="ise.antelope.tasks.AntFetch"/>
  <taskdef name="assert" classname="ise.antelope.tasks.Assert"/>
... etc
</antlib>

Doing this means that if the antelope jar is in the core classpath
(in ${ant.home}/lib for example) one can use the namespace
short-cut to load them;

<project xmlns:antelope="antlib:ise.antelope.tasks">
  <antelope:try messageproperty="failed">
    <fail>This should fail</fail>
    <echo>This will not be reached</echo>
    <antelope:catch>
      <echo>failed is ${failed}</echo>
    </antelope:catch>
  </antelope:try>
</project>
 
Peter

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: failonerror; general solution

Posted by Steve Loughran <st...@iseran.com>.
Dale Anson wrote:
> What's the difference in use case between this and the try/catch from 
> ant-contrib or antelope? I'd suggest grabbing the try/catch from either, 
> and making it a core task. Just judging from the e-mail that I get, the 
> try/catch task in antelope is one of the main reasons people download it.

I am +1 to trycatch, because it gives you better failure modes than just 
'ignore'; like the option to rollback or warn.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: failonerror; general solution

Posted by Dale Anson <da...@germane-software.com>.
What's the difference in use case between this and the try/catch from 
ant-contrib or antelope? I'd suggest grabbing the try/catch from either, 
and making it a core task. Just judging from the e-mail that I get, the 
try/catch task in antelope is one of the main reasons people download it.

Contrast this usage with Peter's example:
<project>
   <mkdir dir="classes"/>
   <javac srcdir="src" destdir="classes"/>
   <taskdef name="try" classname="...whatever"/>

   <target name="test">
     <try messageproperty="failed">
       <fail>This should fail</fail>
       <echo>This will not be reached</echo>
       <catch>
          <echo>failed is ${failed}</echo>
       </catch>
     </try>
   </target>
</project>

FYI, I'll be posting a new antelope distribution to sourceforge this 
weekend that has been updated for Ant 1.6.

Dale


peter reilly wrote:
> Here is a task that does some like that:
> 
> package task;
> 
> import org.apache.tools.ant.taskdefs.Sequential;
> 
> 
> public class NoFail extends Sequential {
>     private String failureProperty;
>     public void setFailureProperty(String name) {
>         this.failureProperty = name;
>     }
>     public void execute() {
>         try {
>             super.execute();
>         } catch (Throwable t) {
>             if (failureProperty != null) {
>                 getProject().setNewProperty(
>                     failureProperty, "true");
>             }
>         }
>     }
> }
> 
> Usage:
> <project>
>   <mkdir dir="classes"/>
>   <javac srcdir="src" destdir="classes"/>
>   <taskdef name="nofail" classname="task.NoFail"
>            classpath="classes"/>
> 
>   <target name="test">
>     <nofail failureproperty="failed">
>       <fail>This should fail</fail>
>       <echo>This will not be reached</echo>
>     </nofail>
>     <echo>failed is ${failed}</echo>
>   </target>
> </project>
> 
> 
> Peter
> 
> On Friday 03 October 2003 15:43, Emmanuel Feller wrote:
> 
>>I agree, it is a good option in my mind.
>>
>>+1 :)
>>
>>Emmanuel
>>----- Message d'origine -----
>>De : "Jan Schroeder" <ja...@gmx.net>
>>�: <de...@ant.apache.org>
>>Envoy�: vendredi 3 octobre 2003 16:38
>>Objet : failonerror; general solution
>>
>>
>>>There are a few new entries in bugzilla regarding handling
>>
>>of
>>
>>
>>>BuildExceptions.
>>
>>http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23540
>>
>>http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23581
>>
>>
>>>Also, some tasks already implement some "failonerror"
>>
>>attribute (e.g.
>>
>>
>>><java>).
>>>
>>>What about creating a container task instead.
>>>Like:
>>>
>>><nofail failureproperty="part.failed">
>>>    <patch .../>
>>>    <echo ../>
>>>    <antcall />
>>></nofail>
>>>
>>>That way all tasks automatically have something like
>>
>>"failonerror" + you
>>
>>
>>>actually know if the part failed and can take an
>>
>>appropriate build path
>>
>>
>>>from here on.
>>>
>>>
>>>Jan
>>>
>>>
>>>----------------------------------------------------------
>>
>>-----------
>>
>>
>>>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>>>For additional commands, e-mail: dev-help@ant.apache.org
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
>>For additional commands, e-mail: dev-help@ant.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: failonerror; general solution

Posted by peter reilly <pe...@corvil.com>.
Here is a task that does some like that:

package task;

import org.apache.tools.ant.taskdefs.Sequential;


public class NoFail extends Sequential {
    private String failureProperty;
    public void setFailureProperty(String name) {
        this.failureProperty = name;
    }
    public void execute() {
        try {
            super.execute();
        } catch (Throwable t) {
            if (failureProperty != null) {
                getProject().setNewProperty(
                    failureProperty, "true");
            }
        }
    }
}

Usage:
<project>
  <mkdir dir="classes"/>
  <javac srcdir="src" destdir="classes"/>
  <taskdef name="nofail" classname="task.NoFail"
           classpath="classes"/>

  <target name="test">
    <nofail failureproperty="failed">
      <fail>This should fail</fail>
      <echo>This will not be reached</echo>
    </nofail>
    <echo>failed is ${failed}</echo>
  </target>
</project>


Peter

On Friday 03 October 2003 15:43, Emmanuel Feller wrote:
> I agree, it is a good option in my mind.
>
> +1 :)
>
> Emmanuel
> ----- Message d'origine -----
> De : "Jan Schroeder" <ja...@gmx.net>
> �: <de...@ant.apache.org>
> Envoy�: vendredi 3 octobre 2003 16:38
> Objet : failonerror; general solution
>
> > There are a few new entries in bugzilla regarding handling
>
> of
>
> > BuildExceptions.
>
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23540
>
> http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23581
>
> > Also, some tasks already implement some "failonerror"
>
> attribute (e.g.
>
> > <java>).
> >
> > What about creating a container task instead.
> > Like:
> >
> > <nofail failureproperty="part.failed">
> >     <patch .../>
> >     <echo ../>
> >     <antcall />
> > </nofail>
> >
> > That way all tasks automatically have something like
>
> "failonerror" + you
>
> > actually know if the part failed and can take an
>
> appropriate build path
>
> > from here on.
> >
> >
> > Jan
> >
> >
> > ----------------------------------------------------------
>
> -----------
>
> > To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> > For additional commands, e-mail: dev-help@ant.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Re: failonerror; general solution

Posted by Emmanuel Feller <Em...@free.fr>.
I agree, it is a good option in my mind.

+1 :)

Emmanuel
----- Message d'origine ----- 
De : "Jan Schroeder" <ja...@gmx.net>
� : <de...@ant.apache.org>
Envoy� : vendredi 3 octobre 2003 16:38
Objet : failonerror; general solution


> There are a few new entries in bugzilla regarding handling
of
> BuildExceptions.
>
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23540
>
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=23581
>
> Also, some tasks already implement some "failonerror"
attribute (e.g.
> <java>).
>
> What about creating a container task instead.
> Like:
>
> <nofail failureproperty="part.failed">
>     <patch .../>
>     <echo ../>
>     <antcall />
> </nofail>
>
> That way all tasks automatically have something like
"failonerror" + you
> actually know if the part failed and can take an
appropriate build path
> from here on.
>
>
> Jan
>
>
> ----------------------------------------------------------
-----------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org