diff options
| author | pyxide <oparent@gmail.com> | 2017-01-20 16:33:35 +0100 |
|---|---|---|
| committer | Stefan Bodewig <bodewig@apache.org> | 2017-02-20 17:41:37 +0100 |
| commit | ea7091756bb65ba5667ac8246efba6ac3f04322e (patch) | |
| tree | c8a1b4c3a88d0203ae54c592586bc617c922c02e | |
| parent | 5710193e1464397b3093207c22f2cb8b28275c71 (diff) | |
| download | ant-ea7091756bb65ba5667ac8246efba6ac3f04322e.tar.gz | |
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
| -rw-r--r-- | manual/Tasks/conditions.html | 5 | ||||
| -rw-r--r-- | manual/Tasks/script.html | 7 | ||||
| -rw-r--r-- | manual/Tasks/scriptdef.html | 14 | ||||
| -rw-r--r-- | manual/Types/filterchain.html | 5 | ||||
| -rw-r--r-- | manual/Types/mapper.html | 5 | ||||
| -rw-r--r-- | manual/Types/selectors.html | 5 | ||||
| -rw-r--r-- | src/etc/testcases/taskdefs/optional/script.xml | 22 | ||||
| -rw-r--r-- | src/etc/testcases/taskdefs/optional/script/heavy-script.js | 68 | ||||
| -rw-r--r-- | src/etc/testcases/taskdefs/optional/script/scriptdef.xml | 84 | ||||
| -rw-r--r-- | src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java | 38 | ||||
| -rw-r--r-- | src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java | 18 | ||||
| -rw-r--r-- | src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java | 22 | ||||
| -rw-r--r-- | src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java | 41 |
13 files changed, 303 insertions, 31 deletions
diff --git a/manual/Tasks/conditions.html b/manual/Tasks/conditions.html index 08d0bccec..895da5426 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> diff --git a/manual/Tasks/script.html b/manual/Tasks/script.html index fb008224a..7a56eec89 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>; diff --git a/manual/Tasks/scriptdef.html b/manual/Tasks/scriptdef.html index 38c3ffff0..de601a583 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. diff --git a/manual/Types/filterchain.html b/manual/Types/filterchain.html index 90dd74bef..14968160d 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> diff --git a/manual/Types/mapper.html b/manual/Types/mapper.html index 5aff311e6..f6bc76dd2 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> diff --git a/manual/Types/selectors.html b/manual/Types/selectors.html index a79138003..6a080cbc3 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> diff --git a/src/etc/testcases/taskdefs/optional/script.xml b/src/etc/testcases/taskdefs/optional/script.xml index 841f70d27..c098289bc 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 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 000000000..4033adda3 --- /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(); diff --git a/src/etc/testcases/taskdefs/optional/script/scriptdef.xml b/src/etc/testcases/taskdefs/optional/script/scriptdef.xml index 0d051eaea..3b54e3e48 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> 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 9f3854fe0..7a410e0ab 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) { 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 7209e2884..63ab4d93a 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); } } 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 35576dcb6..5b41d0f4f 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]>")); + } + } } 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 5d4d4cf61..0b2ebce61 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); + } } |
