ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <peter.rei...@corvil.com>
Subject Re: creating macro instance from a script task?
Date Thu, 13 Nov 2003 17:55:55 GMT
Hi,
I had a quick look at this.
the project.createTask does not set the owningTarget
attribute of the task created.
This causes grief for the created macroinstance object.
Setting the owning target solves the problem.

   <target name="test">
     <script language="javascript"> <![CDATA[

       newTask = project.createTask("my-macro");
       newTask.setOwningTarget(self.getOwningTarget());
       newTask.setDynamicAttribute("host", "bingo");
       project.log("new task is: " + newTask.toString());
       newTask.execute();

     ]]> </script>

I will make a change to set the owning target to a temp target if
there is no owning target for the macroinstance, but
the script should set the target.

Peter

On Thursday 13 November 2003 17:10, Bell, Aaron wrote:
> Hi there
>
> I love the new macrodef task in 1.6. However, how can I invoke one of my
> macrodefs from a script task?
>
> I'm using Javascript. I can create a MacroInstance object... when I
> execute() it though I receive a NullPointerException.
>
> Quick example:
>
> <project name="test" default="test" basedir=".">
>
>   <macrodef name="my-macro">
>     <attribute name="host"/>
>     <sequential>
>       <echo>macro called with host '${host}'</echo>
>     </sequential>
>   </macrodef>
>
>   <target name="test">
>     <script language="javascript"> <![CDATA[
>
>       newTask = project.createTask("my-macro");
>       newTask.setDynamicAttribute("host", "bingo");
>       project.log("new task is: " + newTask.toString());
>       newTask.execute();
>
>     ]]> </script>
>   </target>
> </project>
>
> This returns:
>
> new task is: org.apache.tools.ant.taskdefs.MacroInstance@1b9ce4b
>
> BUILD FAILED
> C:\build\test.xml:16: java.lang.NullPointerException
>
> Does anyone have any ideas?
>
> Many thanks!
> - Aaron
>
> Aaron Bell
> CRM Release Management
> int tel. 5448
> ext tel. (01506) 485448
>
>
> -----------------------------------------------------------------------
> Information in this email may be privileged, confidential and is
> intended exclusively for the addressee.  The views expressed may
> not be official policy, but the personal views of the originator.
> If you have received it in error, please notify the sender by return
> e-mail and delete it from your system.  You should not reproduce,
> distribute, store, retransmit, use or disclose its contents to anyone.
>
> Please note we reserve the right to monitor all e-mail
> communication through our internal and external networks.
> -----------------------------------------------------------------------
>
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message