You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by pe...@apache.org on 2004/07/07 10:32:02 UTC

cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional/script ScriptDefBase.java ScriptDef.java

peterreilly    2004/07/07 01:32:02

  Modified:    docs/manual/OptionalTasks scriptdef.html
               src/main/org/apache/tools/ant/taskdefs/optional/script
                        ScriptDefBase.java ScriptDef.java
  Log:
  add a "self" reference for scriptdef
  
  Revision  Changes    Path
  1.6       +9 -6      ant/docs/manual/OptionalTasks/scriptdef.html
  
  Index: scriptdef.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/OptionalTasks/scriptdef.html,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- scriptdef.html	23 Apr 2004 14:26:47 -0000	1.5
  +++ scriptdef.html	7 Jul 2004 08:32:02 -0000	1.6
  @@ -41,11 +41,14 @@
   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 @@
       &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 @@
       &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 @@
   Reserved.</p>
   
   </body>
  -</html>
  \ No newline at end of file
  +</html>
  
  
  
  1.11      +1 -1      ant/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDefBase.java
  
  Index: ScriptDefBase.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDefBase.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ScriptDefBase.java	9 Mar 2004 16:48:35 -0000	1.10
  +++ ScriptDefBase.java	7 Jul 2004 08:32:02 -0000	1.11
  @@ -44,7 +44,7 @@
        * control to it
        */
       public void execute() {
  -        getScript().executeScript(attributes, nestedElementMap);
  +        getScript().executeScript(attributes, nestedElementMap, this);
       }
   
       private ScriptDef getScript() {
  
  
  
  1.14      +18 -1     ant/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
  
  Index: ScriptDef.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ScriptDef.java	23 Apr 2004 14:18:15 -0000	1.13
  +++ ScriptDef.java	7 Jul 2004 08:32:02 -0000	1.14
  @@ -307,13 +307,30 @@
        * 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);
           runner.addBean("elements", elements);
           runner.addBean("project", getProject());
  +        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);
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org