AW: How to create a task associated a target

Jan Matèrne (jhm) <[email protected]>
Newsgroups gmane.comp.jakarta.ant.user
Message-ID <002101d19f8d$58087750$081965f0$@de>
Try 
            task.setOwningTarget( self.getOwningTarget() );

'self' is referencing the <script> task and the new created instance will get its owning target.


Jan


> -----Ursprüngliche Nachricht-----
> Von: Al Le [mailto:[email protected]]
> Gesendet: Dienstag, 26. April 2016 08:53
> An: [email protected]
> Betreff: How to create a task associated a target
> 
> Hello,
> 
> in my ant script, I do the following:
> 
> 1. there is a target "calledTarget"
> 
> 2. there is a task "macroTask", defined via "macrodef". This task
> contains in its body a call to "calledTarget" (via "antcall").
> 
> 3. there is a target "mainTarget" which contains a task "script"
> (javascript). In this script, I create an instance of macroTask and
> then execute it.
> 
> 
> Here's the picture as an outline:
> 
> <project default="mainTarget">
> 
>     <target name="mainTarget">
>         <script language="javascript">
>             var task = project.createTask("macroTask");
>             //
> task.setOwningTarget(project.getTargets().get("mainTarget")); // This
> must be done to avoid NPE
>             task.perform();
>         </script>
>     </target>
> 
>     <macrodef name="macroTask">
>         <sequential>
>             <antcall target="calledTarget"/>
>         </sequential>
>     </macrodef>
> 
>     <target name="calledTarget">
>         <!-- Do something -->
>     </target>
> 
> </project>
> 
> When I run the script, I get a NullPointerException. I found out that
> it occurs in Ant.java, at the line "if
> (getOwningTarget().getName().equals("")) {" (line number about 380,
> depending on the ant version).
> 
> OK, it's clear that the owning target is not set for the task because
> the task is created via the project (and not via a target).
> 
> Now I have some questions:
> 
> 1. Is it possible to create a task so that it "automatically" gets
> associated with a task?
> 
> 2. Is it possible to find out the name of the current target (or even
> get the current target as an object) in a script? So that I don't have
> to write "mainTarget" in the call to "setOwningTarget" in the script
> above, but rather can do something like getCurrentTarget().
> 
> 
> The code above is just an outline. In the real script, I have a rather
> complicated logics in the javascript, and from the script I set some
> project properties and call the macro which passes the properties to
> the called target (to call the target is my real goal; the macroTask is
> just passing it through).
> 
> Thank you
> AL
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected] For additional
> commands, e-mail: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.