You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Isaac Jurado <di...@gmail.com> on 2019/02/23 09:37:23 UTC

Creating task/macro wrappers

Hello Ant users,

I'm trying to create a <macrodef> wrapper over <testng>.  The idea is
to have my macro expose the same attributes that <testng> supports,
with as close semantics as possible.

Unfortunately, I have no idea how to reproduce the presence/absence
behavior.  For instance, <testng> accepts a "timeout" integer
attribute.  So in my macro I would do:

<attribute name="timeout" default=""/>

And then calling TestNG would be:

<testng timeout="@{timeout}">...</testng>

But this turns out not to be the same behavior as NOT specifying the
timeout attribute.  In this case, Ant fails because empty string does
not parse to an integer.

Is there a way to achieve my goal?  I would like to avoid writing Java
code.  But I don't mind resorting to Javascript in the build file
(<script> or <scriptdef>).

Thanks in advance.

-- 
Isaac Jurado

"The noblest pleasure is the joy of understanding"
Leonardo da Vinci

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


AW: Creating task/macro wrappers

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
Maybe writing your own Task in Java is the easiest and most maintainable way.
The task collects all data and then uses the existing testng task via delegation.
(don’t forget to pass project and location reference)

Jan

> -----Ursprüngliche Nachricht-----
> Von: Isaac Jurado [mailto:diptongo@gmail.com]
> Gesendet: Montag, 25. Februar 2019 19:59
> An: Ant Users List; Matt Benson
> Betreff: Re: Creating task/macro wrappers
> 
> So, if I understood that right, the idea would be to create two
> <presetdef>: one with "timeout" and another one without?
> 
> If that is the case, as the number of "omittable" attributes grows, the
> amount of <presetdef> combinations increases exponentially.
> 
> I may be pretty much stretching Ant beyond its limits (in terms of XML
> syntax).  And the behavior of the <testng> task implemented in Java
> doesn't help much either, not interpreting empty strings as null
> values.
> 
> But thanks anyway.
> 
> On Mon, Feb 25, 2019 at 7:53 PM Matt Benson <gu...@gmail.com>
> wrote:
> >
> > You could conditionally <presetdef> with or without the desired
> > attributes, depending on the structure of your build. :|
> >
> > Matt
> >
> > On Mon, Feb 25, 2019 at 12:39 PM Isaac Jurado <di...@gmail.com>
> wrote:
> >
> > > Thanks for the info, I didn't know about <presetdef> either.
> > >
> > > By the looks of it, seems that <presetdef> is the opposite of what
> > > I'm trying to achieve.
> > >
> > > I'll try to explain myself again with a very narrowed and concrete
> > > example.  As I mentioned, I'm trying to wrap <testng> because I
> want
> > > to teak some of its attributes, while leaving others "untouched"
> but
> > > still exposed through my wrapper macro.
> > >
> > > One of these "untouched" attributes would be "timeout", defined
> here:
> > >
> > >
> > >
> https://github.com/cbeust/testng/blob/master/src/main/java/org/testn
> > > g/TestNGAntTask.java#L285-L287
> > >
> > > So, without a wrapper, using <testng timeout="4"> is different from
> > > just <testng>.  In this case, the default value of timeout is null,
> > > which cannot be represented in a build.xml file. Using the
> following:
> > >
> > > <macrodef name="mymacro">
> > >   <attribute name="timeout" default=""/>
> > >   <testng timeout="@{timeout}">...</testng> </macrodef>
> > >
> > > Doesn't work with the default value because
> > > TestNGAntTask.setTimeout() accepts an Integer which Ant cannot
> parse.
> > >
> > > Then, using <augment> seems like the way to go.  However, <testng>
> > > is a task which executes immediately.  So none of the following
> > > options
> > > work:
> > >
> > > <macrodef name="mymacro">
> > >   <attribute name="timeout" default=""/>
> > >   <sequential>
> > >     <augment unless:blank="timeout" id="invocation"
> timeout="@{timeout}"/>
> > >     <testng ref="invocation">...</testng>
> > >   </sequential>
> > > </macrodef>
> > >
> > > <macrodef name="mymacro">
> > >   <attribute name="timeout" default=""/>
> > >   <sequential>
> > >     <testng ref="invocation">...</testng>
> > >     <augment unless:blank="timeout" id="invocation"
> > > timeout="@{timeout}"/>  </sequential> </macrodef>
> > >
> > > The first one fails because the reference is defined after
> > > <agument>, and the second one doesn't achieve the desired result
> > > because <testng> is executed before being augmented.
> > >
> > > I guess the only two solutions left are, as Al Le suggested, use
> > > Javascript or Java directly.  Which is a pity because reproducing
> > > the functionality of <element optional="true" implicit="true"/>
> with
> > > Javascript (e.g. via <scriptdef>) seems very tedious.
> > >
> > > Fortunately, none of the problematic TestNG's attributes are
> > > essential right now, so I may end up implementing the wrapper in
> Java.
> > >
> > > Thank you all for your suggestions.
> > >
> > > On Mon, Feb 25, 2019 at 3:20 PM Jan Matèrne (jhm)
> > > <ap...@materne.de>
> > > wrote:
> > > >
> > > > Not sure why you want to wrap an existing Ant task ...
> > > > If you want to provide default settings, you could use
> <presetdef>
> > > >
> > > > Jan
> > > >
> > > > > -----Ursprüngliche Nachricht-----
> > > > > Von: Isaac Jurado [mailto:diptongo@gmail.com]
> > > > > Gesendet: Sonntag, 24. Februar 2019 18:27
> > > > > An: Ant Users List; gudnabrsam@gmail.com
> > > > > Betreff: Re: Creating task/macro wrappers
> > > > >
> > > > > Thanks!  I didn't notice the <augment> task existed.
> > > > >
> > > > > However, I don't seem to wrap my head around it.  In
> particular,
> > > > > it doesn't seem to support forward references.  This is what I
> tried:
> > > > >
> > > > > <macrodef name="mywrapper">
> > > > >   <attribute name="timeOut" default=""/>
> > > > >   <sequential>
> > > > >     <augment unless:blank="timeOut" id="my-testng-invocation"
> > > > > timeOut="@{timeOut}"/>
> > > > >     <testng id="my-testng-invocation">...</testng>
> > > > >   </sequentail>
> > > > > </macrodef>
> > > > >
> > > > > The error I get is:
> > > > >
> > > > > java.lang.IllegalStateException: Unknown reference "my-testng-
> > > > > invocation"
> > > > >
> > > > > Best regards.
> > > > >
> > > > > On Sat, Feb 23, 2019 at 5:41 PM Matt Benson
> > > > > <gu...@gmail.com>
> > > > > wrote:
> > > > > >
> > > > > > Look into the <augment> task with conditionally executed
> > > > > > (using if/unless namespaces, antcontrib <if>, or similar)
> > > > > > <sequential>
> > > > > blocks.
> > > > > >
> > > > > > HTH,
> > > > > > Matt
> > > > > >
> > > > > > On Sat, Feb 23, 2019, 3:37 AM Isaac Jurado
> > > > > > <di...@gmail.com>
> > > > > wrote:
> > > > > >
> > > > > > > Hello Ant users,
> > > > > > >
> > > > > > > I'm trying to create a <macrodef> wrapper over <testng>.
> > > > > > > The idea is to have my macro expose the same attributes
> that
> > > > > > > <testng> supports, with as close semantics as possible.
> > > > > > >
> > > > > > > Unfortunately, I have no idea how to reproduce the
> > > > > > > presence/absence behavior.  For instance, <testng> accepts
> a
> > > > > > > "timeout" integer attribute.  So in my macro I would do:
> > > > > > >
> > > > > > > <attribute name="timeout" default=""/>
> > > > > > >
> > > > > > > And then calling TestNG would be:
> > > > > > >
> > > > > > > <testng timeout="@{timeout}">...</testng>
> > > > > > >
> > > > > > > But this turns out not to be the same behavior as NOT
> > > > > > > specifying
> > > > > the
> > > > > > > timeout attribute.  In this case, Ant fails because empty
> > > > > > > string does not parse to an integer.
> > > > > > >
> > > > > > > Is there a way to achieve my goal?  I would like to avoid
> > > > > > > writing Java code.  But I don't mind resorting to
> Javascript
> > > > > > > in the build file (<script> or <scriptdef>).
> > > > > > >
> > > > > > > Thanks in advance.
> > > > > > >
> > > > > > > --
> > > > > > > Isaac Jurado
> > > > > > >
> > > > > > > "The noblest pleasure is the joy of understanding"
> > > > > > > Leonardo da Vinci
> > > > > > >
> > > > > > > -----------------------------------------------------------
> -
> > > > > > > -------
> > > > > -
> > > > > > > - To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > > > > > > For additional commands, e-mail: user-help@ant.apache.org
> > > > > > >
> > > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Isaac Jurado
> > > > >
> > > > > "The noblest pleasure is the joy of understanding"
> > > > > Leonardo da Vinci
> > > > >
> > > > > ---------------------------------------------------------------
> -
> > > > > ----- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > > > > For additional commands, e-mail: user-help@ant.apache.org
> > > >
> > > >
> > > >
> > > > -----------------------------------------------------------------
> -
> > > > --- To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For
> > > > additional commands, e-mail: user-help@ant.apache.org
> > > >
> > >
> > >
> > > --
> > > Isaac Jurado
> > >
> > > "The noblest pleasure is the joy of understanding"
> > > Leonardo da Vinci
> > >
> > > -------------------------------------------------------------------
> -
> > > - To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For
> > > additional commands, e-mail: user-help@ant.apache.org
> > >
> > >
> 
> 
> 
> --
> Isaac Jurado
> 
> "The noblest pleasure is the joy of understanding"
> Leonardo da Vinci
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional
> commands, e-mail: user-help@ant.apache.org



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


Re: Creating task/macro wrappers

Posted by Isaac Jurado <di...@gmail.com>.
So, if I understood that right, the idea would be to create two
<presetdef>: one with "timeout" and another one without?

If that is the case, as the number of "omittable" attributes grows,
the amount of <presetdef> combinations increases exponentially.

I may be pretty much stretching Ant beyond its limits (in terms of XML
syntax).  And the behavior of the <testng> task implemented in Java
doesn't help much either, not interpreting empty strings as null
values.

But thanks anyway.

On Mon, Feb 25, 2019 at 7:53 PM Matt Benson <gu...@gmail.com> wrote:
>
> You could conditionally <presetdef> with or without the desired attributes,
> depending on the structure of your build. :|
>
> Matt
>
> On Mon, Feb 25, 2019 at 12:39 PM Isaac Jurado <di...@gmail.com> wrote:
>
> > Thanks for the info, I didn't know about <presetdef> either.
> >
> > By the looks of it, seems that <presetdef> is the opposite of what I'm
> > trying to achieve.
> >
> > I'll try to explain myself again with a very narrowed and concrete
> > example.  As I mentioned, I'm trying to wrap <testng> because I want
> > to teak some of its attributes, while leaving others "untouched" but
> > still exposed through my wrapper macro.
> >
> > One of these "untouched" attributes would be "timeout", defined here:
> >
> >
> > https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/TestNGAntTask.java#L285-L287
> >
> > So, without a wrapper, using <testng timeout="4"> is different from
> > just <testng>.  In this case, the default value of timeout is null,
> > which cannot be represented in a build.xml file. Using the following:
> >
> > <macrodef name="mymacro">
> >   <attribute name="timeout" default=""/>
> >   <testng timeout="@{timeout}">...</testng>
> > </macrodef>
> >
> > Doesn't work with the default value because TestNGAntTask.setTimeout()
> > accepts an Integer which Ant cannot parse.
> >
> > Then, using <augment> seems like the way to go.  However, <testng> is
> > a task which executes immediately.  So none of the following options
> > work:
> >
> > <macrodef name="mymacro">
> >   <attribute name="timeout" default=""/>
> >   <sequential>
> >     <augment unless:blank="timeout" id="invocation" timeout="@{timeout}"/>
> >     <testng ref="invocation">...</testng>
> >   </sequential>
> > </macrodef>
> >
> > <macrodef name="mymacro">
> >   <attribute name="timeout" default=""/>
> >   <sequential>
> >     <testng ref="invocation">...</testng>
> >     <augment unless:blank="timeout" id="invocation" timeout="@{timeout}"/>
> >  </sequential>
> > </macrodef>
> >
> > The first one fails because the reference is defined after <agument>,
> > and the second one doesn't achieve the desired result because <testng>
> > is executed before being augmented.
> >
> > I guess the only two solutions left are, as Al Le suggested, use
> > Javascript or Java directly.  Which is a pity because reproducing the
> > functionality of <element optional="true" implicit="true"/> with
> > Javascript (e.g. via <scriptdef>) seems very tedious.
> >
> > Fortunately, none of the problematic TestNG's attributes are essential
> > right now, so I may end up implementing the wrapper in Java.
> >
> > Thank you all for your suggestions.
> >
> > On Mon, Feb 25, 2019 at 3:20 PM Jan Matèrne (jhm) <ap...@materne.de>
> > wrote:
> > >
> > > Not sure why you want to wrap an existing Ant task ...
> > > If you want to provide default settings, you could use <presetdef>
> > >
> > > Jan
> > >
> > > > -----Ursprüngliche Nachricht-----
> > > > Von: Isaac Jurado [mailto:diptongo@gmail.com]
> > > > Gesendet: Sonntag, 24. Februar 2019 18:27
> > > > An: Ant Users List; gudnabrsam@gmail.com
> > > > Betreff: Re: Creating task/macro wrappers
> > > >
> > > > Thanks!  I didn't notice the <augment> task existed.
> > > >
> > > > However, I don't seem to wrap my head around it.  In particular, it
> > > > doesn't seem to support forward references.  This is what I tried:
> > > >
> > > > <macrodef name="mywrapper">
> > > >   <attribute name="timeOut" default=""/>
> > > >   <sequential>
> > > >     <augment unless:blank="timeOut" id="my-testng-invocation"
> > > > timeOut="@{timeOut}"/>
> > > >     <testng id="my-testng-invocation">...</testng>
> > > >   </sequentail>
> > > > </macrodef>
> > > >
> > > > The error I get is:
> > > >
> > > > java.lang.IllegalStateException: Unknown reference "my-testng-
> > > > invocation"
> > > >
> > > > Best regards.
> > > >
> > > > On Sat, Feb 23, 2019 at 5:41 PM Matt Benson <gu...@gmail.com>
> > > > wrote:
> > > > >
> > > > > Look into the <augment> task with conditionally executed (using
> > > > > if/unless namespaces, antcontrib <if>, or similar) <sequential>
> > > > blocks.
> > > > >
> > > > > HTH,
> > > > > Matt
> > > > >
> > > > > On Sat, Feb 23, 2019, 3:37 AM Isaac Jurado <di...@gmail.com>
> > > > wrote:
> > > > >
> > > > > > Hello Ant users,
> > > > > >
> > > > > > I'm trying to create a <macrodef> wrapper over <testng>.  The idea
> > > > > > is to have my macro expose the same attributes that <testng>
> > > > > > supports, with as close semantics as possible.
> > > > > >
> > > > > > Unfortunately, I have no idea how to reproduce the presence/absence
> > > > > > behavior.  For instance, <testng> accepts a "timeout" integer
> > > > > > attribute.  So in my macro I would do:
> > > > > >
> > > > > > <attribute name="timeout" default=""/>
> > > > > >
> > > > > > And then calling TestNG would be:
> > > > > >
> > > > > > <testng timeout="@{timeout}">...</testng>
> > > > > >
> > > > > > But this turns out not to be the same behavior as NOT specifying
> > > > the
> > > > > > timeout attribute.  In this case, Ant fails because empty string
> > > > > > does not parse to an integer.
> > > > > >
> > > > > > Is there a way to achieve my goal?  I would like to avoid writing
> > > > > > Java code.  But I don't mind resorting to Javascript in the build
> > > > > > file (<script> or <scriptdef>).
> > > > > >
> > > > > > Thanks in advance.
> > > > > >
> > > > > > --
> > > > > > Isaac Jurado
> > > > > >
> > > > > > "The noblest pleasure is the joy of understanding"
> > > > > > Leonardo da Vinci
> > > > > >
> > > > > > -------------------------------------------------------------------
> > > > -
> > > > > > - To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For
> > > > > > additional commands, e-mail: user-help@ant.apache.org
> > > > > >
> > > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Isaac Jurado
> > > >
> > > > "The noblest pleasure is the joy of understanding"
> > > > Leonardo da Vinci
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional
> > > > commands, e-mail: user-help@ant.apache.org
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > > For additional commands, e-mail: user-help@ant.apache.org
> > >
> >
> >
> > --
> > Isaac Jurado
> >
> > "The noblest pleasure is the joy of understanding"
> > Leonardo da Vinci
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >



-- 
Isaac Jurado

"The noblest pleasure is the joy of understanding"
Leonardo da Vinci

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


Re: Creating task/macro wrappers

Posted by Matt Benson <gu...@gmail.com>.
You could conditionally <presetdef> with or without the desired attributes,
depending on the structure of your build. :|

Matt

On Mon, Feb 25, 2019 at 12:39 PM Isaac Jurado <di...@gmail.com> wrote:

> Thanks for the info, I didn't know about <presetdef> either.
>
> By the looks of it, seems that <presetdef> is the opposite of what I'm
> trying to achieve.
>
> I'll try to explain myself again with a very narrowed and concrete
> example.  As I mentioned, I'm trying to wrap <testng> because I want
> to teak some of its attributes, while leaving others "untouched" but
> still exposed through my wrapper macro.
>
> One of these "untouched" attributes would be "timeout", defined here:
>
>
> https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/TestNGAntTask.java#L285-L287
>
> So, without a wrapper, using <testng timeout="4"> is different from
> just <testng>.  In this case, the default value of timeout is null,
> which cannot be represented in a build.xml file. Using the following:
>
> <macrodef name="mymacro">
>   <attribute name="timeout" default=""/>
>   <testng timeout="@{timeout}">...</testng>
> </macrodef>
>
> Doesn't work with the default value because TestNGAntTask.setTimeout()
> accepts an Integer which Ant cannot parse.
>
> Then, using <augment> seems like the way to go.  However, <testng> is
> a task which executes immediately.  So none of the following options
> work:
>
> <macrodef name="mymacro">
>   <attribute name="timeout" default=""/>
>   <sequential>
>     <augment unless:blank="timeout" id="invocation" timeout="@{timeout}"/>
>     <testng ref="invocation">...</testng>
>   </sequential>
> </macrodef>
>
> <macrodef name="mymacro">
>   <attribute name="timeout" default=""/>
>   <sequential>
>     <testng ref="invocation">...</testng>
>     <augment unless:blank="timeout" id="invocation" timeout="@{timeout}"/>
>  </sequential>
> </macrodef>
>
> The first one fails because the reference is defined after <agument>,
> and the second one doesn't achieve the desired result because <testng>
> is executed before being augmented.
>
> I guess the only two solutions left are, as Al Le suggested, use
> Javascript or Java directly.  Which is a pity because reproducing the
> functionality of <element optional="true" implicit="true"/> with
> Javascript (e.g. via <scriptdef>) seems very tedious.
>
> Fortunately, none of the problematic TestNG's attributes are essential
> right now, so I may end up implementing the wrapper in Java.
>
> Thank you all for your suggestions.
>
> On Mon, Feb 25, 2019 at 3:20 PM Jan Matèrne (jhm) <ap...@materne.de>
> wrote:
> >
> > Not sure why you want to wrap an existing Ant task ...
> > If you want to provide default settings, you could use <presetdef>
> >
> > Jan
> >
> > > -----Ursprüngliche Nachricht-----
> > > Von: Isaac Jurado [mailto:diptongo@gmail.com]
> > > Gesendet: Sonntag, 24. Februar 2019 18:27
> > > An: Ant Users List; gudnabrsam@gmail.com
> > > Betreff: Re: Creating task/macro wrappers
> > >
> > > Thanks!  I didn't notice the <augment> task existed.
> > >
> > > However, I don't seem to wrap my head around it.  In particular, it
> > > doesn't seem to support forward references.  This is what I tried:
> > >
> > > <macrodef name="mywrapper">
> > >   <attribute name="timeOut" default=""/>
> > >   <sequential>
> > >     <augment unless:blank="timeOut" id="my-testng-invocation"
> > > timeOut="@{timeOut}"/>
> > >     <testng id="my-testng-invocation">...</testng>
> > >   </sequentail>
> > > </macrodef>
> > >
> > > The error I get is:
> > >
> > > java.lang.IllegalStateException: Unknown reference "my-testng-
> > > invocation"
> > >
> > > Best regards.
> > >
> > > On Sat, Feb 23, 2019 at 5:41 PM Matt Benson <gu...@gmail.com>
> > > wrote:
> > > >
> > > > Look into the <augment> task with conditionally executed (using
> > > > if/unless namespaces, antcontrib <if>, or similar) <sequential>
> > > blocks.
> > > >
> > > > HTH,
> > > > Matt
> > > >
> > > > On Sat, Feb 23, 2019, 3:37 AM Isaac Jurado <di...@gmail.com>
> > > wrote:
> > > >
> > > > > Hello Ant users,
> > > > >
> > > > > I'm trying to create a <macrodef> wrapper over <testng>.  The idea
> > > > > is to have my macro expose the same attributes that <testng>
> > > > > supports, with as close semantics as possible.
> > > > >
> > > > > Unfortunately, I have no idea how to reproduce the presence/absence
> > > > > behavior.  For instance, <testng> accepts a "timeout" integer
> > > > > attribute.  So in my macro I would do:
> > > > >
> > > > > <attribute name="timeout" default=""/>
> > > > >
> > > > > And then calling TestNG would be:
> > > > >
> > > > > <testng timeout="@{timeout}">...</testng>
> > > > >
> > > > > But this turns out not to be the same behavior as NOT specifying
> > > the
> > > > > timeout attribute.  In this case, Ant fails because empty string
> > > > > does not parse to an integer.
> > > > >
> > > > > Is there a way to achieve my goal?  I would like to avoid writing
> > > > > Java code.  But I don't mind resorting to Javascript in the build
> > > > > file (<script> or <scriptdef>).
> > > > >
> > > > > Thanks in advance.
> > > > >
> > > > > --
> > > > > Isaac Jurado
> > > > >
> > > > > "The noblest pleasure is the joy of understanding"
> > > > > Leonardo da Vinci
> > > > >
> > > > > -------------------------------------------------------------------
> > > -
> > > > > - To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For
> > > > > additional commands, e-mail: user-help@ant.apache.org
> > > > >
> > > > >
> > >
> > >
> > >
> > > --
> > > Isaac Jurado
> > >
> > > "The noblest pleasure is the joy of understanding"
> > > Leonardo da Vinci
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional
> > > commands, e-mail: user-help@ant.apache.org
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
>
>
> --
> Isaac Jurado
>
> "The noblest pleasure is the joy of understanding"
> Leonardo da Vinci
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

Re: Creating task/macro wrappers

Posted by Isaac Jurado <di...@gmail.com>.
Thanks for the info, I didn't know about <presetdef> either.

By the looks of it, seems that <presetdef> is the opposite of what I'm
trying to achieve.

I'll try to explain myself again with a very narrowed and concrete
example.  As I mentioned, I'm trying to wrap <testng> because I want
to teak some of its attributes, while leaving others "untouched" but
still exposed through my wrapper macro.

One of these "untouched" attributes would be "timeout", defined here:

https://github.com/cbeust/testng/blob/master/src/main/java/org/testng/TestNGAntTask.java#L285-L287

So, without a wrapper, using <testng timeout="4"> is different from
just <testng>.  In this case, the default value of timeout is null,
which cannot be represented in a build.xml file. Using the following:

<macrodef name="mymacro">
  <attribute name="timeout" default=""/>
  <testng timeout="@{timeout}">...</testng>
</macrodef>

Doesn't work with the default value because TestNGAntTask.setTimeout()
accepts an Integer which Ant cannot parse.

Then, using <augment> seems like the way to go.  However, <testng> is
a task which executes immediately.  So none of the following options
work:

<macrodef name="mymacro">
  <attribute name="timeout" default=""/>
  <sequential>
    <augment unless:blank="timeout" id="invocation" timeout="@{timeout}"/>
    <testng ref="invocation">...</testng>
  </sequential>
</macrodef>

<macrodef name="mymacro">
  <attribute name="timeout" default=""/>
  <sequential>
    <testng ref="invocation">...</testng>
    <augment unless:blank="timeout" id="invocation" timeout="@{timeout}"/>
 </sequential>
</macrodef>

The first one fails because the reference is defined after <agument>,
and the second one doesn't achieve the desired result because <testng>
is executed before being augmented.

I guess the only two solutions left are, as Al Le suggested, use
Javascript or Java directly.  Which is a pity because reproducing the
functionality of <element optional="true" implicit="true"/> with
Javascript (e.g. via <scriptdef>) seems very tedious.

Fortunately, none of the problematic TestNG's attributes are essential
right now, so I may end up implementing the wrapper in Java.

Thank you all for your suggestions.

On Mon, Feb 25, 2019 at 3:20 PM Jan Matèrne (jhm) <ap...@materne.de> wrote:
>
> Not sure why you want to wrap an existing Ant task ...
> If you want to provide default settings, you could use <presetdef>
>
> Jan
>
> > -----Ursprüngliche Nachricht-----
> > Von: Isaac Jurado [mailto:diptongo@gmail.com]
> > Gesendet: Sonntag, 24. Februar 2019 18:27
> > An: Ant Users List; gudnabrsam@gmail.com
> > Betreff: Re: Creating task/macro wrappers
> >
> > Thanks!  I didn't notice the <augment> task existed.
> >
> > However, I don't seem to wrap my head around it.  In particular, it
> > doesn't seem to support forward references.  This is what I tried:
> >
> > <macrodef name="mywrapper">
> >   <attribute name="timeOut" default=""/>
> >   <sequential>
> >     <augment unless:blank="timeOut" id="my-testng-invocation"
> > timeOut="@{timeOut}"/>
> >     <testng id="my-testng-invocation">...</testng>
> >   </sequentail>
> > </macrodef>
> >
> > The error I get is:
> >
> > java.lang.IllegalStateException: Unknown reference "my-testng-
> > invocation"
> >
> > Best regards.
> >
> > On Sat, Feb 23, 2019 at 5:41 PM Matt Benson <gu...@gmail.com>
> > wrote:
> > >
> > > Look into the <augment> task with conditionally executed (using
> > > if/unless namespaces, antcontrib <if>, or similar) <sequential>
> > blocks.
> > >
> > > HTH,
> > > Matt
> > >
> > > On Sat, Feb 23, 2019, 3:37 AM Isaac Jurado <di...@gmail.com>
> > wrote:
> > >
> > > > Hello Ant users,
> > > >
> > > > I'm trying to create a <macrodef> wrapper over <testng>.  The idea
> > > > is to have my macro expose the same attributes that <testng>
> > > > supports, with as close semantics as possible.
> > > >
> > > > Unfortunately, I have no idea how to reproduce the presence/absence
> > > > behavior.  For instance, <testng> accepts a "timeout" integer
> > > > attribute.  So in my macro I would do:
> > > >
> > > > <attribute name="timeout" default=""/>
> > > >
> > > > And then calling TestNG would be:
> > > >
> > > > <testng timeout="@{timeout}">...</testng>
> > > >
> > > > But this turns out not to be the same behavior as NOT specifying
> > the
> > > > timeout attribute.  In this case, Ant fails because empty string
> > > > does not parse to an integer.
> > > >
> > > > Is there a way to achieve my goal?  I would like to avoid writing
> > > > Java code.  But I don't mind resorting to Javascript in the build
> > > > file (<script> or <scriptdef>).
> > > >
> > > > Thanks in advance.
> > > >
> > > > --
> > > > Isaac Jurado
> > > >
> > > > "The noblest pleasure is the joy of understanding"
> > > > Leonardo da Vinci
> > > >
> > > > -------------------------------------------------------------------
> > -
> > > > - To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For
> > > > additional commands, e-mail: user-help@ant.apache.org
> > > >
> > > >
> >
> >
> >
> > --
> > Isaac Jurado
> >
> > "The noblest pleasure is the joy of understanding"
> > Leonardo da Vinci
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional
> > commands, e-mail: user-help@ant.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>


-- 
Isaac Jurado

"The noblest pleasure is the joy of understanding"
Leonardo da Vinci

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


AW: Creating task/macro wrappers

Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
Not sure why you want to wrap an existing Ant task ...
If you want to provide default settings, you could use <presetdef>

Jan

> -----Ursprüngliche Nachricht-----
> Von: Isaac Jurado [mailto:diptongo@gmail.com]
> Gesendet: Sonntag, 24. Februar 2019 18:27
> An: Ant Users List; gudnabrsam@gmail.com
> Betreff: Re: Creating task/macro wrappers
> 
> Thanks!  I didn't notice the <augment> task existed.
> 
> However, I don't seem to wrap my head around it.  In particular, it
> doesn't seem to support forward references.  This is what I tried:
> 
> <macrodef name="mywrapper">
>   <attribute name="timeOut" default=""/>
>   <sequential>
>     <augment unless:blank="timeOut" id="my-testng-invocation"
> timeOut="@{timeOut}"/>
>     <testng id="my-testng-invocation">...</testng>
>   </sequentail>
> </macrodef>
> 
> The error I get is:
> 
> java.lang.IllegalStateException: Unknown reference "my-testng-
> invocation"
> 
> Best regards.
> 
> On Sat, Feb 23, 2019 at 5:41 PM Matt Benson <gu...@gmail.com>
> wrote:
> >
> > Look into the <augment> task with conditionally executed (using
> > if/unless namespaces, antcontrib <if>, or similar) <sequential>
> blocks.
> >
> > HTH,
> > Matt
> >
> > On Sat, Feb 23, 2019, 3:37 AM Isaac Jurado <di...@gmail.com>
> wrote:
> >
> > > Hello Ant users,
> > >
> > > I'm trying to create a <macrodef> wrapper over <testng>.  The idea
> > > is to have my macro expose the same attributes that <testng>
> > > supports, with as close semantics as possible.
> > >
> > > Unfortunately, I have no idea how to reproduce the presence/absence
> > > behavior.  For instance, <testng> accepts a "timeout" integer
> > > attribute.  So in my macro I would do:
> > >
> > > <attribute name="timeout" default=""/>
> > >
> > > And then calling TestNG would be:
> > >
> > > <testng timeout="@{timeout}">...</testng>
> > >
> > > But this turns out not to be the same behavior as NOT specifying
> the
> > > timeout attribute.  In this case, Ant fails because empty string
> > > does not parse to an integer.
> > >
> > > Is there a way to achieve my goal?  I would like to avoid writing
> > > Java code.  But I don't mind resorting to Javascript in the build
> > > file (<script> or <scriptdef>).
> > >
> > > Thanks in advance.
> > >
> > > --
> > > Isaac Jurado
> > >
> > > "The noblest pleasure is the joy of understanding"
> > > Leonardo da Vinci
> > >
> > > -------------------------------------------------------------------
> -
> > > - To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For
> > > additional commands, e-mail: user-help@ant.apache.org
> > >
> > >
> 
> 
> 
> --
> Isaac Jurado
> 
> "The noblest pleasure is the joy of understanding"
> Leonardo da Vinci
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org For additional
> commands, e-mail: user-help@ant.apache.org



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


Re: Creating task/macro wrappers

Posted by Isaac Jurado <di...@gmail.com>.
Thanks!  I didn't notice the <augment> task existed.

However, I don't seem to wrap my head around it.  In particular, it
doesn't seem to support forward references.  This is what I tried:

<macrodef name="mywrapper">
  <attribute name="timeOut" default=""/>
  <sequential>
    <augment unless:blank="timeOut" id="my-testng-invocation"
timeOut="@{timeOut}"/>
    <testng id="my-testng-invocation">...</testng>
  </sequentail>
</macrodef>

The error I get is:

java.lang.IllegalStateException: Unknown reference "my-testng-invocation"

Best regards.

On Sat, Feb 23, 2019 at 5:41 PM Matt Benson <gu...@gmail.com> wrote:
>
> Look into the <augment> task with conditionally executed (using if/unless
> namespaces, antcontrib <if>, or similar) <sequential> blocks.
>
> HTH,
> Matt
>
> On Sat, Feb 23, 2019, 3:37 AM Isaac Jurado <di...@gmail.com> wrote:
>
> > Hello Ant users,
> >
> > I'm trying to create a <macrodef> wrapper over <testng>.  The idea is
> > to have my macro expose the same attributes that <testng> supports,
> > with as close semantics as possible.
> >
> > Unfortunately, I have no idea how to reproduce the presence/absence
> > behavior.  For instance, <testng> accepts a "timeout" integer
> > attribute.  So in my macro I would do:
> >
> > <attribute name="timeout" default=""/>
> >
> > And then calling TestNG would be:
> >
> > <testng timeout="@{timeout}">...</testng>
> >
> > But this turns out not to be the same behavior as NOT specifying the
> > timeout attribute.  In this case, Ant fails because empty string does
> > not parse to an integer.
> >
> > Is there a way to achieve my goal?  I would like to avoid writing Java
> > code.  But I don't mind resorting to Javascript in the build file
> > (<script> or <scriptdef>).
> >
> > Thanks in advance.
> >
> > --
> > Isaac Jurado
> >
> > "The noblest pleasure is the joy of understanding"
> > Leonardo da Vinci
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> >
> >



-- 
Isaac Jurado

"The noblest pleasure is the joy of understanding"
Leonardo da Vinci

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


Re: Creating task/macro wrappers

Posted by Matt Benson <gu...@gmail.com>.
Look into the <augment> task with conditionally executed (using if/unless
namespaces, antcontrib <if>, or similar) <sequential> blocks.

HTH,
Matt

On Sat, Feb 23, 2019, 3:37 AM Isaac Jurado <di...@gmail.com> wrote:

> Hello Ant users,
>
> I'm trying to create a <macrodef> wrapper over <testng>.  The idea is
> to have my macro expose the same attributes that <testng> supports,
> with as close semantics as possible.
>
> Unfortunately, I have no idea how to reproduce the presence/absence
> behavior.  For instance, <testng> accepts a "timeout" integer
> attribute.  So in my macro I would do:
>
> <attribute name="timeout" default=""/>
>
> And then calling TestNG would be:
>
> <testng timeout="@{timeout}">...</testng>
>
> But this turns out not to be the same behavior as NOT specifying the
> timeout attribute.  In this case, Ant fails because empty string does
> not parse to an integer.
>
> Is there a way to achieve my goal?  I would like to avoid writing Java
> code.  But I don't mind resorting to Javascript in the build file
> (<script> or <scriptdef>).
>
> Thanks in advance.
>
> --
> Isaac Jurado
>
> "The noblest pleasure is the joy of understanding"
> Leonardo da Vinci
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>