You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Eric Fetzer <el...@yahoo.com> on 2009/12/30 16:31:12 UTC
Call a Macrodef using a property?
Is there any way to call a macrodef with the name of the macrodef held in a property? Like this (of course this doesn't work):
<project default="main">
<target name="main">
<property name="myProperty" value="myMac"/>
<${myProperty}/>
</target>
<macrodef name="myMac">
<sequential>
<echo message="I made it in"/>
</sequential>
</macrodef>
</project>
Re: Call a Macrodef using a property?
Posted by Eric Fetzer <el...@yahoo.com>.
OK, here's a simple repro for anybody looking to do this:
<project default="main">
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<taskdef name="unset" classname="ise.antelope.tasks.Unset"/>
<target name="main">
<for list="one,two,three,one,three,two,one,one" param="value">
<sequential>
<unset name="myProperty"/>
<property name="myProperty" value="@{value}"/>
<script language="javascript"> <![CDATA[
macroname=project.getProperty("myProperty");
macrotask = project.createTask(macroname);
macrotask.execute();
]]>
</script>
</sequential>
</for>
</target>
<macrodef name="one">
<sequential>
<echo message="I made it to one"/>
</sequential>
</macrodef>
<macrodef name="two">
<sequential>
<echo message="I made it to two"/>
</sequential>
</macrodef>
<macrodef name="three">
<sequential>
<echo message="I made it to three"/>
</sequential>
</macrodef>
</project>
Thanks Antoine!
________________________________
From: Eric Fetzer <el...@yahoo.com>
To: Ant Users List <us...@ant.apache.org>
Sent: Wed, December 30, 2009 10:02:45 AM
Subject: Re: Call a Macrodef using a property?
Sorry, should have looked better at the library dependencies. Needed bsf, logFactory, and js.jar. Thanks again!
________________________________
From: Eric Fetzer <el...@yahoo.com>
To: Ant Users List <us...@ant.apache.org>
Sent: Wed, December 30, 2009 9:49:38 AM
Subject: Re: Call a Macrodef using a property?
Thanks Antoine. I haven't used the script task before. I need a little help on setup though, do you have a link for me. I started by getting bsf.jar in my path. Once I got that out there, it asked for logFactory. I put that in my path, now it's asking for EvaluatorException. I'm guessing there's a simpler way to allow scripting in Ant.
Thanks Again,
Eric
________________________________
From: Antoine Levy Lambert <an...@gmx.de>
To: Ant Users List <us...@ant.apache.org>
Sent: Wed, December 30, 2009 9:01:57 AM
Subject: Re: Call a Macrodef using a property?
Hello Eric,
you would have to embed a scripting language in ant to do this.
Something like (untested)
<script language="javascript"> <![CDATA[
macroname=project.getProperty("myProperty");
macrotask = project.createTask(macroname);
macrotask.execute();
]]> </script>
Look at the corresponding page in the manual (under optional tasks, Script) and at the library dependencies.
Regards,
Antoine
Eric Fetzer wrote:
> Is there any way to call a macrodef with the name of the macrodef held in a property? Like this (of course this doesn't work):
>
> <project default="main">
> <target name="main">
> <property name="myProperty" value="myMac"/>
> <${myProperty}/>
> </target>
> <macrodef name="myMac">
> <sequential>
> <echo message="I made it in"/>
> </sequential>
> </macrodef>
> </project>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Call a Macrodef using a property?
Posted by Eric Fetzer <el...@yahoo.com>.
Sorry, should have looked better at the library dependencies. Needed bsf, logFactory, and js.jar. Thanks again!
________________________________
From: Eric Fetzer <el...@yahoo.com>
To: Ant Users List <us...@ant.apache.org>
Sent: Wed, December 30, 2009 9:49:38 AM
Subject: Re: Call a Macrodef using a property?
Thanks Antoine. I haven't used the script task before. I need a little help on setup though, do you have a link for me. I started by getting bsf.jar in my path. Once I got that out there, it asked for logFactory. I put that in my path, now it's asking for EvaluatorException. I'm guessing there's a simpler way to allow scripting in Ant.
Thanks Again,
Eric
________________________________
From: Antoine Levy Lambert <an...@gmx.de>
To: Ant Users List <us...@ant.apache.org>
Sent: Wed, December 30, 2009 9:01:57 AM
Subject: Re: Call a Macrodef using a property?
Hello Eric,
you would have to embed a scripting language in ant to do this.
Something like (untested)
<script language="javascript"> <![CDATA[
macroname=project.getProperty("myProperty");
macrotask = project.createTask(macroname);
macrotask.execute();
]]> </script>
Look at the corresponding page in the manual (under optional tasks, Script) and at the library dependencies.
Regards,
Antoine
Eric Fetzer wrote:
> Is there any way to call a macrodef with the name of the macrodef held in a property? Like this (of course this doesn't work):
>
> <project default="main">
> <target name="main">
> <property name="myProperty" value="myMac"/>
> <${myProperty}/>
> </target>
> <macrodef name="myMac">
> <sequential>
> <echo message="I made it in"/>
> </sequential>
> </macrodef>
> </project>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Call a Macrodef using a property?
Posted by Eric Fetzer <el...@yahoo.com>.
Thanks Antoine. I haven't used the script task before. I need a little help on setup though, do you have a link for me. I started by getting bsf.jar in my path. Once I got that out there, it asked for logFactory. I put that in my path, now it's asking for EvaluatorException. I'm guessing there's a simpler way to allow scripting in Ant.
Thanks Again,
Eric
________________________________
From: Antoine Levy Lambert <an...@gmx.de>
To: Ant Users List <us...@ant.apache.org>
Sent: Wed, December 30, 2009 9:01:57 AM
Subject: Re: Call a Macrodef using a property?
Hello Eric,
you would have to embed a scripting language in ant to do this.
Something like (untested)
<script language="javascript"> <![CDATA[
macroname=project.getProperty("myProperty");
macrotask = project.createTask(macroname);
macrotask.execute();
]]> </script>
Look at the corresponding page in the manual (under optional tasks, Script) and at the library dependencies.
Regards,
Antoine
Eric Fetzer wrote:
> Is there any way to call a macrodef with the name of the macrodef held in a property? Like this (of course this doesn't work):
>
> <project default="main">
> <target name="main">
> <property name="myProperty" value="myMac"/>
> <${myProperty}/>
> </target>
> <macrodef name="myMac">
> <sequential>
> <echo message="I made it in"/>
> </sequential>
> </macrodef>
> </project>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org
Re: Call a Macrodef using a property?
Posted by Antoine Levy Lambert <an...@gmx.de>.
Hello Eric,
you would have to embed a scripting language in ant to do this.
Something like (untested)
<script language="javascript"> <![CDATA[
macroname=project.getProperty("myProperty");
macrotask = project.createTask(macroname);
macrotask.execute();
]]> </script>
Look at the corresponding page in the manual (under optional tasks,
Script) and at the library dependencies.
Regards,
Antoine
Eric Fetzer wrote:
> Is there any way to call a macrodef with the name of the macrodef held in a property? Like this (of course this doesn't work):
>
> <project default="main">
> <target name="main">
> <property name="myProperty" value="myMac"/>
> <${myProperty}/>
> </target>
> <macrodef name="myMac">
> <sequential>
> <echo message="I made it in"/>
> </sequential>
> </macrodef>
> </project>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org