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.jsmaster
| @@ -536,6 +536,11 @@ an explanation of scripts and dependencies. | |||||
| <td valign="top">filename of script source</td> | <td valign="top">filename of script source</td> | ||||
| <td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
| </tr> | </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> | <tr> | ||||
| <td valign="top">setbeans</td> | <td valign="top">setbeans</td> | ||||
| <td valign="top">whether to have all properties, references and targets as | <td valign="top">whether to have all properties, references and targets as | ||||
| @@ -102,6 +102,11 @@ different location values.</p> | |||||
| <td valign="top">The location of the script as a file, if not inline</td> | <td valign="top">The location of the script as a file, if not inline</td> | ||||
| <td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
| </tr> | </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> | <tr> | ||||
| <td valign="top">setbeans</td> | <td valign="top">setbeans</td> | ||||
| <td valign="top"> | <td valign="top"> | ||||
| @@ -282,7 +287,7 @@ filesizes of all files a <code><fileset/></code> caught.</p> | |||||
| // Access to Ant-Properties by their names | // Access to Ant-Properties by their names | ||||
| dir = <font color=blue>project</font>.getProperty("fs.dir"); | dir = <font color=blue>project</font>.getProperty("fs.dir"); | ||||
| includes = <font color=blue>MyProject</font>.getProperty("fs.includes"); | 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=""/> | // Create a <fileset dir="" includes=""/> | ||||
| fs = project.<font color=blue>createDataType("fileset")</font>; | fs = project.<font color=blue>createDataType("fileset")</font>; | ||||
| @@ -115,6 +115,20 @@ more information on writing scripts, please refer to the | |||||
| <td valign="top">The location of the script as a file, if not inline</td> | <td valign="top">The location of the script as a file, if not inline</td> | ||||
| <td valign="top" align="center">No</td> | <td valign="top" align="center">No</td> | ||||
| </tr> | </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> | <tr> | ||||
| <td valign="top">uri</td> | <td valign="top">uri</td> | ||||
| <td valign="top"> | <td valign="top"> | ||||
| @@ -1565,6 +1565,11 @@ Must be a supported Apache BSF or JSR 223 language</td> | |||||
| </td> | </td> | ||||
| <td vAlign=top align="center">No</td> | <td vAlign=top align="center">No</td> | ||||
| </tr> | </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> | <tr> | ||||
| <td valign="top">setbeans</td> | <td valign="top">setbeans</td> | ||||
| <td valign="top">whether to have all properties, references and targets as | <td valign="top">whether to have all properties, references and targets as | ||||
| @@ -805,6 +805,11 @@ an explanation of scripts and dependencies. | |||||
| </td> | </td> | ||||
| <td align="center" valign="top">No</td> | <td align="center" valign="top">No</td> | ||||
| </tr> | </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> | <tr> | ||||
| <td valign="top">setbeans</td> | <td valign="top">setbeans</td> | ||||
| <td valign="top">whether to have all properties, references and targets as | <td valign="top">whether to have all properties, references and targets as | ||||
| @@ -1107,6 +1107,11 @@ | |||||
| <td valign="top">filename of the script</td> | <td valign="top">filename of the script</td> | ||||
| <td valign="top" align="center">no</td> | <td valign="top" align="center">no</td> | ||||
| </tr> | </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> | <tr> | ||||
| <td valign="top">setbeans</td> | <td valign="top">setbeans</td> | ||||
| <td valign="top">whether to have all properties, references and targets as | <td valign="top">whether to have all properties, references and targets as | ||||
| @@ -17,6 +17,10 @@ | |||||
| --> | --> | ||||
| <project name="testproject" default="def" basedir="."> | <project name="testproject" default="def" basedir="."> | ||||
| <import file="../../buildfiletest-base.xml"/> | |||||
| <property name="root" location="../../../../.."/> | |||||
| <target name="def"> | <target name="def"> | ||||
| <fail>This build-file is intended to be run from the test cases</fail> | <fail>This build-file is intended to be run from the test cases</fail> | ||||
| </target> | </target> | ||||
| @@ -43,4 +47,22 @@ | |||||
| ]]></script> | ]]></script> | ||||
| </target> | </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> | </project> | ||||
| @@ -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(); | |||||
| @@ -17,6 +17,10 @@ | |||||
| --> | --> | ||||
| <project name="testproject" default="def" basedir="."> | <project name="testproject" default="def" basedir="."> | ||||
| <import file="../../../buildfiletest-base.xml"/> | |||||
| <property name="root" location="../../../../../.."/> | |||||
| <target name="def"> | <target name="def"> | ||||
| <fail>This build-file is intended to be run from the test cases</fail> | <fail>This build-file is intended to be run from the test cases</fail> | ||||
| </target> | </target> | ||||
| @@ -141,5 +145,85 @@ | |||||
| </scripttest> | </scripttest> | ||||
| </target> | </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> | </project> | ||||
| @@ -40,7 +40,7 @@ import org.apache.tools.ant.util.ScriptRunnerBase; | |||||
| import org.apache.tools.ant.util.ScriptRunnerHelper; | import org.apache.tools.ant.util.ScriptRunnerHelper; | ||||
| /** | /** | ||||
| * Define a task using a script | |||||
| * Defines a task using a script. | |||||
| * | * | ||||
| * @since Ant 1.6 | * @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 | * file | ||||
| * | * | ||||
| * @param name the name of the script | * @param name the name of the script | ||||
| @@ -104,7 +104,7 @@ public class ScriptDef extends DefBase { | |||||
| private String name; | private String name; | ||||
| /** | /** | ||||
| * Set the attribute name | |||||
| * Sets the attribute name | |||||
| * | * | ||||
| * @param name 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. | * @param attribute the attribute definition. | ||||
| */ | */ | ||||
| @@ -136,7 +136,7 @@ public class ScriptDef extends DefBase { | |||||
| private String className; | 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 | * @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 | * 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 | * 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 | * This specifies the class directly and is an alternative to specifying | ||||
| * the Ant type name. | * 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. | * @param nestedElement the nested element definition. | ||||
| */ | */ | ||||
| @@ -179,7 +179,7 @@ public class ScriptDef extends DefBase { | |||||
| } | } | ||||
| /** | /** | ||||
| * Define the script. | |||||
| * Defines the script. | |||||
| */ | */ | ||||
| public void execute() { | public void execute() { | ||||
| if (name == null) { | 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} | * This method is synchronized on the project under {@link MagicNames#SCRIPT_REPOSITORY} | ||||
| * @return the current script repository registered as a reference. | * @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. | * @param elementName the name of the nested element. | ||||
| * @return object representing the element name. | * @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 attributes collection of attributes | ||||
| * @param elements a list of nested element values. | * @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 | * This is called by the script instance to execute the script for this | ||||
| * definition. | * definition. | ||||
| * | * | ||||
| @@ -375,13 +375,14 @@ public class ScriptDef extends DefBase { | |||||
| * Defines the compilation feature ; optional. | * Defines the compilation feature ; optional. | ||||
| * | * | ||||
| * @param compiled enables the script compilation if available. | * @param compiled enables the script compilation if available. | ||||
| * @since Ant 1.10.1 | |||||
| */ | */ | ||||
| public void setCompiled(boolean compiled) { | public void setCompiled(boolean compiled) { | ||||
| helper.setCompiled(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. | * @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. | * @param encoding the encoding of the file containing the script source. | ||||
| * @since Ant 1.10.1 | |||||
| */ | */ | ||||
| public void setEncoding(String encoding) { | public void setEncoding(String encoding) { | ||||
| helper.setEncoding(encoding); | helper.setEncoding(encoding); | ||||
| } | } | ||||
| /** | /** | ||||
| * Set the script text. | |||||
| * Sets the script text. | |||||
| * | * | ||||
| * @param text a component of the script text to be added. | * @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 | * @param resource source of script | ||||
| */ | */ | ||||
| public void add(ResourceCollection resource) { | public void add(ResourceCollection resource) { | ||||
| @@ -84,14 +84,14 @@ public class JavaxScriptRunner extends ScriptRunnerBase { | |||||
| if (getCompiled()) { | if (getCompiled()) { | ||||
| final String compiledScriptRefName = execName + ".compiledScript.0123456789"; | |||||
| final String compiledScriptRefName = execName + ".compiled." + getScript().hashCode() + "." + getProject().hashCode(); | |||||
| if (null == compiledScript) { | if (null == compiledScript) { | ||||
| compiledScript = getProject().getReference(compiledScriptRefName); | compiledScript = getProject().getReference(compiledScriptRefName); | ||||
| } | } | ||||
| if (null == compiledScript) { | if (null == compiledScript) { | ||||
| ReflectWrapper engine = createEngine(); | |||||
| final ReflectWrapper engine = createEngine(); | |||||
| if (engine == null) { | if (engine == null) { | ||||
| throw new BuildException( | throw new BuildException( | ||||
| "Unable to create javax script engine for " | "Unable to create javax script engine for " | ||||
| @@ -111,7 +111,7 @@ public class JavaxScriptRunner extends ScriptRunnerBase { | |||||
| compiledScript = new ReflectWrapper(compiled); | compiledScript = new ReflectWrapper(compiled); | ||||
| } else { | } 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); | compiledScript = new ReflectWrapper(null); | ||||
| } | } | ||||
| getProject().addReference(compiledScriptRefName, compiledScript); | getProject().addReference(compiledScriptRefName, compiledScript); | ||||
| @@ -123,7 +123,7 @@ public class JavaxScriptRunner extends ScriptRunnerBase { | |||||
| applyBindings(simpleBindings); | 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()); | 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(); | String key = (String) i.next(); | ||||
| Object value = getBeans().get(key); | Object value = getBeans().get(key); | ||||
| if ("FX".equalsIgnoreCase(getLanguage())) { | 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); | |||||
| } | } | ||||
| } | } | ||||
| @@ -17,12 +17,14 @@ | |||||
| */ | */ | ||||
| package org.apache.tools.ant.taskdefs.optional; | package org.apache.tools.ant.taskdefs.optional; | ||||
| import org.apache.tools.ant.BuildException; | |||||
| import org.apache.tools.ant.BuildFileRule; | import org.apache.tools.ant.BuildFileRule; | ||||
| import org.junit.Before; | import org.junit.Before; | ||||
| import org.junit.Rule; | import org.junit.Rule; | ||||
| import org.junit.Test; | import org.junit.Test; | ||||
| import static org.junit.Assert.assertTrue; | import static org.junit.Assert.assertTrue; | ||||
| import static org.junit.Assert.fail; | |||||
| /** | /** | ||||
| * Tests the examples of the <script> task docs. | * Tests the examples of the <script> task docs. | ||||
| @@ -64,4 +66,24 @@ public class RhinoScriptTest { | |||||
| assertTrue(index > -1); | 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]>")); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -142,5 +142,46 @@ public class ScriptDefTest { | |||||
| log.indexOf("Attribute value = test") != -1); | 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); | |||||
| } | |||||
| } | } | ||||