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 <dipto...@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) <apa...@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:dipto...@gmail.com] > > > Gesendet: Sonntag, 24. Februar 2019 18:27 > > > An: Ant Users List; gudnabr...@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 <gudnabr...@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 <dipto...@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-unsubscr...@ant.apache.org For > > > > > additional commands, e-mail: user-h...@ant.apache.org > > > > > > > > > > > > > > > > > > > > > > -- > > > Isaac Jurado > > > > > > "The noblest pleasure is the joy of understanding" > > > Leonardo da Vinci > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: user-unsubscr...@ant.apache.org For additional > > > commands, e-mail: user-h...@ant.apache.org > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: user-unsubscr...@ant.apache.org > > For additional commands, e-mail: user-h...@ant.apache.org > > > > > -- > Isaac Jurado > > "The noblest pleasure is the joy of understanding" > Leonardo da Vinci > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@ant.apache.org > For additional commands, e-mail: user-h...@ant.apache.org > >