ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Fetzer <elstonk...@yahoo.com>
Subject Re: Call a Macrodef using a property?
Date Wed, 30 Dec 2009 17:19:09 GMT
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 <elstonkers@yahoo.com>
To: Ant Users List <user@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 <elstonkers@yahoo.com>
To: Ant Users List <user@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 <antoine@gmx.de>
To: Ant Users List <user@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


      
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message