You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by gi...@apache.org on 2018/06/18 20:23:30 UTC

ant git commit: Bz 61241: document use of Nashorn

Repository: ant
Updated Branches:
  refs/heads/master 0228b5456 -> 2b855ea39


Bz 61241: document use of Nashorn

Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/2b855ea3
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/2b855ea3
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/2b855ea3

Branch: refs/heads/master
Commit: 2b855ea39720729cb88e5a8c35b48b15c6b6c8b2
Parents: 0228b54
Author: Gintas Grigelionis <gi...@apache.org>
Authored: Mon Jun 18 22:22:40 2018 +0200
Committer: Gintas Grigelionis <gi...@apache.org>
Committed: Mon Jun 18 22:23:13 2018 +0200

----------------------------------------------------------------------
 manual/Tasks/script.html | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/2b855ea3/manual/Tasks/script.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/script.html b/manual/Tasks/script.html
index 97482f9..2904f9e 100644
--- a/manual/Tasks/script.html
+++ b/manual/Tasks/script.html
@@ -228,6 +228,11 @@ of all files a <code>&lt;fileset/&gt;</code> caught.</p>
       // import statements
       <span style="color:blue">// importPackage(java.io)</span>;
       <span style="color:blue">importClass(java.io.File)</span>;
+      // Nashorn syntax
+      // <span style="color:blue">load("nashorn:mozilla_compat.js");</span>
+      // or
+      // <span style="color:blue">var File = Java.type('java.io.File');</span>
+
 
       // Access to Ant-Properties by their names
       dir      = <span style="color:blue">project</span>.getProperty("fs.dir");
@@ -268,13 +273,18 @@ so <code class="code">java.lang.System</code> can be directly imported
 with <code>importClass</code>/<code>importPackage</code>. For other packages you have to prefix the
 full classified name with <strong>Packages</strong>. For example
 Ant's <code class="code">FileUtils</code> class can be imported
-with <code class="code">importClass(<strong>Packages</strong>.org.apache.tools.ant.util.FileUtils)</code><br/>
-The <code>&lt;script&gt;</code> task populates the Project instance under the
-name <code>project</code>, so we can use that reference. Another way is to use its given name or
-getting its reference from the task itself.<br/>The Project provides methods for accessing and
-setting properties, creating DataTypes and Tasks and much more.<br/>After creating a FileSet object
-we initialize that by calling its set-methods. Then we can use that object like a normal Ant task
-(<code>&lt;copy&gt;</code> for example).<br/>For getting the size of a file we instantiate
+with <code class="code">importClass(<strong>Packages</strong>.org.apache.tools.ant.util.FileUtils)</code></p>
+<p>In Java 8+, you may use the built-in Nashorn JavaScript engine rather than Rhino (which is
+available in Java 7 runtime). Then, use <code>Java.type</code> as import statement for any Java
+class
+or <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/prog_guide/javascript.html#A1147207">the
+compatibility script</a>: <code>load("nashorn:mozilla_compat.js");</code>.</p>
+<p>The <code>&lt;script&gt;</code> task populates the Project instance under the
+name <code class="code">project</code>, so we can use that reference. Another way is to use its
+given name or getting its reference from the task itself. The Project provides methods for accessing
+and setting properties, creating DataTypes and Tasks and much more.<br/>After creating a FileSet
+object we initialize that by calling its set-methods. Then we can use that object like a normal Ant
+task (<code>&lt;copy&gt;</code> for example).<br/>For getting the size of a file we instantiate
 a <code class="code">java.io.File</code>. So we are using normal Java API here.<br/>Finally we use
 the <code>&lt;echo&gt;</code> task for producing the output. The task is not executed by
 its <code class="code">execute()</code> method, because the <code class="code">perform()</code>