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]