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
@@ -536,6 +536,11 @@ an explanation of scripts and dependencies.
setbeans |
whether to have all properties, references and targets as
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 @@
-->
+
+
+
+
This build-file is intended to be run from the test cases
@@ -43,4 +47,22 @@
]]>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ 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 @@
-->
+
+
+
+
This build-file is intended to be run from the test cases
@@ -141,5 +145,85 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
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 but was "));
+ }
+ }
}
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 but was "));
+ }
+ }
+ @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);
+ }
}
|