ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peterrei...@apache.org
Subject cvs commit: ant/docs/manual/OptionalTasks script.html
Date Wed, 02 Mar 2005 19:38:45 GMT
peterreilly    2005/03/02 11:38:45

  Modified:    docs/manual/OptionalTasks Tag: ANT_16_BRANCH script.html
  Log:
  sync
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.13.2.6  +62 -13    ant/docs/manual/OptionalTasks/script.html
  
  Index: script.html
  ===================================================================
  RCS file: /home/cvs/ant/docs/manual/OptionalTasks/script.html,v
  retrieving revision 1.13.2.5
  retrieving revision 1.13.2.6
  diff -u -r1.13.2.5 -r1.13.2.6
  --- script.html	19 Nov 2004 09:10:04 -0000	1.13.2.5
  +++ script.html	2 Mar 2005 19:38:45 -0000	1.13.2.6
  @@ -1,7 +1,7 @@
   <html>
   
   <head>
  -<meta http-equiv="Content-Language" content="en-us">
  +<meta http-equiv="Content-Language" content="en-us"></meta>
   <title>Script Task</title>
   <link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
   </head>
  @@ -20,14 +20,14 @@
   valid Java identifiers, that is).
   The name "project" is a pre-defined reference to the Project, which can be
   used instead of the project name. The name "self" is a pre-defined reference to the actual
  -&lt;script&gt;-Task instance.<br>From these objects you have access to the
Ant Java API, see the
  +<code>&lt;script&gt;</code>-Task instance.<br/>From these objects
you have access to the Ant Java API, see the
   <a href="../api/index.html">JavaDoc</a> (especially for
   <a href="../api/org/apache/tools/ant/Project.html">Project</a> and
   <a href="../api/org/apache/tools/ant/taskdefs/optional/Script.html">Script</a>)
for more information.</p>
   <p>If you are using JavaScript a good resource is <a target="_blank" href="http://www.mozilla.org/rhino/doc.html">
   http://www.mozilla.org/rhino/doc.html</a> as we are using their JavaScript interpreter.</p>
   <p>Scripts can do almost anything a task written in Java could do.</p>
  -<p>Rhino provides a special construct - the <i>JavaAdapter</i>. Whith
that you can
  +<p>Rhino provides a special construct - the <i>JavaAdapter</i>. With
that you can
   create an object which implements several interfaces, extends classes and for which you
   can overwrite methods. Because this is an undocumented feature (yet), here is the link
   to an explanation: <a href="http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&newwindow=1&frame=right&th=610d2db45c0756bd&seekm=391EEC3C.5236D929%40yahoo.com#link2">
  @@ -56,31 +56,80 @@
     </tr>
   </table>
   <h3>Examples</h3>
  +The following snippet shows use of five different languages:
  +  <blockquote><pre>
  +    &lt;property name="message" value="Hello world"/&gt;
  +
  +    &lt;script language="groovy"&gt;
  +      println("message is " + message)
  +    &lt;/script&gt;
  +
  +    &lt;script language="beanshell"&gt;
  +      System.out.println("message is " + message);
  +    &lt;/script&gt;
  +
  +    &lt;script language="judoscript"&gt;
  +        println 'message is ', message
  +    &lt;/script&gt;
  +
  +    &lt;script language="ruby"&gt;
  +        print 'message is ', $message, "\n"
  +    &lt;/script&gt;
  +
  +    &lt;script language="jython"&gt;
  +print "message is %s" % message
  +    &lt;/script&gt;
  +</pre>
  +  </blockquote>
  +  <p>
  +  Note that for the <i>jython</i> example, the script contents <b>must</b>
  +  start on the first column.
  +  </p>
  +  <p>
  +    The following script shows a little more complicated jruby example:
  +  </p>
  +  <blockquote><pre>
  +&lt;script language="ruby"&gt;
  +  xmlfiles = Dir.new(".").entries.delete_if { |i| ! (i =~ /\.xml$/) }
  +  xmlfiles.sort.each { |i| $self.log(i) }
  +&lt;/script&gt;
  +</pre>
  +  </blockquote>
  +  <p>
  +    The same example in groovy is:
  +  </p>
  +  <blockquote><pre>
  +&lt;script language="groovy"&gt;
  +  xmlfiles = new java.io.File(".").listFiles().findAll{ it =~ "\.xml$"}
  +  xmlfiles.sort().each { self.log(it.toString())}
  +&lt;/script&gt;
  +</pre>
  +  </blockquote>
  +  <p>
  +    The following script uses javascript to create a number of
  +    echo tasks and execute them.
  +  </p>
   <blockquote><pre>
   &lt;project name=&quot;squares&quot; default=&quot;main&quot; basedir=&quot;.&quot;&gt;
   
  -  &lt;target name=&quot;setup&quot;&gt;
  +  &lt;target name=&quot;main&quot;&gt;
   
       &lt;script language=&quot;javascript&quot;&gt; &lt;![CDATA[
   
         for (i=1; i&lt;=10; i++) {
           echo = squares.createTask(&quot;echo&quot;);
  -        main.addTask(echo);
           echo.setMessage(i*i);
  +        echo.perform();
         }
   
       ]]&gt; &lt;/script&gt;
   
     &lt;/target&gt;
   
  -  &lt;target name=&quot;main&quot; depends=&quot;setup&quot;/&gt;
  -
   &lt;/project&gt;
   </pre></blockquote>
   <p>generates</p>
   <blockquote><pre>
  -setup:
  -
   main:
   1
   4
  @@ -184,13 +233,13 @@
     &lt;/target&gt;
   &lt;/project&gt;
   </pre></blockquote>
  -<p>We want to use the Java API. Because we donīt want always typing the package signature
  +<p>We want to use the Java API. Because we don't want always typing the package signature
   we do an import. Rhino knows two different methods for import statements: one for packages
   and one for a single class. By default only the <i>java</i> packages are available,
so
   <i>java.lang.System</i> can be directly imported with <code>importClass/importPackage</code>.
  -For other packages you have to prefix the full classified name with <i>Package</i>.
  -For example antīs <i>FileUtil</i> class can be imported with
  -<code>importClass(<b>Package</b>.org.apache.tools.ant.util.FileUtils)</code>
  +For other packages you have to prefix the full classified name with <i>Packages</i>.
  +For example Ant's <i>FileUtils</i> class can be imported with
  +<code>importClass(<b>Packages</b>.org.apache.tools.ant.util.FileUtils)</code>
   <br>
   The <code>&lt;script&gt;</code> task populates the Project instance
under
   the name <i>project</i>, so we can use that reference. Another way is to use
its given name
  
  
  

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


Mime
View raw message