Creating task/macro wrappers

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating task/macro wrappers

Isaac Jurado
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: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Creating task/macro wrappers

Matt Benson-2
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 <[hidden email]> 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: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Creating task/macro wrappers

Al Le
In reply to this post by Isaac Jurado
You could write a script, e.g. in JavaScript. There, you would create a
new instance of the testng task (using the global 'project' object),
then set all the necessary attributes and nested elements of the task
(don't forget to set the owning target), and, finally, call its
'execute' method.



Am 23.02.2019 um 10:37 schrieb Isaac Jurado:

> 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.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Creating task/macro wrappers

Isaac Jurado
In reply to this post by Matt Benson-2
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 <[hidden email]> 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 <[hidden email]> 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: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >



--
Isaac Jurado

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

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

AW: Creating task/macro wrappers

Jan Matèrne (jhm)
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:[hidden email]]
> Gesendet: Sonntag, 24. Februar 2019 18:27
> An: Ant Users List; [hidden email]
> 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 <[hidden email]>
> 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 <[hidden email]>
> 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: [hidden email] For
> > > additional commands, e-mail: [hidden email]
> > >
> > >
>
>
>
> --
> Isaac Jurado
>
> "The noblest pleasure is the joy of understanding"
> Leonardo da Vinci
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email] For additional
> commands, e-mail: [hidden email]



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Creating task/macro wrappers

Isaac Jurado
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) <[hidden email]> 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:[hidden email]]
> > Gesendet: Sonntag, 24. Februar 2019 18:27
> > An: Ant Users List; [hidden email]
> > 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 <[hidden email]>
> > 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 <[hidden email]>
> > 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: [hidden email] For
> > > > additional commands, e-mail: [hidden email]
> > > >
> > > >
> >
> >
> >
> > --
> > Isaac Jurado
> >
> > "The noblest pleasure is the joy of understanding"
> > Leonardo da Vinci
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email] For additional
> > commands, e-mail: [hidden email]
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


--
Isaac Jurado

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

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Creating task/macro wrappers

Matt Benson-2
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 <[hidden email]> 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) <[hidden email]>
> 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:[hidden email]]
> > > Gesendet: Sonntag, 24. Februar 2019 18:27
> > > An: Ant Users List; [hidden email]
> > > 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 <[hidden email]>
> > > 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 <[hidden email]>
> > > 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: [hidden email] For
> > > > > additional commands, e-mail: [hidden email]
> > > > >
> > > > >
> > >
> > >
> > >
> > > --
> > > Isaac Jurado
> > >
> > > "The noblest pleasure is the joy of understanding"
> > > Leonardo da Vinci
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email] For additional
> > > commands, e-mail: [hidden email]
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
>
>
> --
> Isaac Jurado
>
> "The noblest pleasure is the joy of understanding"
> Leonardo da Vinci
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Creating task/macro wrappers

Isaac Jurado
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 <[hidden email]> 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 <[hidden email]> 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) <[hidden email]>
> > 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:[hidden email]]
> > > > Gesendet: Sonntag, 24. Februar 2019 18:27
> > > > An: Ant Users List; [hidden email]
> > > > 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 <[hidden email]>
> > > > 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 <[hidden email]>
> > > > 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: [hidden email] For
> > > > > > additional commands, e-mail: [hidden email]
> > > > > >
> > > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Isaac Jurado
> > > >
> > > > "The noblest pleasure is the joy of understanding"
> > > > Leonardo da Vinci
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: [hidden email] For additional
> > > > commands, e-mail: [hidden email]
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> >
> >
> > --
> > Isaac Jurado
> >
> > "The noblest pleasure is the joy of understanding"
> > Leonardo da Vinci
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >



--
Isaac Jurado

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

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

AW: Creating task/macro wrappers

Jan Matèrne (jhm)
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:[hidden email]]
> 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 <[hidden email]>
> 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 <[hidden email]>
> 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)
> > > <[hidden email]>
> > > 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:[hidden email]]
> > > > > Gesendet: Sonntag, 24. Februar 2019 18:27
> > > > > An: Ant Users List; [hidden email]
> > > > > 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
> > > > > <[hidden email]>
> > > > > 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
> > > > > > <[hidden email]>
> > > > > 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: [hidden email]
> > > > > > > For additional commands, e-mail: [hidden email]
> > > > > > >
> > > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Isaac Jurado
> > > > >
> > > > > "The noblest pleasure is the joy of understanding"
> > > > > Leonardo da Vinci
> > > > >
> > > > > ---------------------------------------------------------------
> -
> > > > > ----- To unsubscribe, e-mail: [hidden email]
> > > > > For additional commands, e-mail: [hidden email]
> > > >
> > > >
> > > >
> > > > -----------------------------------------------------------------
> -
> > > > --- To unsubscribe, e-mail: [hidden email] For
> > > > additional commands, e-mail: [hidden email]
> > > >
> > >
> > >
> > > --
> > > Isaac Jurado
> > >
> > > "The noblest pleasure is the joy of understanding"
> > > Leonardo da Vinci
> > >
> > > -------------------------------------------------------------------
> -
> > > - To unsubscribe, e-mail: [hidden email] For
> > > additional commands, e-mail: [hidden email]
> > >
> > >
>
>
>
> --
> Isaac Jurado
>
> "The noblest pleasure is the joy of understanding"
> Leonardo da Vinci
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email] For additional
> commands, e-mail: [hidden email]



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]