You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2017/02/20 16:58:53 UTC
[03/12] ant git commit: Enhanced JavaxScriptRunner, Junit, docs,
Javadoc
Enhanced JavaxScriptRunner, Junit, docs, Javadoc
JavaxScriptRunner:
- Better compiled script reference name to avoid reference name
collision, project wide : execName + ".compiled." +
getScript().hashCode() + "." + getProject().hashCode();
ScriptDef:
- Fixed Javadoc + use of 3rd person
[(oracle style
guideline)](http://www.oracle.com/technetwork/articles/java/index-137868.html#styleguide)
Task manual: documentation for `encoding` and `compiled` options.
- `encoding` : script.html, scriptdef.html, conditions.html,
selectors.html, mapper.html, filterchain.html
- `compiled` : scriptdef.html
Added source file `encoding` option on:
- org.apache.tools.ant.taskdefs.optional.Script
- org.apache.tools.ant.types.optional.AbstractScriptComponent
(inherited by ScriptCondition, ScriptMapper)
- org.apache.tools.ant.types.optional.ScriptFilter
- org.apache.tools.ant.types.optional.ScriptSelector
Test units :
- org.apache.tools.ant.taskdefs.optional.script.ScriptDefTest,
script.xml : src + encoding
- org.apache.tools.ant.taskdefs.optional.RhinoScriptDefTest,
scriptdef.xml : src + encoding, compiled
- new file: src/etc/testcases/taskdefs/optional/script/heavy-script.js
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/ea709175
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/ea709175
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/ea709175
Branch: refs/heads/master
Commit: ea7091756bb65ba5667ac8246efba6ac3f04322e
Parents: 5710193
Author: pyxide <op...@gmail.com>
Authored: Fri Jan 20 16:33:35 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Feb 20 17:41:37 2017 +0100
----------------------------------------------------------------------
manual/Tasks/conditions.html | 5 ++
manual/Tasks/script.html | 7 +-
manual/Tasks/scriptdef.html | 14 ++++
manual/Types/filterchain.html | 5 ++
manual/Types/mapper.html | 5 ++
manual/Types/selectors.html | 5 ++
src/etc/testcases/taskdefs/optional/script.xml | 22 +++++
.../taskdefs/optional/script/heavy-script.js | 68 ++++++++++++++++
.../taskdefs/optional/script/scriptdef.xml | 84 ++++++++++++++++++++
.../ant/taskdefs/optional/script/ScriptDef.java | 38 ++++-----
.../ant/util/optional/JavaxScriptRunner.java | 18 ++---
.../ant/taskdefs/optional/RhinoScriptTest.java | 22 +++++
.../taskdefs/optional/script/ScriptDefTest.java | 41 ++++++++++
13 files changed, 303 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/manual/Tasks/conditions.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/conditions.html b/manual/Tasks/conditions.html
index 08d0bcc..895da54 100644
--- a/manual/Tasks/conditions.html
+++ b/manual/Tasks/conditions.html
@@ -537,6 +537,11 @@ an explanation of scripts and dependencies.
<td valign="top" align="center">No</td>
</tr>
<tr>
+ <td valign="top">encoding</td>
+ <td valign="top">The encoding of the script source. <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to default JVM encoding</td>
+ </tr>
+ <tr>
<td valign="top">setbeans</td>
<td valign="top">whether to have all properties, references and targets as
global variables in the script. <em>since Ant 1.8.0</em></td>
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/manual/Tasks/script.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/script.html b/manual/Tasks/script.html
index fb00822..7a56eec 100644
--- a/manual/Tasks/script.html
+++ b/manual/Tasks/script.html
@@ -103,6 +103,11 @@ different location values.</p>
<td valign="top" align="center">No</td>
</tr>
<tr>
+ <td valign="top">encoding</td>
+ <td valign="top">The encoding of the script as a file. <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to default JVM encoding</td>
+ </tr>
+ <tr>
<td valign="top">setbeans</td>
<td valign="top">
This attribute controls whether to set variables for
@@ -282,7 +287,7 @@ filesizes of all files a <code><fileset/></code> caught.</p>
// Access to Ant-Properties by their names
dir = <font color=blue>project</font>.getProperty("fs.dir");
includes = <font color=blue>MyProject</font>.getProperty("fs.includes");
- excludes = <font color=blue>self.getProject()</font> .<font color=blue>getProperty("fs.excludes")</font>;
+ excludes = <font color=blue>self.getProject()</font>.<font color=blue>getProperty("fs.excludes")</font>;
// Create a <fileset dir="" includes=""/>
fs = project.<font color=blue>createDataType("fileset")</font>;
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/manual/Tasks/scriptdef.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/scriptdef.html b/manual/Tasks/scriptdef.html
index 38c3fff..de601a5 100644
--- a/manual/Tasks/scriptdef.html
+++ b/manual/Tasks/scriptdef.html
@@ -116,6 +116,20 @@ more information on writing scripts, please refer to the
<td valign="top" align="center">No</td>
</tr>
<tr>
+ <td valign="top">encoding</td>
+ <td valign="top">The encoding of the script as a file. <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to default JVM encoding</td>
+ </tr>
+ <tr>
+ <td valign="top">compiled</td>
+ <td valign="top">If true, the script is compiled before the first
+ evaluation for faster multiple executions, on the condition that the <em>manager</em> is "javax" and the
+ target engine implements <code>javax.script.Compilable</code>.
+ Note that the <code>bsf</code> manager may automatically compiles the script.
+ <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to false</td>
+ </tr>
+ <tr>
<td valign="top">uri</td>
<td valign="top">
The XML namespace uri that this definition should live in.
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/manual/Types/filterchain.html
----------------------------------------------------------------------
diff --git a/manual/Types/filterchain.html b/manual/Types/filterchain.html
index 90dd74b..1496816 100644
--- a/manual/Types/filterchain.html
+++ b/manual/Types/filterchain.html
@@ -1566,6 +1566,11 @@ Must be a supported Apache BSF or JSR 223 language</td>
<td vAlign=top align="center">No</td>
</tr>
<tr>
+ <td valign="top">encoding</td>
+ <td valign="top">The encoding of the script as a file. <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to default JVM encoding</td>
+ </tr>
+ <tr>
<td valign="top">setbeans</td>
<td valign="top">whether to have all properties, references and targets as
global variables in the script. <em>since Ant 1.8.0</em></td>
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/manual/Types/mapper.html
----------------------------------------------------------------------
diff --git a/manual/Types/mapper.html b/manual/Types/mapper.html
index 5aff311..f6bc76d 100644
--- a/manual/Types/mapper.html
+++ b/manual/Types/mapper.html
@@ -806,6 +806,11 @@ an explanation of scripts and dependencies.
<td align="center" valign="top">No</td>
</tr>
<tr>
+ <td valign="top">encoding</td>
+ <td valign="top">The encoding of the script as a file. <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to default JVM encoding</td>
+ </tr>
+ <tr>
<td valign="top">setbeans</td>
<td valign="top">whether to have all properties, references and targets as
global variables in the script. <em>since Ant 1.8.0</em></td>
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/manual/Types/selectors.html
----------------------------------------------------------------------
diff --git a/manual/Types/selectors.html b/manual/Types/selectors.html
index a791380..6a080cb 100644
--- a/manual/Types/selectors.html
+++ b/manual/Types/selectors.html
@@ -1108,6 +1108,11 @@
<td valign="top" align="center">no</td>
</tr>
<tr>
+ <td valign="top">encoding</td>
+ <td valign="top">The encoding of the script as a file. <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to default JVM encoding</td>
+ </tr>
+ <tr>
<td valign="top">setbeans</td>
<td valign="top">whether to have all properties, references and targets as
global variables in the script.</td>
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/etc/testcases/taskdefs/optional/script.xml
----------------------------------------------------------------------
diff --git a/src/etc/testcases/taskdefs/optional/script.xml b/src/etc/testcases/taskdefs/optional/script.xml
index 841f70d..c098289 100644
--- a/src/etc/testcases/taskdefs/optional/script.xml
+++ b/src/etc/testcases/taskdefs/optional/script.xml
@@ -17,6 +17,10 @@
-->
<project name="testproject" default="def" basedir=".">
+ <import file="../../buildfiletest-base.xml"/>
+
+ <property name="root" location="../../../../.."/>
+
<target name="def">
<fail>This build-file is intended to be run from the test cases</fail>
</target>
@@ -43,4 +47,22 @@
]]></script>
</target>
+ <target name="useSrcAndEncoding">
+ <mkdir dir="${output}" />
+ <property name="useSrcAndEncoding.encoding" value="UTF-8"/>
+ <property name="useSrcAndEncoding.reader.encoding" value="${useSrcAndEncoding.encoding}"
+ description="Set a different encoding to raise a failure (ex. ISO-8859-1)" />
+ <property name="useSrcAndEncoding.file" location="${output}/script.useSrcAndEncoding.js"/>
+ <property name="useSrcAndEncoding.expectedProp" value="eacute [é]" />
+
+ <echo file="${useSrcAndEncoding.file}" encoding="${useSrcAndEncoding.encoding}"
+ message="project.setNewProperty('useSrcAndEncoding.prop', '${useSrcAndEncoding.expectedProp}');"/>
+
+ <script language="javascript" src="${useSrcAndEncoding.file}" encoding="${useSrcAndEncoding.reader.encoding}"/>
+ <condition property="useSrcAndEncoding.testOK" >
+ <equals arg1="${useSrcAndEncoding.expectedProp}" arg2="${useSrcAndEncoding.prop}" />
+ </condition>
+ <fail message="expected <${useSrcAndEncoding.expectedProp}> but was <${useSrcAndEncoding.prop}>" unless="useSrcAndEncoding.testOK" />
+ </target>
+
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/etc/testcases/taskdefs/optional/script/heavy-script.js
----------------------------------------------------------------------
diff --git a/src/etc/testcases/taskdefs/optional/script/heavy-script.js b/src/etc/testcases/taskdefs/optional/script/heavy-script.js
new file mode 100644
index 0000000..4033add
--- /dev/null
+++ b/src/etc/testcases/taskdefs/optional/script/heavy-script.js
@@ -0,0 +1,68 @@
+
+var functions = [
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+];
+
+var v = 'a';
+for(var i in functions) {
+ v = functions[i](v);
+}
+
+var echo = project.createTask("echo");
+echo.setMessage("heavy-script done");
+echo.perform();
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/etc/testcases/taskdefs/optional/script/scriptdef.xml
----------------------------------------------------------------------
diff --git a/src/etc/testcases/taskdefs/optional/script/scriptdef.xml b/src/etc/testcases/taskdefs/optional/script/scriptdef.xml
index 0d051ea..3b54e3e 100644
--- a/src/etc/testcases/taskdefs/optional/script/scriptdef.xml
+++ b/src/etc/testcases/taskdefs/optional/script/scriptdef.xml
@@ -17,6 +17,10 @@
-->
<project name="testproject" default="def" basedir=".">
+ <import file="../../../buildfiletest-base.xml"/>
+
+ <property name="root" location="../../../../../.."/>
+
<target name="def">
<fail>This build-file is intended to be run from the test cases</fail>
</target>
@@ -141,5 +145,85 @@
</scripttest>
</target>
+ <target name="useBeanshell">
+ <script language="beanshell"><![CDATA[
+ self.log("I'm here", org.apache.tools.ant.Project.MSG_INFO);
+ ]]></script>
+ </target>
+
+ <target name="useSrcAndEncoding">
+ <mkdir dir="${output}" />
+ <property name="useSrcAndEncoding.encoding" value="UTF-8"/>
+ <property name="useSrcAndEncoding.reader.encoding" value="${useSrcAndEncoding.encoding}"
+ description="Set a different encoding to raise a failure (ex. ISO-8859-1)" />
+ <property name="useSrcAndEncoding.file" location="${output}/script.useSrcAndEncoding.js"/>
+ <property name="useSrcAndEncoding.expectedProp" value="eacute [é]" />
+
+ <echo file="${useSrcAndEncoding.file}" encoding="${useSrcAndEncoding.encoding}"
+ message="project.setNewProperty('useSrcAndEncoding.prop', '${useSrcAndEncoding.expectedProp}');"/>
+
+ <scriptdef name="useSrcAndEncoding" language="javascript" src="${useSrcAndEncoding.file}" encoding="${useSrcAndEncoding.reader.encoding}"/>
+ <useSrcAndEncoding/>
+
+ <condition property="useSrcAndEncoding.testOK" >
+ <equals arg1="${useSrcAndEncoding.expectedProp}" arg2="${useSrcAndEncoding.prop}" />
+ </condition>
+ <fail message="expected <${useSrcAndEncoding.expectedProp}> but was <${useSrcAndEncoding.prop}>" unless="useSrcAndEncoding.testOK" />
+ </target>
+
+ <target name="useCompiled">
+
+ <!-- Test with 'javax' manager, 'bsf' manager already compiles the script. -->
+ <scriptdef manager="javax" name="heavyscript" language="javascript" src="heavy-script.js" encoding="UTF-8" compiled="true" />
+
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+
+ </target>
+
+ <target name="useNotCompiled">
+
+ <scriptdef manager="javax" name="heavyscriptNotCompiled" language="javascript" src="heavy-script.js" encoding="UTF-8" compiled="false" />
+
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+
+ </target>
</project>
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
----------------------------------------------------------------------
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 9f3854f..7a410e0 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
@@ -40,7 +40,7 @@ import org.apache.tools.ant.util.ScriptRunnerBase;
import org.apache.tools.ant.util.ScriptRunnerHelper;
/**
- * Define a task using a script
+ * Defines a task using a script.
*
* @since Ant 1.6
*/
@@ -76,7 +76,7 @@ public class ScriptDef extends DefBase {
}
/**
- * set the name under which this script will be activated in a build
+ * Sets the name under which this script will be activated in a build
* file
*
* @param name the name of the script
@@ -104,7 +104,7 @@ public class ScriptDef extends DefBase {
private String name;
/**
- * Set the attribute name
+ * Sets the attribute name
*
* @param name the attribute name
*/
@@ -114,7 +114,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Add an attribute definition to this script.
+ * Adds an attribute definition to this script.
*
* @param attribute the attribute definition.
*/
@@ -136,7 +136,7 @@ public class ScriptDef extends DefBase {
private String className;
/**
- * set the tag name for this nested element
+ * Sets the tag name for this nested element
*
* @param name the name of this nested element
*/
@@ -145,7 +145,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Set the type of this element. This is the name of an
+ * Sets the type of this element. This is the name of an
* Ant task or type which is to be used when this element is to be
* created. This is an alternative to specifying the class name directly
*
@@ -157,7 +157,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Set the classname of the class to be used for the nested element.
+ * Sets the classname of the class to be used for the nested element.
* This specifies the class directly and is an alternative to specifying
* the Ant type name.
*
@@ -170,7 +170,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Add a nested element definition.
+ * Adds a nested element definition.
*
* @param nestedElement the nested element definition.
*/
@@ -179,7 +179,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Define the script.
+ * Defines the script.
*/
public void execute() {
if (name == null) {
@@ -257,7 +257,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Find or create the script repository - it is stored in the project.
+ * Finds or creates the script repository - it is stored in the project.
* This method is synchronized on the project under {@link MagicNames#SCRIPT_REPOSITORY}
* @return the current script repository registered as a reference.
*/
@@ -277,7 +277,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Create a nested element to be configured.
+ * Creates a nested element to be configured.
*
* @param elementName the name of the nested element.
* @return object representing the element name.
@@ -322,7 +322,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Execute the script.
+ * Executes the script.
*
* @param attributes collection of attributes
* @param elements a list of nested element values.
@@ -334,7 +334,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Execute the script.
+ * Executes the script.
* This is called by the script instance to execute the script for this
* definition.
*
@@ -375,13 +375,14 @@ public class ScriptDef extends DefBase {
* Defines the compilation feature ; optional.
*
* @param compiled enables the script compilation if available.
+ * @since Ant 1.10.1
*/
public void setCompiled(boolean compiled) {
helper.setCompiled(compiled);
}
/**
- * Load the script from an external file ; optional.
+ * Loads the script from an external file ; optional.
*
* @param file the file containing the script source.
*/
@@ -390,16 +391,17 @@ public class ScriptDef extends DefBase {
}
/**
- * Set the encoding of the script from an external file ; optional.
+ * Sets the encoding of the script from an external file ; optional.
*
* @param encoding the encoding of the file containing the script source.
+ * @since Ant 1.10.1
*/
public void setEncoding(String encoding) {
helper.setEncoding(encoding);
}
/**
- * Set the script text.
+ * Sets the script text.
*
* @param text a component of the script text to be added.
*/
@@ -408,8 +410,8 @@ public class ScriptDef extends DefBase {
}
/**
- * Add any source resource.
- * @since Ant1.7.1
+ * Adds any source resource.
+ * @since Ant 1.7.1
* @param resource source of script
*/
public void add(ResourceCollection resource) {
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java b/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
index 7209e28..63ab4d9 100644
--- a/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
+++ b/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
@@ -84,14 +84,14 @@ public class JavaxScriptRunner extends ScriptRunnerBase {
if (getCompiled()) {
- final String compiledScriptRefName = execName + ".compiledScript.0123456789";
+ final String compiledScriptRefName = execName + ".compiled." + getScript().hashCode() + "." + getProject().hashCode();
if (null == compiledScript) {
compiledScript = getProject().getReference(compiledScriptRefName);
}
if (null == compiledScript) {
- ReflectWrapper engine = createEngine();
+ final ReflectWrapper engine = createEngine();
if (engine == null) {
throw new BuildException(
"Unable to create javax script engine for "
@@ -111,7 +111,7 @@ public class JavaxScriptRunner extends ScriptRunnerBase {
compiledScript = new ReflectWrapper(compiled);
} else {
- getProject().log("script compilation not available", Project.MSG_VERBOSE);
+ getProject().log("script compilation not available for " + execName, Project.MSG_VERBOSE);
compiledScript = new ReflectWrapper(null);
}
getProject().addReference(compiledScriptRefName, compiledScript);
@@ -123,7 +123,7 @@ public class JavaxScriptRunner extends ScriptRunnerBase {
applyBindings(simpleBindings);
- getProject().log("run compiled script " + execName, Project.MSG_DEBUG);
+ getProject().log("run compiled script " + compiledScriptRefName, Project.MSG_DEBUG);
final Class bindingsClass = Class.forName("javax.script.Bindings", true, getClass().getClassLoader());
@@ -173,15 +173,9 @@ public class JavaxScriptRunner extends ScriptRunnerBase {
String key = (String) i.next();
Object value = getBeans().get(key);
if ("FX".equalsIgnoreCase(getLanguage())) {
- engine.invoke(
- "put", String.class, key
- + ":" + value.getClass().getName(),
- Object.class, value);
- } else {
- engine.invoke(
- "put", String.class, key,
- Object.class, value);
+ key += ":" + value.getClass().getName();
}
+ engine.invoke("put", String.class, key, Object.class, value);
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
index 35576dc..5b41d0f 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
@@ -17,12 +17,14 @@
*/
package org.apache.tools.ant.taskdefs.optional;
+import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileRule;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Tests the examples of the <script> task docs.
@@ -64,4 +66,24 @@ public class RhinoScriptTest {
assertTrue(index > -1);
}
+ @Test
+ public void testUseSrcAndEncoding() {
+ final String readerEncoding = "UTF-8";
+ buildRule.getProject().setProperty("useSrcAndEncoding.reader.encoding", readerEncoding);
+ buildRule.executeTarget("useSrcAndEncoding");
+ }
+
+ @Test
+ public void testUseSrcAndEncodingFailure() {
+ final String readerEncoding = "ISO-8859-1";
+ buildRule.getProject().setProperty("useSrcAndEncoding.reader.encoding", readerEncoding);
+ try {
+ buildRule.executeTarget("useSrcAndEncoding");
+ fail("should have failed with reader's encoding [" + readerEncoding +
+ "] different from the writer's encoding [" + buildRule.getProject().getProperty("useSrcAndEncoding.encoding") + "]");
+ }
+ catch(BuildException e) {
+ assertTrue(e.getMessage().matches("expected <eacute \\[\u00e9]> but was <eacute \\[\u00c3\u00a9]>"));
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
index 5d4d4cf..0b2ebce 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
@@ -142,5 +142,46 @@ public class ScriptDefTest {
log.indexOf("Attribute value = test") != -1);
}
+ @Test
+ public void testUseSrcAndEncoding() {
+ final String readerEncoding = "UTF-8";
+ buildRule.getProject().setProperty("useSrcAndEncoding.reader.encoding", readerEncoding);
+ buildRule.executeTarget("useSrcAndEncoding");
+ }
+
+ @Test
+ public void testUseSrcAndEncodingFailure() {
+ final String readerEncoding = "ISO-8859-1";
+ buildRule.getProject().setProperty("useSrcAndEncoding.reader.encoding", readerEncoding);
+ try {
+ buildRule.executeTarget("useSrcAndEncoding");
+ fail("should have failed with reader's encoding [" + readerEncoding +
+ "] different from the writer's encoding [" +
+ buildRule.getProject().getProperty("useSrcAndEncoding.encoding") + "]");
+ }
+ catch(BuildException e) {
+ assertTrue(e.getMessage().matches(
+ "expected <eacute \\[\u00e9]> but was <eacute \\[\u00c3\u00a9]>"));
+ }
+ }
+ @Test
+ public void testUseCompiled() {
+
+ final long duration;
+ {
+ long start = System.nanoTime();
+ buildRule.executeTarget("useCompiled");
+ duration = System.nanoTime() - start;
+ }
+
+ final long notCompiledDuration;
+ {
+ long start = System.nanoTime();
+ buildRule.executeTarget("useNotCompiled");
+ notCompiledDuration = System.nanoTime() - start;
+ }
+
+ assertTrue(duration < notCompiledDuration);
+ }
}