diff --git a/docs/manual/OptionalTasks/scriptdef.html b/docs/manual/OptionalTasks/scriptdef.html index 47de9b5c2..396bc1e5f 100755 --- a/docs/manual/OptionalTasks/scriptdef.html +++ b/docs/manual/OptionalTasks/scriptdef.html @@ -41,11 +41,14 @@ lowercase names, so even if you use name="SomeAttribute", you'll have to use "someattribute" to retrieve the attribute's value from the attributes collection.

+

The name "self" (since Ant 1.6.3) is a pre-defined reference to the script def task instance. + It can be used for logging purposes

The name "project" is a pre-defined reference to the Ant Project. For more information on writing scripts, please refer to the <script> task

+

Parameters

@@ -133,9 +136,9 @@ of the first fileset. <element name="path" type="path"/> <![CDATA[ - project.log("Hello from script"); - project.log("Attribute attr1 = " + attributes.get("attr1")); - project.log("First fileset basedir = " + self.log("Hello from script"); + self.log("Attribute attr1 = " + attributes.get("attr1")); + self.log("First fileset basedir = " + elements.get("fileset").get(0).getDir(project)); ]]> @@ -159,9 +162,9 @@ and iterates through them <element name="fileset" type="fileset"/> <![CDATA[ filesets = elements.get("fileset"); - project.log("Number of filesets = " + filesets.size()); + self.log("Number of filesets = " + filesets.size()); for (i = 0; i < filesets.size(); ++i) { - project.log("fileset " + i + " basedir = " + self.log("fileset " + i + " basedir = " + filesets.get(i).getDir(project)); } ]]> @@ -192,4 +195,4 @@ Script errors are only detected when a script task is actually executed. Reserved.

- \ No newline at end of file + diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java b/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java index a4e1f08f9..aed0c10a4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java @@ -307,8 +307,8 @@ public class ScriptDef extends DefBase { * Execute the script. * * @param attributes collection of attributes - * * @param elements a list of nested element values. + * @deprecated use executeScript(attribute, elements, instance) instead */ public void executeScript(Map attributes, Map elements) { runner.addBean("attributes", attributes); @@ -317,6 +317,23 @@ public class ScriptDef extends DefBase { runner.executeScript("scriptdef_" + name); } + /** + * Execute the script. + * This is called by the script instance to execute the script for this + * definition. + * + * @param attributes collection of attributes + * @param elements a list of nested element values. + * @param instance the script instance + */ + public void executeScript(Map attributes, Map elements, ScriptDefBase instance) { + runner.addBean("attributes", attributes); + runner.addBean("elements", elements); + runner.addBean("project", getProject()); + runner.addBean("self", self); + runner.executeScript("scriptdef_" + name); + } + /** * Defines the language (required). diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDefBase.java b/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDefBase.java index e057b8ffa..471e3540a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDefBase.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDefBase.java @@ -44,7 +44,7 @@ public class ScriptDefBase extends Task implements DynamicConfigurator { * control to it */ public void execute() { - getScript().executeScript(attributes, nestedElementMap); + getScript().executeScript(attributes, nestedElementMap, this); } private ScriptDef getScript() {