Browse Source

add a "self" reference for scriptdef

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276682 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 21 years ago
parent
commit
9c40397d18
3 changed files with 28 additions and 8 deletions
  1. +9
    -6
      docs/manual/OptionalTasks/scriptdef.html
  2. +18
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
  3. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDefBase.java

+ 9
- 6
docs/manual/OptionalTasks/scriptdef.html View File

@@ -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
<code>attributes</code> collection.</p>

<p>The name "self" (<i>since Ant 1.6.3</i>) is a pre-defined reference to the script def task instance.
It can be used for logging purposes</p>
<p>The name "project" is a pre-defined reference to the Ant Project. For
more information on writing scripts, please refer to the
<a href="script.html">&lt;script&gt;</a> task
</p>


<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
@@ -133,9 +136,9 @@ of the first fileset.
&lt;element name=&quot;path&quot; type=&quot;path&quot;/&gt;
&lt;![CDATA[

project.log(&quot;Hello from script&quot;);
project.log(&quot;Attribute attr1 = &quot; + attributes.get(&quot;attr1&quot;));
project.log(&quot;First fileset basedir = &quot;
self.log(&quot;Hello from script&quot;);
self.log(&quot;Attribute attr1 = &quot; + attributes.get(&quot;attr1&quot;));
self.log(&quot;First fileset basedir = &quot;
+ elements.get(&quot;fileset&quot;).get(0).getDir(project));

]]&gt;
@@ -159,9 +162,9 @@ and iterates through them
&lt;element name=&quot;fileset&quot; type=&quot;fileset&quot;/&gt;
&lt;![CDATA[
filesets = elements.get(&quot;fileset&quot;);
project.log(&quot;Number of filesets = &quot; + filesets.size());
self.log(&quot;Number of filesets = &quot; + filesets.size());
for (i = 0; i &lt; filesets.size(); ++i) {
project.log(&quot;fileset &quot; + i + &quot; basedir = &quot;
self.log(&quot;fileset &quot; + i + &quot; basedir = &quot;
+ filesets.get(i).getDir(project));
}
]]&gt;
@@ -192,4 +195,4 @@ Script errors are only detected when a script task is actually executed.
Reserved.</p>

</body>
</html>
</html>

+ 18
- 1
src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java View File

@@ -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).


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDefBase.java View File

@@ -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() {


Loading…
Cancel
Save