You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Felix Dorner <FD...@zed.com> on 2009/03/24 13:35:40 UTC

Dynamic macro dispatch.

Hi Ant users,

I have three macros: a, b, c, and a property 'x'. Is there a way to execute the macro ${x}, i.e. a if ${x}=a, b if ${x}=b, c if ${x}=c, (fail otherwise) with ant core? Something like <macroExec macro="${x}"/>

Thanks,
Felix

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


RE: Dynamic macro dispatch.

Posted by Martin Gainty <mg...@hotmail.com>.

_________________________________________________________________
Get quick access to your favorite MSN content with Internet Explorer 8. 
http://ie8.msn.com/microsoft/internet-explorer-8/en-us/ie8.aspx?ocid=B037MSN55C0701A
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: Dynamic macro dispatch.

Posted by Felix Dorner <FD...@zed.com>.

Well I assume it would be easy to write a contributed task 
similar to the one that I describe above. The only thing I'd
need to know is how to execute a macro with a given name from
within a Task implementation...

> I understand what you mean now. You want all possible values 
> to be taken care of. Not sure if I can think of anything 
> off-hand that would do that.


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


Re: Dynamic macro dispatch.

Posted by David Corley <da...@gmail.com>.
I understand what you mean now. You want all possible values to be taken
care of. Not sure if I can think of anything off-hand that would do that.

On Tue, Mar 24, 2009 at 1:30 PM, Felix Dorner <FD...@zed.com> wrote:

> Hey David,
>
> Thanks for your suggestions.
>
> > Well the only reason I specified the method below is that you
> > asked what could be done with ant-core.
>
> > However, if you're able to use ant-contrib, then you can
> > simplify it a little more using the ant-contrib <if> task.
>
> Of course this is a possibility, but it would assume I *know*
> all possible values that the property would ever take. (I know,
> I only spoke of a,b,c, but of course I'm trying to abstract as
> much as possible..
>
> And every time someone downstream wants to add a new possible
> property and a corresponding macro definition, he would
> need to write me an email and ask me to modify that piece
> of code to include his value.
>
> <macroExec name="${x}"/> would just pretty much nail it down.
>
> Felix
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


-- 
"To be or not to be. That's not really a question." - Jean-Luc Godard

RE: Dynamic macro dispatch.

Posted by Felix Dorner <FD...@zed.com>.
Hey David,

Thanks for your suggestions.

> Well the only reason I specified the method below is that you
> asked what could be done with ant-core.

> However, if you're able to use ant-contrib, then you can
> simplify it a little more using the ant-contrib <if> task.

Of course this is a possibility, but it would assume I *know*
all possible values that the property would ever take. (I know,
I only spoke of a,b,c, but of course I'm trying to abstract as
much as possible..

And every time someone downstream wants to add a new possible
property and a corresponding macro definition, he would
need to write me an email and ask me to modify that piece
of code to include his value.

<macroExec name="${x}"/> would just pretty much nail it down.

Felix

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


Re: Dynamic macro dispatch.

Posted by David Corley <da...@gmail.com>.
Well the only reason I specified the method below is that you asked what
could be done with ant-core.
I don't think you can do much more than what I've suggested.
However, if you're able to use ant-contrib, then you can simplify it a
little more using the ant-contrib <if> task.
So:
<if>
<equals arg1="${x}" arg2="a"/>
<then>
<macroA/>
</then>
<elseif>
<equals arg1="${x}" arg2="b"/>
<then>
<macroB/>
 </then>
</elseif>
<elseif>
<equals arg1="${x}" arg2="c"/>
<then>
<macroC/>
 </then>
 </elseif>
</if>
As I said before, this all depends on whether you can use the ant-contrib
classes.
http://ant-contrib.sourceforge.net/

Regards,
Dave



On Tue, Mar 24, 2009 at 1:10 PM, Felix Dorner <FD...@zed.com> wrote:

>
> This approach would make the macros obsolete. Instead I
> would move the macro code into the targets you mention, and could do
> <antcall target="${x}">
>
> This is actually how my build file currently looks like. But I
> want to switch to macros as they are more lightweight and controllable.
>
>
> Felix
>
> > You'd probably be better have individual properties as flags
> > for each macro.
> > So something like:
> > <condition property="flagA">
> > <equals arg1="${x} arg2="a"/>
> > </condition>
> > <condition property="flabB">
> > <equals arg1="${x} arg2="b"/>
> >  </condition>
> > <condition property="flagC">
> > <equals arg1="${x} arg2="c"/>
> >  </condition>
> > <target name="RunMacroA if="flagA">
> > <macroA/>
> > </target>
> > <target name="RunMacroB if="flagB">
> > <macroB/>
> >  </target>
> > <target name="RunMacroC if="flagC">
> > <macroC/>
> >  </target>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


-- 
"To be or not to be. That's not really a question." - Jean-Luc Godard

RE: Dynamic macro dispatch.

Posted by Felix Dorner <FD...@zed.com>.
This approach would make the macros obsolete. Instead I
would move the macro code into the targets you mention, and could do
<antcall target="${x}">

This is actually how my build file currently looks like. But I
want to switch to macros as they are more lightweight and controllable.


Felix

> You'd probably be better have individual properties as flags
> for each macro.
> So something like:
> <condition property="flagA">
> <equals arg1="${x} arg2="a"/>
> </condition>
> <condition property="flabB">
> <equals arg1="${x} arg2="b"/>
>  </condition>
> <condition property="flagC">
> <equals arg1="${x} arg2="c"/>
>  </condition>
> <target name="RunMacroA if="flagA">
> <macroA/>
> </target>
> <target name="RunMacroB if="flagB">
> <macroB/>
>  </target>
> <target name="RunMacroC if="flagC">
> <macroC/>
>  </target>

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


Re: Dynamic macro dispatch.

Posted by David Corley <da...@gmail.com>.
You'd probably be better have individual properties as flags for each macro.
So something like:
<condition property="flagA">
<equals arg1="${x} arg2="a"/>
</condition>
<condition property="flabB">
<equals arg1="${x} arg2="b"/>
 </condition>
<condition property="flagC">
<equals arg1="${x} arg2="c"/>
 </condition>
<target name="RunMacroA if="flagA">
<macroA/>
</target>
<target name="RunMacroB if="flagB">
<macroB/>
 </target>
<target name="RunMacroC if="flagC">
<macroC/>
 </target>

So you set individual properties depending on the value of ${x}. The
individual properties can then be used to determine whether particular
targets containing each macro are run.



On Tue, Mar 24, 2009 at 12:35 PM, Felix Dorner <FD...@zed.com> wrote:

> Hi Ant users,
>
> I have three macros: a, b, c, and a property 'x'. Is there a way to execute
> the macro ${x}, i.e. a if ${x}=a, b if ${x}=b, c if ${x}=c, (fail otherwise)
> with ant core? Something like <macroExec macro="${x}"/>
>
> Thanks,
> Felix
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>


-- 
"To be or not to be. That's not really a question." - Jean-Luc Godard

RE: Dynamic macro dispatch.

Posted by Felix Dorner <FD...@zed.com>.
Heya,

> You can check out the various macroforeach tasks 
> around to get an idea of what you need to do. 

This hint lead me to AntExtra, which provides a
<call> task that accepts makro names. 

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


Re: Dynamic macro dispatch.

Posted by Brian Pontarelli <br...@pontarelli.com>.
You can invoke macros easily from Java or Groovy. Groovy is easier,  
but if you want to write a task, it isn't too difficult. You can check  
out the various macroforeach tasks around to get an idea of what you  
need to do. Or just invoke it from groovy like:

<groovy>
ant."${x}"(...)
</groovy>

Pretty certain that is the correct syntax, but you might want to  
verify that in the groovy docs.
-bp


On Mar 24, 2009, at 6:35 AM, Felix Dorner wrote:

> Hi Ant users,
>
> I have three macros: a, b, c, and a property 'x'. Is there a way to  
> execute the macro ${x}, i.e. a if ${x}=a, b if ${x}=b, c if ${x}=c,  
> (fail otherwise) with ant core? Something like <macroExec macro="$ 
> {x}"/>
>
> Thanks,
> Felix
>
> ---------------------------------------------------------------------
> 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