You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2017/02/20 16:58:51 UTC
[01/12] ant git commit: fix line-ends
Repository: ant
Updated Branches:
refs/heads/master 5c9767039 -> 5a0d2d1f1
fix line-ends
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/526df1e1
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/526df1e1
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/526df1e1
Branch: refs/heads/master
Commit: 526df1e155a1b555d00a8eccae86e355e96787db
Parents: 5c97670
Author: Stefan Bodewig <bo...@apache.org>
Authored: Mon Feb 20 17:41:27 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Feb 20 17:41:27 2017 +0100
----------------------------------------------------------------------
.../ant/taskdefs/optional/RhinoScriptTest.java | 134 ++++-----
.../taskdefs/optional/script/ScriptDefTest.java | 292 +++++++++----------
2 files changed, 213 insertions(+), 213 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/526df1e1/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
index d05cf0c..35576dc 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
@@ -1,67 +1,67 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests the examples of the <script> task docs.
- *
- * @since Ant 1.5.2
- */
-public class RhinoScriptTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/script.xml");
- }
-
- @Test
- public void testExample1() {
- buildRule.executeTarget("example1");
- int index = buildRule.getLog().indexOf("1");
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("4", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("9", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("16", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("25", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("36", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("49", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("64", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("81", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("100", index);
- assertTrue(index > -1);
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests the examples of the <script> task docs.
+ *
+ * @since Ant 1.5.2
+ */
+public class RhinoScriptTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/script.xml");
+ }
+
+ @Test
+ public void testExample1() {
+ buildRule.executeTarget("example1");
+ int index = buildRule.getLog().indexOf("1");
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("4", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("9", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("16", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("25", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("36", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("49", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("64", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("81", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("100", index);
+ assertTrue(index > -1);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/526df1e1/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
index 77c7036..5d4d4cf 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
@@ -1,146 +1,146 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.script;
-
-import org.apache.tools.ant.AntAssert;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.types.FileSet;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import java.io.File;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * Tests the examples of the <scriptdef> task.
- *
- * @since Ant 1.6
- */
-public class ScriptDefTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/script/scriptdef.xml");
- }
-
- @Test
- public void testSimple() {
- buildRule.executeTarget("simple");
- // get the fileset and its basedir
- Project p = buildRule.getProject();
- FileSet fileset = (FileSet) p.getReference("testfileset");
- File baseDir = fileset.getDir(p);
- String log = buildRule.getLog();
- assertTrue("Expecting attribute value printed",
- log.indexOf("Attribute attr1 = test") != -1);
-
- assertTrue("Expecting nested element value printed",
- log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1);
- }
-
- @Test
- public void testNoLang() {
- try {
- buildRule.executeTarget("nolang");
- fail("Absence of language attribute not detected");
- } catch(BuildException ex) {
- AntAssert.assertContains("requires a language attribute", ex.getMessage());
- }
- }
-
- @Test
- public void testNoName() {
- try {
- buildRule.executeTarget("noname");
- fail("Absence of name attribute not detected");
- } catch(BuildException ex) {
- AntAssert.assertContains("scriptdef requires a name attribute", ex.getMessage());
- }
- }
-
- @Test
- public void testNestedByClassName() {
- buildRule.executeTarget("nestedbyclassname");
- // get the fileset and its basedir
- Project p = buildRule.getProject();
- FileSet fileset = (FileSet) p.getReference("testfileset");
- File baseDir = fileset.getDir(p);
- String log = buildRule.getLog();
- assertTrue("Expecting attribute value to be printed",
- log.indexOf("Attribute attr1 = test") != -1);
-
- assertTrue("Expecting nested element value to be printed",
- log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1);
- }
-
- @Test
- public void testNoElement() {
- buildRule.executeTarget("noelement");
- assertEquals("Attribute attr1 = test", buildRule.getOutput().trim());
- }
-
- @Test
- public void testException() {
- try {
- buildRule.executeTarget("exception");
- fail("Should have thrown an exception in the script");
- } catch(BuildException ex) {
- AntAssert.assertContains("TypeError", ex.getMessage());
- }
- }
-
- @Test
- public void testDoubleDef() {
- buildRule.executeTarget("doubledef");
- String log = buildRule.getLog();
- assertTrue("Task1 did not execute",
- log.indexOf("Task1") != -1);
- assertTrue("Task2 did not execute",
- log.indexOf("Task2") != -1);
- }
-
- @Test
- public void testDoubleAttribute() {
- try {
- buildRule.executeTarget("doubleAttributeDef");
- fail("Should have detected duplicate attirbute definition");
- } catch(BuildException ex) {
- AntAssert.assertContains("attr1 attribute more than once", ex.getMessage());
- }
- }
-
- @Test
- public void testProperty() {
- buildRule.executeTarget("property");
- // get the fileset and its basedir
- String log = buildRule.getLog();
- assertTrue("Expecting property in attribute value replaced",
- log.indexOf("Attribute value = test") != -1);
- }
-
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.script;
+
+import org.apache.tools.ant.AntAssert;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.FileSet;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests the examples of the <scriptdef> task.
+ *
+ * @since Ant 1.6
+ */
+public class ScriptDefTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/script/scriptdef.xml");
+ }
+
+ @Test
+ public void testSimple() {
+ buildRule.executeTarget("simple");
+ // get the fileset and its basedir
+ Project p = buildRule.getProject();
+ FileSet fileset = (FileSet) p.getReference("testfileset");
+ File baseDir = fileset.getDir(p);
+ String log = buildRule.getLog();
+ assertTrue("Expecting attribute value printed",
+ log.indexOf("Attribute attr1 = test") != -1);
+
+ assertTrue("Expecting nested element value printed",
+ log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1);
+ }
+
+ @Test
+ public void testNoLang() {
+ try {
+ buildRule.executeTarget("nolang");
+ fail("Absence of language attribute not detected");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("requires a language attribute", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testNoName() {
+ try {
+ buildRule.executeTarget("noname");
+ fail("Absence of name attribute not detected");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("scriptdef requires a name attribute", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testNestedByClassName() {
+ buildRule.executeTarget("nestedbyclassname");
+ // get the fileset and its basedir
+ Project p = buildRule.getProject();
+ FileSet fileset = (FileSet) p.getReference("testfileset");
+ File baseDir = fileset.getDir(p);
+ String log = buildRule.getLog();
+ assertTrue("Expecting attribute value to be printed",
+ log.indexOf("Attribute attr1 = test") != -1);
+
+ assertTrue("Expecting nested element value to be printed",
+ log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1);
+ }
+
+ @Test
+ public void testNoElement() {
+ buildRule.executeTarget("noelement");
+ assertEquals("Attribute attr1 = test", buildRule.getOutput().trim());
+ }
+
+ @Test
+ public void testException() {
+ try {
+ buildRule.executeTarget("exception");
+ fail("Should have thrown an exception in the script");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("TypeError", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testDoubleDef() {
+ buildRule.executeTarget("doubledef");
+ String log = buildRule.getLog();
+ assertTrue("Task1 did not execute",
+ log.indexOf("Task1") != -1);
+ assertTrue("Task2 did not execute",
+ log.indexOf("Task2") != -1);
+ }
+
+ @Test
+ public void testDoubleAttribute() {
+ try {
+ buildRule.executeTarget("doubleAttributeDef");
+ fail("Should have detected duplicate attirbute definition");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("attr1 attribute more than once", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testProperty() {
+ buildRule.executeTarget("property");
+ // get the fileset and its basedir
+ String log = buildRule.getLog();
+ assertTrue("Expecting property in attribute value replaced",
+ log.indexOf("Attribute value = test") != -1);
+ }
+
+
+}
[08/12] ant git commit: missing license
Posted by bo...@apache.org.
missing license
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/166ce263
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/166ce263
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/166ce263
Branch: refs/heads/master
Commit: 166ce26357f86f140eaad70bfa0c90b98c87d49f
Parents: fd0fb26
Author: Stefan Bodewig <bo...@apache.org>
Authored: Mon Feb 20 17:44:06 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Feb 20 17:44:06 2017 +0100
----------------------------------------------------------------------
.../taskdefs/optional/script/heavy-script.js | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/166ce263/src/etc/testcases/taskdefs/optional/script/heavy-script.js
----------------------------------------------------------------------
diff --git a/src/etc/testcases/taskdefs/optional/script/heavy-script.js b/src/etc/testcases/taskdefs/optional/script/heavy-script.js
index 4033add..63c166d 100644
--- a/src/etc/testcases/taskdefs/optional/script/heavy-script.js
+++ b/src/etc/testcases/taskdefs/optional/script/heavy-script.js
@@ -1,3 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
var functions = [
function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
[05/12] ant git commit: Cosmetic changes
Posted by bo...@apache.org.
Cosmetic changes
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/5710193e
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/5710193e
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/5710193e
Branch: refs/heads/master
Commit: 5710193e1464397b3093207c22f2cb8b28275c71
Parents: 49896d3
Author: pyxide <op...@gmail.com>
Authored: Tue Jan 17 01:08:54 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Feb 20 17:41:37 2017 +0100
----------------------------------------------------------------------
.../org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java | 4 ++--
src/main/org/apache/tools/ant/util/ScriptRunnerBase.java | 4 ++--
src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/5710193e/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java b/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
index e45668c..9f3854f 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
@@ -194,7 +194,7 @@ public class ScriptDef extends DefBase {
if (helper.getSrc() == null && helper.getEncoding() != null) {
throw new BuildException("scriptdef requires a src attribute "
- + "if the encoding is set");
+ + "if the encoding is set");
}
// Check if need to set the loader
@@ -372,7 +372,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Defines the compilation feature (optional).
+ * Defines the compilation feature ; optional.
*
* @param compiled enables the script compilation if available.
*/
http://git-wip-us.apache.org/repos/asf/ant/blob/5710193e/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
index ae0af33..c738999 100644
--- a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
+++ b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
@@ -283,11 +283,11 @@ public abstract class ScriptRunnerBase {
* @throws BuildException if the resource cannot be read
*/
public void loadResource(Resource sourceResource) {
- if(sourceResource instanceof StringResource) {
+ if (sourceResource instanceof StringResource) {
script += ((StringResource) sourceResource).getValue();
return;
}
- if(sourceResource instanceof PropertyResource) {
+ if (sourceResource instanceof PropertyResource) {
script += ((PropertyResource) sourceResource).getValue();
return;
}
http://git-wip-us.apache.org/repos/asf/ant/blob/5710193e/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java b/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
index 528a565..eda0421 100644
--- a/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
+++ b/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
@@ -183,7 +183,7 @@ public class ScriptRunnerHelper {
* If this is true and the compilation feature is available in
* the script engine, the script is compiled before the first
* evaluation, and should be cached for future evaluations.
- * Otherwise, a script is evaluated is used.
+ * Otherwise, the script is evaluated each time.
* The default is false.
*
* @param compiled the value to set.
[12/12] ant git commit: seems there was a setter missing in
Posted by bo...@apache.org.
seems there was a setter missing in <script>
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/5a0d2d1f
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/5a0d2d1f
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/5a0d2d1f
Branch: refs/heads/master
Commit: 5a0d2d1f174f6ddef40ebab925b4aeb02646adab
Parents: 13c6aaa
Author: Stefan Bodewig <bo...@apache.org>
Authored: Mon Feb 20 17:58:25 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Feb 20 17:58:25 2017 +0100
----------------------------------------------------------------------
.../org/apache/tools/ant/taskdefs/optional/Script.java | 11 +++++++++++
1 file changed, 11 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/5a0d2d1f/src/main/org/apache/tools/ant/taskdefs/optional/Script.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Script.java b/src/main/org/apache/tools/ant/taskdefs/optional/Script.java
index 2b8d9f6..de6bf5a 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/Script.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/Script.java
@@ -130,4 +130,15 @@ public class Script extends Task {
public void setSetBeans(boolean setBeans) {
helper.setSetBeans(setBeans);
}
+
+ /**
+ * Set 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.2
+ */
+ public void setEncoding(String encoding) {
+ helper.setEncoding(encoding);
+ }
+
}
[03/12] ant git commit: Enhanced JavaxScriptRunner, Junit, docs,
Javadoc
Posted by bo...@apache.org.
Enhanced JavaxScriptRunner, Junit, docs, Javadoc
JavaxScriptRunner:
- Better compiled script reference name to avoid reference name
collision, project wide : execName + ".compiled." +
getScript().hashCode() + "." + getProject().hashCode();
ScriptDef:
- Fixed Javadoc + use of 3rd person
[(oracle style
guideline)](http://www.oracle.com/technetwork/articles/java/index-137868.html#styleguide)
Task manual: documentation for `encoding` and `compiled` options.
- `encoding` : script.html, scriptdef.html, conditions.html,
selectors.html, mapper.html, filterchain.html
- `compiled` : scriptdef.html
Added source file `encoding` option on:
- org.apache.tools.ant.taskdefs.optional.Script
- org.apache.tools.ant.types.optional.AbstractScriptComponent
(inherited by ScriptCondition, ScriptMapper)
- org.apache.tools.ant.types.optional.ScriptFilter
- org.apache.tools.ant.types.optional.ScriptSelector
Test units :
- org.apache.tools.ant.taskdefs.optional.script.ScriptDefTest,
script.xml : src + encoding
- org.apache.tools.ant.taskdefs.optional.RhinoScriptDefTest,
scriptdef.xml : src + encoding, compiled
- new file: src/etc/testcases/taskdefs/optional/script/heavy-script.js
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/ea709175
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/ea709175
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/ea709175
Branch: refs/heads/master
Commit: ea7091756bb65ba5667ac8246efba6ac3f04322e
Parents: 5710193
Author: pyxide <op...@gmail.com>
Authored: Fri Jan 20 16:33:35 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Feb 20 17:41:37 2017 +0100
----------------------------------------------------------------------
manual/Tasks/conditions.html | 5 ++
manual/Tasks/script.html | 7 +-
manual/Tasks/scriptdef.html | 14 ++++
manual/Types/filterchain.html | 5 ++
manual/Types/mapper.html | 5 ++
manual/Types/selectors.html | 5 ++
src/etc/testcases/taskdefs/optional/script.xml | 22 +++++
.../taskdefs/optional/script/heavy-script.js | 68 ++++++++++++++++
.../taskdefs/optional/script/scriptdef.xml | 84 ++++++++++++++++++++
.../ant/taskdefs/optional/script/ScriptDef.java | 38 ++++-----
.../ant/util/optional/JavaxScriptRunner.java | 18 ++---
.../ant/taskdefs/optional/RhinoScriptTest.java | 22 +++++
.../taskdefs/optional/script/ScriptDefTest.java | 41 ++++++++++
13 files changed, 303 insertions(+), 31 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/manual/Tasks/conditions.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/conditions.html b/manual/Tasks/conditions.html
index 08d0bcc..895da54 100644
--- a/manual/Tasks/conditions.html
+++ b/manual/Tasks/conditions.html
@@ -537,6 +537,11 @@ an explanation of scripts and dependencies.
<td valign="top" align="center">No</td>
</tr>
<tr>
+ <td valign="top">encoding</td>
+ <td valign="top">The encoding of the script source. <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to default JVM encoding</td>
+ </tr>
+ <tr>
<td valign="top">setbeans</td>
<td valign="top">whether to have all properties, references and targets as
global variables in the script. <em>since Ant 1.8.0</em></td>
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/manual/Tasks/script.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/script.html b/manual/Tasks/script.html
index fb00822..7a56eec 100644
--- a/manual/Tasks/script.html
+++ b/manual/Tasks/script.html
@@ -103,6 +103,11 @@ different location values.</p>
<td valign="top" align="center">No</td>
</tr>
<tr>
+ <td valign="top">encoding</td>
+ <td valign="top">The encoding of the script as a file. <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to default JVM encoding</td>
+ </tr>
+ <tr>
<td valign="top">setbeans</td>
<td valign="top">
This attribute controls whether to set variables for
@@ -282,7 +287,7 @@ filesizes of all files a <code><fileset/></code> caught.</p>
// Access to Ant-Properties by their names
dir = <font color=blue>project</font>.getProperty("fs.dir");
includes = <font color=blue>MyProject</font>.getProperty("fs.includes");
- excludes = <font color=blue>self.getProject()</font> .<font color=blue>getProperty("fs.excludes")</font>;
+ excludes = <font color=blue>self.getProject()</font>.<font color=blue>getProperty("fs.excludes")</font>;
// Create a <fileset dir="" includes=""/>
fs = project.<font color=blue>createDataType("fileset")</font>;
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/manual/Tasks/scriptdef.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/scriptdef.html b/manual/Tasks/scriptdef.html
index 38c3fff..de601a5 100644
--- a/manual/Tasks/scriptdef.html
+++ b/manual/Tasks/scriptdef.html
@@ -116,6 +116,20 @@ more information on writing scripts, please refer to the
<td valign="top" align="center">No</td>
</tr>
<tr>
+ <td valign="top">encoding</td>
+ <td valign="top">The encoding of the script as a file. <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to default JVM encoding</td>
+ </tr>
+ <tr>
+ <td valign="top">compiled</td>
+ <td valign="top">If true, the script is compiled before the first
+ evaluation for faster multiple executions, on the condition that the <em>manager</em> is "javax" and the
+ target engine implements <code>javax.script.Compilable</code>.
+ Note that the <code>bsf</code> manager may automatically compiles the script.
+ <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to false</td>
+ </tr>
+ <tr>
<td valign="top">uri</td>
<td valign="top">
The XML namespace uri that this definition should live in.
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/manual/Types/filterchain.html
----------------------------------------------------------------------
diff --git a/manual/Types/filterchain.html b/manual/Types/filterchain.html
index 90dd74b..1496816 100644
--- a/manual/Types/filterchain.html
+++ b/manual/Types/filterchain.html
@@ -1566,6 +1566,11 @@ Must be a supported Apache BSF or JSR 223 language</td>
<td vAlign=top align="center">No</td>
</tr>
<tr>
+ <td valign="top">encoding</td>
+ <td valign="top">The encoding of the script as a file. <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to default JVM encoding</td>
+ </tr>
+ <tr>
<td valign="top">setbeans</td>
<td valign="top">whether to have all properties, references and targets as
global variables in the script. <em>since Ant 1.8.0</em></td>
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/manual/Types/mapper.html
----------------------------------------------------------------------
diff --git a/manual/Types/mapper.html b/manual/Types/mapper.html
index 5aff311..f6bc76d 100644
--- a/manual/Types/mapper.html
+++ b/manual/Types/mapper.html
@@ -806,6 +806,11 @@ an explanation of scripts and dependencies.
<td align="center" valign="top">No</td>
</tr>
<tr>
+ <td valign="top">encoding</td>
+ <td valign="top">The encoding of the script as a file. <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to default JVM encoding</td>
+ </tr>
+ <tr>
<td valign="top">setbeans</td>
<td valign="top">whether to have all properties, references and targets as
global variables in the script. <em>since Ant 1.8.0</em></td>
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/manual/Types/selectors.html
----------------------------------------------------------------------
diff --git a/manual/Types/selectors.html b/manual/Types/selectors.html
index a791380..6a080cb 100644
--- a/manual/Types/selectors.html
+++ b/manual/Types/selectors.html
@@ -1108,6 +1108,11 @@
<td valign="top" align="center">no</td>
</tr>
<tr>
+ <td valign="top">encoding</td>
+ <td valign="top">The encoding of the script as a file. <em>since Ant 1.10.1.</em></td>
+ <td valign="top" align="center">No - defaults to default JVM encoding</td>
+ </tr>
+ <tr>
<td valign="top">setbeans</td>
<td valign="top">whether to have all properties, references and targets as
global variables in the script.</td>
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/etc/testcases/taskdefs/optional/script.xml
----------------------------------------------------------------------
diff --git a/src/etc/testcases/taskdefs/optional/script.xml b/src/etc/testcases/taskdefs/optional/script.xml
index 841f70d..c098289 100644
--- a/src/etc/testcases/taskdefs/optional/script.xml
+++ b/src/etc/testcases/taskdefs/optional/script.xml
@@ -17,6 +17,10 @@
-->
<project name="testproject" default="def" basedir=".">
+ <import file="../../buildfiletest-base.xml"/>
+
+ <property name="root" location="../../../../.."/>
+
<target name="def">
<fail>This build-file is intended to be run from the test cases</fail>
</target>
@@ -43,4 +47,22 @@
]]></script>
</target>
+ <target name="useSrcAndEncoding">
+ <mkdir dir="${output}" />
+ <property name="useSrcAndEncoding.encoding" value="UTF-8"/>
+ <property name="useSrcAndEncoding.reader.encoding" value="${useSrcAndEncoding.encoding}"
+ description="Set a different encoding to raise a failure (ex. ISO-8859-1)" />
+ <property name="useSrcAndEncoding.file" location="${output}/script.useSrcAndEncoding.js"/>
+ <property name="useSrcAndEncoding.expectedProp" value="eacute [é]" />
+
+ <echo file="${useSrcAndEncoding.file}" encoding="${useSrcAndEncoding.encoding}"
+ message="project.setNewProperty('useSrcAndEncoding.prop', '${useSrcAndEncoding.expectedProp}');"/>
+
+ <script language="javascript" src="${useSrcAndEncoding.file}" encoding="${useSrcAndEncoding.reader.encoding}"/>
+ <condition property="useSrcAndEncoding.testOK" >
+ <equals arg1="${useSrcAndEncoding.expectedProp}" arg2="${useSrcAndEncoding.prop}" />
+ </condition>
+ <fail message="expected <${useSrcAndEncoding.expectedProp}> but was <${useSrcAndEncoding.prop}>" unless="useSrcAndEncoding.testOK" />
+ </target>
+
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/etc/testcases/taskdefs/optional/script/heavy-script.js
----------------------------------------------------------------------
diff --git a/src/etc/testcases/taskdefs/optional/script/heavy-script.js b/src/etc/testcases/taskdefs/optional/script/heavy-script.js
new file mode 100644
index 0000000..4033add
--- /dev/null
+++ b/src/etc/testcases/taskdefs/optional/script/heavy-script.js
@@ -0,0 +1,68 @@
+
+var functions = [
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },function (value) { return value; },
+];
+
+var v = 'a';
+for(var i in functions) {
+ v = functions[i](v);
+}
+
+var echo = project.createTask("echo");
+echo.setMessage("heavy-script done");
+echo.perform();
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/etc/testcases/taskdefs/optional/script/scriptdef.xml
----------------------------------------------------------------------
diff --git a/src/etc/testcases/taskdefs/optional/script/scriptdef.xml b/src/etc/testcases/taskdefs/optional/script/scriptdef.xml
index 0d051ea..3b54e3e 100644
--- a/src/etc/testcases/taskdefs/optional/script/scriptdef.xml
+++ b/src/etc/testcases/taskdefs/optional/script/scriptdef.xml
@@ -17,6 +17,10 @@
-->
<project name="testproject" default="def" basedir=".">
+ <import file="../../../buildfiletest-base.xml"/>
+
+ <property name="root" location="../../../../../.."/>
+
<target name="def">
<fail>This build-file is intended to be run from the test cases</fail>
</target>
@@ -141,5 +145,85 @@
</scripttest>
</target>
+ <target name="useBeanshell">
+ <script language="beanshell"><![CDATA[
+ self.log("I'm here", org.apache.tools.ant.Project.MSG_INFO);
+ ]]></script>
+ </target>
+
+ <target name="useSrcAndEncoding">
+ <mkdir dir="${output}" />
+ <property name="useSrcAndEncoding.encoding" value="UTF-8"/>
+ <property name="useSrcAndEncoding.reader.encoding" value="${useSrcAndEncoding.encoding}"
+ description="Set a different encoding to raise a failure (ex. ISO-8859-1)" />
+ <property name="useSrcAndEncoding.file" location="${output}/script.useSrcAndEncoding.js"/>
+ <property name="useSrcAndEncoding.expectedProp" value="eacute [é]" />
+
+ <echo file="${useSrcAndEncoding.file}" encoding="${useSrcAndEncoding.encoding}"
+ message="project.setNewProperty('useSrcAndEncoding.prop', '${useSrcAndEncoding.expectedProp}');"/>
+
+ <scriptdef name="useSrcAndEncoding" language="javascript" src="${useSrcAndEncoding.file}" encoding="${useSrcAndEncoding.reader.encoding}"/>
+ <useSrcAndEncoding/>
+
+ <condition property="useSrcAndEncoding.testOK" >
+ <equals arg1="${useSrcAndEncoding.expectedProp}" arg2="${useSrcAndEncoding.prop}" />
+ </condition>
+ <fail message="expected <${useSrcAndEncoding.expectedProp}> but was <${useSrcAndEncoding.prop}>" unless="useSrcAndEncoding.testOK" />
+ </target>
+
+ <target name="useCompiled">
+
+ <!-- Test with 'javax' manager, 'bsf' manager already compiles the script. -->
+ <scriptdef manager="javax" name="heavyscript" language="javascript" src="heavy-script.js" encoding="UTF-8" compiled="true" />
+
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+ <heavyscript />
+
+ </target>
+
+ <target name="useNotCompiled">
+
+ <scriptdef manager="javax" name="heavyscriptNotCompiled" language="javascript" src="heavy-script.js" encoding="UTF-8" compiled="false" />
+
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+ <heavyscriptNotCompiled />
+
+ </target>
</project>
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java b/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
index 9f3854f..7a410e0 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
@@ -40,7 +40,7 @@ import org.apache.tools.ant.util.ScriptRunnerBase;
import org.apache.tools.ant.util.ScriptRunnerHelper;
/**
- * Define a task using a script
+ * Defines a task using a script.
*
* @since Ant 1.6
*/
@@ -76,7 +76,7 @@ public class ScriptDef extends DefBase {
}
/**
- * set the name under which this script will be activated in a build
+ * Sets the name under which this script will be activated in a build
* file
*
* @param name the name of the script
@@ -104,7 +104,7 @@ public class ScriptDef extends DefBase {
private String name;
/**
- * Set the attribute name
+ * Sets the attribute name
*
* @param name the attribute name
*/
@@ -114,7 +114,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Add an attribute definition to this script.
+ * Adds an attribute definition to this script.
*
* @param attribute the attribute definition.
*/
@@ -136,7 +136,7 @@ public class ScriptDef extends DefBase {
private String className;
/**
- * set the tag name for this nested element
+ * Sets the tag name for this nested element
*
* @param name the name of this nested element
*/
@@ -145,7 +145,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Set the type of this element. This is the name of an
+ * Sets the type of this element. This is the name of an
* Ant task or type which is to be used when this element is to be
* created. This is an alternative to specifying the class name directly
*
@@ -157,7 +157,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Set the classname of the class to be used for the nested element.
+ * Sets the classname of the class to be used for the nested element.
* This specifies the class directly and is an alternative to specifying
* the Ant type name.
*
@@ -170,7 +170,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Add a nested element definition.
+ * Adds a nested element definition.
*
* @param nestedElement the nested element definition.
*/
@@ -179,7 +179,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Define the script.
+ * Defines the script.
*/
public void execute() {
if (name == null) {
@@ -257,7 +257,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Find or create the script repository - it is stored in the project.
+ * Finds or creates the script repository - it is stored in the project.
* This method is synchronized on the project under {@link MagicNames#SCRIPT_REPOSITORY}
* @return the current script repository registered as a reference.
*/
@@ -277,7 +277,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Create a nested element to be configured.
+ * Creates a nested element to be configured.
*
* @param elementName the name of the nested element.
* @return object representing the element name.
@@ -322,7 +322,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Execute the script.
+ * Executes the script.
*
* @param attributes collection of attributes
* @param elements a list of nested element values.
@@ -334,7 +334,7 @@ public class ScriptDef extends DefBase {
}
/**
- * Execute the script.
+ * Executes the script.
* This is called by the script instance to execute the script for this
* definition.
*
@@ -375,13 +375,14 @@ public class ScriptDef extends DefBase {
* Defines the compilation feature ; optional.
*
* @param compiled enables the script compilation if available.
+ * @since Ant 1.10.1
*/
public void setCompiled(boolean compiled) {
helper.setCompiled(compiled);
}
/**
- * Load the script from an external file ; optional.
+ * Loads the script from an external file ; optional.
*
* @param file the file containing the script source.
*/
@@ -390,16 +391,17 @@ public class ScriptDef extends DefBase {
}
/**
- * Set the encoding of the script from an external file ; optional.
+ * Sets the encoding of the script from an external file ; optional.
*
* @param encoding the encoding of the file containing the script source.
+ * @since Ant 1.10.1
*/
public void setEncoding(String encoding) {
helper.setEncoding(encoding);
}
/**
- * Set the script text.
+ * Sets the script text.
*
* @param text a component of the script text to be added.
*/
@@ -408,8 +410,8 @@ public class ScriptDef extends DefBase {
}
/**
- * Add any source resource.
- * @since Ant1.7.1
+ * Adds any source resource.
+ * @since Ant 1.7.1
* @param resource source of script
*/
public void add(ResourceCollection resource) {
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java b/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
index 7209e28..63ab4d9 100644
--- a/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
+++ b/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
@@ -84,14 +84,14 @@ public class JavaxScriptRunner extends ScriptRunnerBase {
if (getCompiled()) {
- final String compiledScriptRefName = execName + ".compiledScript.0123456789";
+ final String compiledScriptRefName = execName + ".compiled." + getScript().hashCode() + "." + getProject().hashCode();
if (null == compiledScript) {
compiledScript = getProject().getReference(compiledScriptRefName);
}
if (null == compiledScript) {
- ReflectWrapper engine = createEngine();
+ final ReflectWrapper engine = createEngine();
if (engine == null) {
throw new BuildException(
"Unable to create javax script engine for "
@@ -111,7 +111,7 @@ public class JavaxScriptRunner extends ScriptRunnerBase {
compiledScript = new ReflectWrapper(compiled);
} else {
- getProject().log("script compilation not available", Project.MSG_VERBOSE);
+ getProject().log("script compilation not available for " + execName, Project.MSG_VERBOSE);
compiledScript = new ReflectWrapper(null);
}
getProject().addReference(compiledScriptRefName, compiledScript);
@@ -123,7 +123,7 @@ public class JavaxScriptRunner extends ScriptRunnerBase {
applyBindings(simpleBindings);
- getProject().log("run compiled script " + execName, Project.MSG_DEBUG);
+ getProject().log("run compiled script " + compiledScriptRefName, Project.MSG_DEBUG);
final Class bindingsClass = Class.forName("javax.script.Bindings", true, getClass().getClassLoader());
@@ -173,15 +173,9 @@ public class JavaxScriptRunner extends ScriptRunnerBase {
String key = (String) i.next();
Object value = getBeans().get(key);
if ("FX".equalsIgnoreCase(getLanguage())) {
- engine.invoke(
- "put", String.class, key
- + ":" + value.getClass().getName(),
- Object.class, value);
- } else {
- engine.invoke(
- "put", String.class, key,
- Object.class, value);
+ key += ":" + value.getClass().getName();
}
+ engine.invoke("put", String.class, key, Object.class, value);
}
}
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
index 35576dc..5b41d0f 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
@@ -17,12 +17,14 @@
*/
package org.apache.tools.ant.taskdefs.optional;
+import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileRule;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
/**
* Tests the examples of the <script> task docs.
@@ -64,4 +66,24 @@ public class RhinoScriptTest {
assertTrue(index > -1);
}
+ @Test
+ public void testUseSrcAndEncoding() {
+ final String readerEncoding = "UTF-8";
+ buildRule.getProject().setProperty("useSrcAndEncoding.reader.encoding", readerEncoding);
+ buildRule.executeTarget("useSrcAndEncoding");
+ }
+
+ @Test
+ public void testUseSrcAndEncodingFailure() {
+ final String readerEncoding = "ISO-8859-1";
+ buildRule.getProject().setProperty("useSrcAndEncoding.reader.encoding", readerEncoding);
+ try {
+ buildRule.executeTarget("useSrcAndEncoding");
+ fail("should have failed with reader's encoding [" + readerEncoding +
+ "] different from the writer's encoding [" + buildRule.getProject().getProperty("useSrcAndEncoding.encoding") + "]");
+ }
+ catch(BuildException e) {
+ assertTrue(e.getMessage().matches("expected <eacute \\[\u00e9]> but was <eacute \\[\u00c3\u00a9]>"));
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/ant/blob/ea709175/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
index 5d4d4cf..0b2ebce 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
@@ -142,5 +142,46 @@ public class ScriptDefTest {
log.indexOf("Attribute value = test") != -1);
}
+ @Test
+ public void testUseSrcAndEncoding() {
+ final String readerEncoding = "UTF-8";
+ buildRule.getProject().setProperty("useSrcAndEncoding.reader.encoding", readerEncoding);
+ buildRule.executeTarget("useSrcAndEncoding");
+ }
+
+ @Test
+ public void testUseSrcAndEncodingFailure() {
+ final String readerEncoding = "ISO-8859-1";
+ buildRule.getProject().setProperty("useSrcAndEncoding.reader.encoding", readerEncoding);
+ try {
+ buildRule.executeTarget("useSrcAndEncoding");
+ fail("should have failed with reader's encoding [" + readerEncoding +
+ "] different from the writer's encoding [" +
+ buildRule.getProject().getProperty("useSrcAndEncoding.encoding") + "]");
+ }
+ catch(BuildException e) {
+ assertTrue(e.getMessage().matches(
+ "expected <eacute \\[\u00e9]> but was <eacute \\[\u00c3\u00a9]>"));
+ }
+ }
+ @Test
+ public void testUseCompiled() {
+
+ final long duration;
+ {
+ long start = System.nanoTime();
+ buildRule.executeTarget("useCompiled");
+ duration = System.nanoTime() - start;
+ }
+
+ final long notCompiledDuration;
+ {
+ long start = System.nanoTime();
+ buildRule.executeTarget("useNotCompiled");
+ notCompiledDuration = System.nanoTime() - start;
+ }
+
+ assertTrue(duration < notCompiledDuration);
+ }
}
[09/12] ant git commit: accepted the PR too late for 1.10.1
Posted by bo...@apache.org.
accepted the PR too late for 1.10.1
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/fd4ff012
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/fd4ff012
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/fd4ff012
Branch: refs/heads/master
Commit: fd4ff0120ab95c38554c071ee193a64141d1c987
Parents: 166ce26
Author: Stefan Bodewig <bo...@apache.org>
Authored: Mon Feb 20 17:48:01 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Feb 20 17:48:01 2017 +0100
----------------------------------------------------------------------
manual/Tasks/conditions.html | 2 +-
manual/Tasks/script.html | 2 +-
manual/Tasks/scriptdef.html | 4 ++--
manual/Types/filterchain.html | 2 +-
manual/Types/mapper.html | 2 +-
manual/Types/selectors.html | 2 +-
.../apache/tools/ant/taskdefs/optional/script/ScriptDef.java | 4 ++--
src/main/org/apache/tools/ant/util/ScriptRunnerBase.java | 6 +++---
src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java | 6 +++---
9 files changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/fd4ff012/manual/Tasks/conditions.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/conditions.html b/manual/Tasks/conditions.html
index 895da54..b1c1c31 100644
--- a/manual/Tasks/conditions.html
+++ b/manual/Tasks/conditions.html
@@ -538,7 +538,7 @@ an explanation of scripts and dependencies.
</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">The encoding of the script source. <em>since Ant 1.10.2.</em></td>
<td valign="top" align="center">No - defaults to default JVM encoding</td>
</tr>
<tr>
http://git-wip-us.apache.org/repos/asf/ant/blob/fd4ff012/manual/Tasks/script.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/script.html b/manual/Tasks/script.html
index 7a56eec..d111124 100644
--- a/manual/Tasks/script.html
+++ b/manual/Tasks/script.html
@@ -104,7 +104,7 @@ different location values.</p>
</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">The encoding of the script as a file. <em>since Ant 1.10.2.</em></td>
<td valign="top" align="center">No - defaults to default JVM encoding</td>
</tr>
<tr>
http://git-wip-us.apache.org/repos/asf/ant/blob/fd4ff012/manual/Tasks/scriptdef.html
----------------------------------------------------------------------
diff --git a/manual/Tasks/scriptdef.html b/manual/Tasks/scriptdef.html
index de601a5..f593e61 100644
--- a/manual/Tasks/scriptdef.html
+++ b/manual/Tasks/scriptdef.html
@@ -117,7 +117,7 @@ more information on writing scripts, please refer to the
</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">The encoding of the script as a file. <em>since Ant 1.10.2.</em></td>
<td valign="top" align="center">No - defaults to default JVM encoding</td>
</tr>
<tr>
@@ -126,7 +126,7 @@ more information on writing scripts, please refer to the
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>
+ <em>since Ant 1.10.2.</em></td>
<td valign="top" align="center">No - defaults to false</td>
</tr>
<tr>
http://git-wip-us.apache.org/repos/asf/ant/blob/fd4ff012/manual/Types/filterchain.html
----------------------------------------------------------------------
diff --git a/manual/Types/filterchain.html b/manual/Types/filterchain.html
index 1496816..4c5f94e 100644
--- a/manual/Types/filterchain.html
+++ b/manual/Types/filterchain.html
@@ -1567,7 +1567,7 @@ Must be a supported Apache BSF or JSR 223 language</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">The encoding of the script as a file. <em>since Ant 1.10.2.</em></td>
<td valign="top" align="center">No - defaults to default JVM encoding</td>
</tr>
<tr>
http://git-wip-us.apache.org/repos/asf/ant/blob/fd4ff012/manual/Types/mapper.html
----------------------------------------------------------------------
diff --git a/manual/Types/mapper.html b/manual/Types/mapper.html
index f6bc76d..1da85dc 100644
--- a/manual/Types/mapper.html
+++ b/manual/Types/mapper.html
@@ -807,7 +807,7 @@ an explanation of scripts and dependencies.
</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">The encoding of the script as a file. <em>since Ant 1.10.2.</em></td>
<td valign="top" align="center">No - defaults to default JVM encoding</td>
</tr>
<tr>
http://git-wip-us.apache.org/repos/asf/ant/blob/fd4ff012/manual/Types/selectors.html
----------------------------------------------------------------------
diff --git a/manual/Types/selectors.html b/manual/Types/selectors.html
index 6a080cb..db2ec48 100644
--- a/manual/Types/selectors.html
+++ b/manual/Types/selectors.html
@@ -1109,7 +1109,7 @@
</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">The encoding of the script as a file. <em>since Ant 1.10.2.</em></td>
<td valign="top" align="center">No - defaults to default JVM encoding</td>
</tr>
<tr>
http://git-wip-us.apache.org/repos/asf/ant/blob/fd4ff012/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java b/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
index 7a410e0..7e62549 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
@@ -375,7 +375,7 @@ public class ScriptDef extends DefBase {
* Defines the compilation feature ; optional.
*
* @param compiled enables the script compilation if available.
- * @since Ant 1.10.1
+ * @since Ant 1.10.2
*/
public void setCompiled(boolean compiled) {
helper.setCompiled(compiled);
@@ -394,7 +394,7 @@ public class ScriptDef extends DefBase {
* 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
+ * @since Ant 1.10.2
*/
public void setEncoding(String encoding) {
helper.setEncoding(encoding);
http://git-wip-us.apache.org/repos/asf/ant/blob/fd4ff012/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
index c738999..f78ee23 100644
--- a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
+++ b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
@@ -196,7 +196,7 @@ public abstract class ScriptRunnerBase {
/**
* Whether to use script compilation if available.
- * @since Ant 1.10.1
+ * @since Ant 1.10.2
* @param compiled if true, compile the script if possible.
*/
public final void setCompiled(boolean compiled) {
@@ -205,7 +205,7 @@ public abstract class ScriptRunnerBase {
/**
* Get the compiled attribute.
- * @since Ant 1.10.1
+ * @since Ant 1.10.2
* @return the attribute.
*/
public final boolean getCompiled() {
@@ -214,7 +214,7 @@ public abstract class ScriptRunnerBase {
/**
* Set encoding of the script from an external file; optional.
- * @since Ant 1.10.1
+ * @since Ant 1.10.2
* @param encoding encoding of the external file containing the script source.
*/
public void setEncoding(String encoding) {
http://git-wip-us.apache.org/repos/asf/ant/blob/fd4ff012/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java b/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
index eda0421..fc1be2a 100644
--- a/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
+++ b/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
@@ -118,7 +118,7 @@ public class ScriptRunnerHelper {
/**
* Get the external script file ; optional.
* @return the file containing the script source.
- * @since Ant 1.10.1
+ * @since Ant 1.10.2
*/
public File getSrc() {
return srcFile;
@@ -128,7 +128,7 @@ public class ScriptRunnerHelper {
* Set 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
+ * @since Ant 1.10.2
*/
public void setEncoding(String encoding) {
this.encoding = encoding;
@@ -137,7 +137,7 @@ public class ScriptRunnerHelper {
/**
* Get the external file encoding.
* @return the encoding of the file containing the script source.
- * @since Ant 1.10.1
+ * @since Ant 1.10.2
*/
public String getEncoding() {
return encoding;
[11/12] ant git commit: record PR by Olivier Parent @pyxide - closes
#30
Posted by bo...@apache.org.
record PR by Olivier Parent @pyxide - closes #30
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/13c6aaa3
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/13c6aaa3
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/13c6aaa3
Branch: refs/heads/master
Commit: 13c6aaa37ceecaaba0a952d6a16fb34cc9bc1212
Parents: 96dc65b
Author: Stefan Bodewig <bo...@apache.org>
Authored: Mon Feb 20 17:53:12 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Feb 20 17:53:12 2017 +0100
----------------------------------------------------------------------
CONTRIBUTORS | 1 +
WHATSNEW | 4 ++++
contributors.xml | 4 ++++
3 files changed, 9 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/13c6aaa3/CONTRIBUTORS
----------------------------------------------------------------------
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index 17022c7..6481253 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -283,6 +283,7 @@ Nico Seessle
Nigel Magnay
Oliver Merkel
Oliver Rossmueller
+Olivier Parent
Ondra Medek
Omer Shapira
Oystein Gisnas
http://git-wip-us.apache.org/repos/asf/ant/blob/13c6aaa3/WHATSNEW
----------------------------------------------------------------------
diff --git a/WHATSNEW b/WHATSNEW
index 866080c..beaf7d8 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -8,6 +8,10 @@ Other changes:
values always get quoted.
Github Pull Request #32
+ * Added <encoding> attributes to various script related tasks and a
+ compiled attribute to scriptdef.
+ Github Pull Request #30
+
Changes from Ant 1.10.0 TO Ant 1.10.1
=====================================
http://git-wip-us.apache.org/repos/asf/ant/blob/13c6aaa3/contributors.xml
----------------------------------------------------------------------
diff --git a/contributors.xml b/contributors.xml
index ee049cb..ade30f9 100644
--- a/contributors.xml
+++ b/contributors.xml
@@ -1153,6 +1153,10 @@
<last>Rossmueller</last>
</name>
<name>
+ <first>Olivier</first>
+ <last>Parent</last>
+ </name>
+ <name>
<first>Omer</first>
<last>Shapira</last>
</name>
[02/12] ant git commit: New magic name org.apache.ant.scriptcache
Posted by bo...@apache.org.
New magic name org.apache.ant.scriptcache
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/fd0fb26c
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/fd0fb26c
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/fd0fb26c
Branch: refs/heads/master
Commit: fd0fb26cc5f834595ffbd397550e1555691c299a
Parents: ea70917
Author: pyxide <op...@gmail.com>
Authored: Mon Feb 20 13:26:27 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Feb 20 17:41:37 2017 +0100
----------------------------------------------------------------------
src/main/org/apache/tools/ant/MagicNames.java | 6 ++++++
.../org/apache/tools/ant/util/optional/JavaxScriptRunner.java | 6 +++++-
2 files changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/fd0fb26c/src/main/org/apache/tools/ant/MagicNames.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/MagicNames.java b/src/main/org/apache/tools/ant/MagicNames.java
index bc39a25..336c3bc 100644
--- a/src/main/org/apache/tools/ant/MagicNames.java
+++ b/src/main/org/apache/tools/ant/MagicNames.java
@@ -56,6 +56,12 @@ public final class MagicNames {
public static final String SCRIPT_REPOSITORY = "org.apache.ant.scriptrepo";
/**
+ * The name of the script cache used by the script runner.
+ * Value {@value}
+ */
+ public static final String SCRIPT_CACHE = "org.apache.ant.scriptcache";
+
+ /**
* The name of the reference to the System Class Loader.
* Value {@value}
**/
http://git-wip-us.apache.org/repos/asf/ant/blob/fd0fb26c/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java b/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
index 63ab4d9..997af7a 100644
--- a/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
+++ b/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
@@ -21,6 +21,7 @@ package org.apache.tools.ant.util.optional;
import java.util.Iterator;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.ReflectWrapper;
import org.apache.tools.ant.util.ScriptRunnerBase;
@@ -84,7 +85,10 @@ public class JavaxScriptRunner extends ScriptRunnerBase {
if (getCompiled()) {
- final String compiledScriptRefName = execName + ".compiled." + getScript().hashCode() + "." + getProject().hashCode();
+ final String compiledScriptRefName = MagicNames.SCRIPT_CACHE + "." + getLanguage() +
+ "." + getScript().hashCode() + "." +
+ (null == getClass().getClassLoader() ? 0 : getClass().getClassLoader().hashCode());
+
if (null == compiledScript) {
compiledScript = getProject().getReference(compiledScriptRefName);
}
[04/12] ant git commit: Scriptdef task new options : 'compiled' (if
javax.script engine implements Compilable), 'encoding' to load resources
Posted by bo...@apache.org.
Scriptdef task new options : 'compiled' (if javax.script engine implements Compilable), 'encoding' to load resources
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/4bd9b4a6
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/4bd9b4a6
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/4bd9b4a6
Branch: refs/heads/master
Commit: 4bd9b4a6e473a9188124989315f75b778ad2a363
Parents: 526df1e
Author: pyxide <op...@gmail.com>
Authored: Fri Jan 13 17:16:50 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Feb 20 17:41:37 2017 +0100
----------------------------------------------------------------------
.../ant/taskdefs/optional/script/ScriptDef.java | 22 +++-
.../apache/tools/ant/util/ScriptRunnerBase.java | 87 +++++++++++++--
.../tools/ant/util/ScriptRunnerHelper.java | 40 +++++++
.../ant/util/optional/JavaxScriptRunner.java | 108 ++++++++++++++++---
4 files changed, 230 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/4bd9b4a6/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java b/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
index ac9eb88..3f40a14 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
@@ -67,7 +67,7 @@ public class ScriptDef extends DefBase {
/**
* Set the project.
- * @param project the project that this def belows to.
+ * @param project the project that this definition belongs to.
*/
public void setProject(Project project) {
super.setProject(project);
@@ -237,7 +237,6 @@ public class ScriptDef extends DefBase {
+ "attributes");
}
-
nestedElementMap.put(nestedElement.name, nestedElement);
}
@@ -368,6 +367,15 @@ public class ScriptDef extends DefBase {
}
/**
+ * Defines the language (required).
+ *
+ * @param language the scripting language name for the script.
+ */
+ public void setCompiled(boolean compiled) {
+ helper.setCompiled(compiled);
+ }
+
+ /**
* Load the script from an external file ; optional.
*
* @param file the file containing the script source.
@@ -377,6 +385,15 @@ public class ScriptDef extends DefBase {
}
/**
+ * Set the encoding of the script from an external file ; optional.
+ *
+ * @param encoding the encoding of the file containing the script source.
+ */
+ public void setEncoding(String encoding) {
+ helper.setEncoding(encoding);
+ }
+
+ /**
* Set the script text.
*
* @param text a component of the script text to be added.
@@ -394,4 +411,3 @@ public class ScriptDef extends DefBase {
helper.add(resource);
}
}
-
http://git-wip-us.apache.org/repos/asf/ant/blob/4bd9b4a6/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
index b8aa01a..ac08f98 100644
--- a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
+++ b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
@@ -19,12 +19,13 @@ package org.apache.tools.ant.util;
import java.io.BufferedReader;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -34,6 +35,8 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.types.resources.PropertyResource;
+import org.apache.tools.ant.types.resources.StringResource;
/**
* This is a common abstract base case for script runners.
@@ -51,6 +54,11 @@ public abstract class ScriptRunnerBase {
/** Script content */
private String script = "";
+ private String encoding;
+
+ /** Enable script compilation. */
+ private boolean compiled;
+
/** Project this runner is used in */
private Project project;
@@ -187,7 +195,35 @@ public abstract class ScriptRunnerBase {
}
/**
+ * Whether to use script compilation if available.
+ * @since Ant 1.10.1
+ * @param compiled if true, compile the script if possible.
+ */
+ public final void setCompiled(boolean compiled) {
+ this.compiled = compiled;
+ }
+
+ /**
+ * Get the compiled attribute.
+ * @since Ant 1.10.1
+ * @return the attribute.
+ */
+ public final boolean getCompiled() {
+ return compiled;
+ }
+
+ /**
+ * Set encoding of the script from an external file; optional.
+ * @since Ant 1.10.1
+ * @param encoding encoding of the external file containing the script source.
+ */
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ /**
* Load the script from an external file; optional.
+ * @since Ant 1.10.1
* @param file the file containing the script source.
*/
public void setSrc(File file) {
@@ -195,12 +231,19 @@ public abstract class ScriptRunnerBase {
if (!file.exists()) {
throw new BuildException("file " + filename + " not found.");
}
+ InputStream in = null;
try {
- readSource(new FileReader(file), filename);
+ in = new FileInputStream(file);
} catch (FileNotFoundException e) {
//this can only happen if the file got deleted a short moment ago
throw new BuildException("file " + filename + " not found.");
}
+
+ try {
+ readSource(in, filename);
+ } finally {
+ FileUtils.close(in);
+ }
}
/**
@@ -208,19 +251,25 @@ public abstract class ScriptRunnerBase {
* @param reader the reader; this is closed afterwards.
* @param name the name to use in error messages
*/
- private void readSource(Reader reader, String name) {
- BufferedReader in = null;
+ private void readSource(InputStream in, String name) {
+ Reader reader = null;
try {
- in = new BufferedReader(reader);
- script += FileUtils.safeReadFully(in);
+ if (null == encoding) {
+ reader = new InputStreamReader(in);
+ } else {
+ reader = new InputStreamReader(in, encoding);
+ }
+ reader = new BufferedReader(reader);
+ script += FileUtils.safeReadFully(reader);
+ } catch(UnsupportedEncodingException e) {
+ throw new BuildException("Failed to decode " + name + " with encoding " + encoding, e);
} catch (IOException ex) {
throw new BuildException("Failed to read " + name, ex);
} finally {
- FileUtils.close(in);
+ FileUtils.close(reader);
}
}
-
/**
* Add a resource to the source list.
* @since Ant 1.7.1
@@ -228,6 +277,20 @@ public abstract class ScriptRunnerBase {
* @throws BuildException if the resource cannot be read
*/
public void loadResource(Resource sourceResource) {
+ if(sourceResource instanceof StringResource) {
+ // Note: StringResource uses UTF-8 by default to encode/decode, not the default platform encoding
+ script += ((StringResource) sourceResource).getValue();
+ return;
+ }
+ if(sourceResource instanceof PropertyResource) {
+ script += ((PropertyResource) sourceResource).getValue();
+ return;
+ }
+
+ // Concat resource
+
+ // FileResource : OK for default encoding
+
String name = sourceResource.toLongString();
InputStream in = null;
try {
@@ -238,7 +301,12 @@ public abstract class ScriptRunnerBase {
throw new BuildException(
"Failed to open " + name + " -it is not readable", e);
}
- readSource(new InputStreamReader(in), name);
+
+ try {
+ readSource(in, name);
+ } finally {
+ FileUtils.close(in);
+ }
}
/**
@@ -356,5 +424,4 @@ public abstract class ScriptRunnerBase {
Thread.currentThread().setContextClassLoader(
origLoader);
}
-
}
http://git-wip-us.apache.org/repos/asf/ant/blob/4bd9b4a6/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java b/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
index 9e814d9..5cc23ab 100644
--- a/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
+++ b/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
@@ -31,9 +31,11 @@ import org.apache.tools.ant.types.resources.Union;
public class ScriptRunnerHelper {
private ClasspathUtils.Delegate cpDelegate = null;
private File srcFile;
+ private String encoding;
private String manager = "auto";
private String language;
private String text;
+ private boolean compiled = false;
private boolean setBeans = true;
private ProjectComponent projectComponent;
private ClassLoader scriptLoader = null;
@@ -53,6 +55,12 @@ public class ScriptRunnerHelper {
*/
public ScriptRunnerBase getScriptRunner() {
ScriptRunnerBase runner = getRunner();
+ runner.setCompiled(compiled);
+
+ if (encoding != null) {
+ // set it first, because runner.setSrc() loads immediately the file
+ runner.setEncoding(encoding);
+ }
if (srcFile != null) {
runner.setSrc(srcFile);
}
@@ -108,6 +116,16 @@ public class ScriptRunnerHelper {
}
/**
+ * Set 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) {
+ this.encoding = encoding;
+ }
+
+ /**
* Add script text.
*
* @param text a component of the script text to be added.
@@ -143,6 +161,28 @@ public class ScriptRunnerHelper {
}
/**
+ * Enable the compilation of the script if possible.
+ * If this is true and the compilation feature is available in
+ * the script engine, the script is compiled before the first
+ * evaluation, and should be cached for future evaluations.
+ * Otherwise, a script is evaluated is used.
+ * The default is false.
+ *
+ * @param compiled the value to set.
+ */
+ public void setCompiled(boolean compiled) {
+ this.compiled = compiled;
+ }
+
+ /**
+ * Get the compilation feature.
+ * @return the compilation feature.
+ */
+ public boolean getCompiled() {
+ return this.compiled;
+ }
+
+ /**
* Set the setbeans attribute.
* If this is true, <script> will create variables in the
* script instance for all
http://git-wip-us.apache.org/repos/asf/ant/blob/4bd9b4a6/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java b/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
index 7a5cfa4..2670b09 100644
--- a/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
+++ b/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
@@ -21,6 +21,7 @@ package org.apache.tools.ant.util.optional;
import java.util.Iterator;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.ReflectWrapper;
import org.apache.tools.ant.util.ScriptRunnerBase;
@@ -31,6 +32,11 @@ import org.apache.tools.ant.util.ScriptRunnerBase;
public class JavaxScriptRunner extends ScriptRunnerBase {
private ReflectWrapper engine;
+ /** Debug constant */
+ private static final boolean DEBUG = Boolean.getBoolean("JavaxScriptRunner.DEBUG");
+
+ private String compiledScriptRefName;
+
/**
* Get the name of the manager prefix.
* @return "javax"
@@ -79,28 +85,85 @@ public class JavaxScriptRunner extends ScriptRunnerBase {
checkLanguage();
ClassLoader origLoader = replaceContextLoader();
try {
+
+ if(DEBUG) System.out.println("-- JavaxScriptRunner.evaluateScript : compile enabled [" + getCompiled() + "]");
+
+ if (getCompiled()) {
+
+ if (null == compiledScriptRefName) {
+ compiledScriptRefName = execName + ".compiledScript.0123456789";
+ }
+ ReflectWrapper scriptRefObj = getProject().getReference(compiledScriptRefName);
+
+ if (null == scriptRefObj) {
+
+ ReflectWrapper engine = createEngine();
+ if (engine == null) {
+ throw new BuildException(
+ "Unable to create javax script engine for "
+ + getLanguage());
+ }
+
+ final Class engineClass = Class.forName("javax.script.ScriptEngine");
+ final Class compilableClass = Class.forName("javax.script.Compilable");
+ final Object wrappedObject = engine.getObject();
+
+ if (DEBUG) System.out.println("-- JavaxScriptRunner.evaluateScript : wrappedObject [" + wrappedObject.getClass().getName() + "]");
+ if (engineClass.isAssignableFrom(wrappedObject.getClass()) && compilableClass.isAssignableFrom(wrappedObject.getClass())) {
+
+ if(DEBUG) System.out.println("-- JavaxScriptRunner.evaluateScript : compilable [" + wrappedObject.getClass().getName() + "]");
+
+ {
+ getProject().log("compile script" + compiledScriptRefName, Project.MSG_VERBOSE);
+
+ // compilable engine
+ final Object compiledScript = engine.invoke("compile", String.class, getScript());
+ scriptRefObj = new ReflectWrapper(compiledScript);
+ }
+
+ getProject().log("store compiled script, ref " + compiledScriptRefName, Project.MSG_DEBUG);
+
+ } else {
+ getProject().log("script compilation not available", Project.MSG_DEBUG);
+ scriptRefObj = new ReflectWrapper(null);
+ }
+
+ getProject().addReference(compiledScriptRefName, scriptRefObj);
+ }
+
+ if (null != scriptRefObj.getObject()) {
+
+ if (DEBUG) System.out.println("-- JavaxScriptRunner.evaluateScript : execute compiled script");
+
+ final Object simpleBindings;
+ {
+ final Class simpleBindingsClass = Class.forName("javax.script.SimpleBindings");
+ simpleBindings = simpleBindingsClass.newInstance();
+ }
+
+ applyBindings(new ReflectWrapper(simpleBindings));
+ if (DEBUG) System.out.println("-- JavaxScriptRunner.evaluateScript : bindings applied");
+
+ getProject().log("run compiled script, ref " + compiledScriptRefName, Project.MSG_DEBUG);
+
+ final Class bindingsClass = Class.forName("javax.script.Bindings");
+
+ return scriptRefObj.invoke("eval", bindingsClass, simpleBindings);
+ }
+ }
+
ReflectWrapper engine = createEngine();
if (engine == null) {
throw new BuildException(
"Unable to create javax script engine for "
+ getLanguage());
}
- for (Iterator i = getBeans().keySet().iterator(); i.hasNext();) {
- 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);
- }
- }
+
+ applyBindings(engine);
+
// execute the script
return engine.invoke("eval", String.class, getScript());
+
} catch (BuildException be) {
//catch and rethrow build exceptions
@@ -126,6 +189,23 @@ public class JavaxScriptRunner extends ScriptRunnerBase {
}
}
+ private void applyBindings(ReflectWrapper engine) {
+ for (Iterator i = getBeans().keySet().iterator(); i.hasNext();) {
+ 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);
+ }
+ }
+ }
+
private ReflectWrapper createEngine() {
if (engine != null) {
return engine;
[06/12] ant git commit: Fix CRLF to LF
Posted by bo...@apache.org.
Fix CRLF to LF
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/1630d0c0
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/1630d0c0
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/1630d0c0
Branch: refs/heads/master
Commit: 1630d0c0ff3bb7d06fb11cf04fa50ada64740dd9
Parents: 4bd9b4a
Author: pyxide <op...@gmail.com>
Authored: Mon Jan 16 13:48:26 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Feb 20 17:41:37 2017 +0100
----------------------------------------------------------------------
----------------------------------------------------------------------
[07/12] ant git commit: Cleaning,
proper classpath in JavaxScriptRunner
Posted by bo...@apache.org.
Cleaning, proper classpath in JavaxScriptRunner
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/49896d33
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/49896d33
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/49896d33
Branch: refs/heads/master
Commit: 49896d33693b9fb3b766757c566fc862a6f0c0cf
Parents: 1630d0c
Author: pyxide <op...@gmail.com>
Authored: Tue Jan 17 00:38:36 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Feb 20 17:41:37 2017 +0100
----------------------------------------------------------------------
.../ant/taskdefs/optional/script/ScriptDef.java | 11 +++-
.../apache/tools/ant/util/ScriptRunnerBase.java | 31 +++++-----
.../tools/ant/util/ScriptRunnerHelper.java | 26 ++++++--
.../ant/util/optional/JavaxScriptRunner.java | 65 +++++++-------------
4 files changed, 68 insertions(+), 65 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/49896d33/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java b/src/main/org/apache/tools/ant/taskdefs/optional/script/ScriptDef.java
index 3f40a14..e45668c 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
@@ -188,10 +188,15 @@ public class ScriptDef extends DefBase {
}
if (helper.getLanguage() == null) {
- throw new BuildException("<scriptdef> requires a language attribute "
+ throw new BuildException("scriptdef requires a language attribute "
+ "to specify the script language");
}
+ if (helper.getSrc() == null && helper.getEncoding() != null) {
+ throw new BuildException("scriptdef requires a src attribute "
+ + "if the encoding is set");
+ }
+
// Check if need to set the loader
if (getAntlibClassLoader() != null || hasCpDelegate()) {
helper.setClassLoader(createLoader());
@@ -367,9 +372,9 @@ public class ScriptDef extends DefBase {
}
/**
- * Defines the language (required).
+ * Defines the compilation feature (optional).
*
- * @param language the scripting language name for the script.
+ * @param compiled enables the script compilation if available.
*/
public void setCompiled(boolean compiled) {
helper.setCompiled(compiled);
http://git-wip-us.apache.org/repos/asf/ant/blob/49896d33/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
index ac08f98..ae0af33 100644
--- a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
+++ b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
@@ -25,7 +25,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -223,7 +223,6 @@ public abstract class ScriptRunnerBase {
/**
* Load the script from an external file; optional.
- * @since Ant 1.10.1
* @param file the file containing the script source.
*/
public void setSrc(File file) {
@@ -231,6 +230,7 @@ public abstract class ScriptRunnerBase {
if (!file.exists()) {
throw new BuildException("file " + filename + " not found.");
}
+
InputStream in = null;
try {
in = new FileInputStream(file);
@@ -239,8 +239,15 @@ public abstract class ScriptRunnerBase {
throw new BuildException("file " + filename + " not found.");
}
+ final Charset charset;
+ if (null == encoding) {
+ charset = null;
+ } else {
+ charset = Charset.forName(encoding);
+ }
+
try {
- readSource(in, filename);
+ readSource(in, filename, charset);
} finally {
FileUtils.close(in);
}
@@ -250,19 +257,18 @@ public abstract class ScriptRunnerBase {
* Read some source in from the given reader
* @param reader the reader; this is closed afterwards.
* @param name the name to use in error messages
+ * @param charset the encoding for the reader, may be null.
*/
- private void readSource(InputStream in, String name) {
+ private void readSource(InputStream in, String name, Charset charset) {
Reader reader = null;
try {
- if (null == encoding) {
+ if (null == charset) {
reader = new InputStreamReader(in);
} else {
- reader = new InputStreamReader(in, encoding);
+ reader = new InputStreamReader(in, charset);
}
reader = new BufferedReader(reader);
script += FileUtils.safeReadFully(reader);
- } catch(UnsupportedEncodingException e) {
- throw new BuildException("Failed to decode " + name + " with encoding " + encoding, e);
} catch (IOException ex) {
throw new BuildException("Failed to read " + name, ex);
} finally {
@@ -278,7 +284,6 @@ public abstract class ScriptRunnerBase {
*/
public void loadResource(Resource sourceResource) {
if(sourceResource instanceof StringResource) {
- // Note: StringResource uses UTF-8 by default to encode/decode, not the default platform encoding
script += ((StringResource) sourceResource).getValue();
return;
}
@@ -287,10 +292,6 @@ public abstract class ScriptRunnerBase {
return;
}
- // Concat resource
-
- // FileResource : OK for default encoding
-
String name = sourceResource.toLongString();
InputStream in = null;
try {
@@ -299,11 +300,11 @@ public abstract class ScriptRunnerBase {
throw new BuildException("Failed to open " + name, e);
} catch (UnsupportedOperationException e) {
throw new BuildException(
- "Failed to open " + name + " -it is not readable", e);
+ "Failed to open " + name + " - it is not readable", e);
}
try {
- readSource(in, name);
+ readSource(in, name, (Charset) null);
} finally {
FileUtils.close(in);
}
http://git-wip-us.apache.org/repos/asf/ant/blob/49896d33/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java b/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
index 5cc23ab..528a565 100644
--- a/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
+++ b/src/main/org/apache/tools/ant/util/ScriptRunnerHelper.java
@@ -58,7 +58,7 @@ public class ScriptRunnerHelper {
runner.setCompiled(compiled);
if (encoding != null) {
- // set it first, because runner.setSrc() loads immediately the file
+ // set it first, because runner.setSrc() loads immediately the file
runner.setEncoding(encoding);
}
if (srcFile != null) {
@@ -116,14 +116,32 @@ public class ScriptRunnerHelper {
}
/**
+ * Get the external script file ; optional.
+ * @return the file containing the script source.
+ * @since Ant 1.10.1
+ */
+ public File getSrc() {
+ return srcFile;
+ }
+
+ /**
* Set 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) {
- this.encoding = encoding;
- }
+ public void setEncoding(String encoding) {
+ this.encoding = encoding;
+ }
+
+ /**
+ * Get the external file encoding.
+ * @return the encoding of the file containing the script source.
+ * @since Ant 1.10.1
+ */
+ public String getEncoding() {
+ return encoding;
+ }
/**
* Add script text.
http://git-wip-us.apache.org/repos/asf/ant/blob/49896d33/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java b/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
index 2670b09..7209e28 100644
--- a/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
+++ b/src/main/org/apache/tools/ant/util/optional/JavaxScriptRunner.java
@@ -31,11 +31,7 @@ import org.apache.tools.ant.util.ScriptRunnerBase;
*/
public class JavaxScriptRunner extends ScriptRunnerBase {
private ReflectWrapper engine;
-
- /** Debug constant */
- private static final boolean DEBUG = Boolean.getBoolean("JavaxScriptRunner.DEBUG");
-
- private String compiledScriptRefName;
+ private ReflectWrapper compiledScript;
/**
* Get the name of the manager prefix.
@@ -86,16 +82,14 @@ public class JavaxScriptRunner extends ScriptRunnerBase {
ClassLoader origLoader = replaceContextLoader();
try {
- if(DEBUG) System.out.println("-- JavaxScriptRunner.evaluateScript : compile enabled [" + getCompiled() + "]");
-
if (getCompiled()) {
- if (null == compiledScriptRefName) {
- compiledScriptRefName = execName + ".compiledScript.0123456789";
- }
- ReflectWrapper scriptRefObj = getProject().getReference(compiledScriptRefName);
+ final String compiledScriptRefName = execName + ".compiledScript.0123456789";
+ if (null == compiledScript) {
+ compiledScript = getProject().getReference(compiledScriptRefName);
+ }
- if (null == scriptRefObj) {
+ if (null == compiledScript) {
ReflectWrapper engine = createEngine();
if (engine == null) {
@@ -104,51 +98,36 @@ public class JavaxScriptRunner extends ScriptRunnerBase {
+ getLanguage());
}
- final Class engineClass = Class.forName("javax.script.ScriptEngine");
- final Class compilableClass = Class.forName("javax.script.Compilable");
+ final Class engineClass = Class.forName("javax.script.ScriptEngine", true, getClass().getClassLoader());
+ final Class compilableClass = Class.forName("javax.script.Compilable", true, getClass().getClassLoader());
final Object wrappedObject = engine.getObject();
- if (DEBUG) System.out.println("-- JavaxScriptRunner.evaluateScript : wrappedObject [" + wrappedObject.getClass().getName() + "]");
- if (engineClass.isAssignableFrom(wrappedObject.getClass()) && compilableClass.isAssignableFrom(wrappedObject.getClass())) {
-
- if(DEBUG) System.out.println("-- JavaxScriptRunner.evaluateScript : compilable [" + wrappedObject.getClass().getName() + "]");
+ if (engineClass.isAssignableFrom(wrappedObject.getClass()) &&
+ compilableClass.isAssignableFrom(wrappedObject.getClass())) {
- {
- getProject().log("compile script" + compiledScriptRefName, Project.MSG_VERBOSE);
+ getProject().log("compile script " + execName, Project.MSG_VERBOSE);
- // compilable engine
- final Object compiledScript = engine.invoke("compile", String.class, getScript());
- scriptRefObj = new ReflectWrapper(compiledScript);
- }
-
- getProject().log("store compiled script, ref " + compiledScriptRefName, Project.MSG_DEBUG);
+ final Object compiled = engine.invoke("compile", String.class, getScript());
+ compiledScript = new ReflectWrapper(compiled);
} else {
- getProject().log("script compilation not available", Project.MSG_DEBUG);
- scriptRefObj = new ReflectWrapper(null);
+ getProject().log("script compilation not available", Project.MSG_VERBOSE);
+ compiledScript = new ReflectWrapper(null);
}
-
- getProject().addReference(compiledScriptRefName, scriptRefObj);
+ getProject().addReference(compiledScriptRefName, compiledScript);
}
- if (null != scriptRefObj.getObject()) {
+ if (null != compiledScript.getObject()) {
- if (DEBUG) System.out.println("-- JavaxScriptRunner.evaluateScript : execute compiled script");
-
- final Object simpleBindings;
- {
- final Class simpleBindingsClass = Class.forName("javax.script.SimpleBindings");
- simpleBindings = simpleBindingsClass.newInstance();
- }
+ final ReflectWrapper simpleBindings = new ReflectWrapper(getClass().getClassLoader(), "javax.script.SimpleBindings");
- applyBindings(new ReflectWrapper(simpleBindings));
- if (DEBUG) System.out.println("-- JavaxScriptRunner.evaluateScript : bindings applied");
+ applyBindings(simpleBindings);
- getProject().log("run compiled script, ref " + compiledScriptRefName, Project.MSG_DEBUG);
+ getProject().log("run compiled script " + execName, Project.MSG_DEBUG);
- final Class bindingsClass = Class.forName("javax.script.Bindings");
+ final Class bindingsClass = Class.forName("javax.script.Bindings", true, getClass().getClassLoader());
- return scriptRefObj.invoke("eval", bindingsClass, simpleBindings);
+ return compiledScript.invoke("eval", bindingsClass, simpleBindings.getObject());
}
}
[10/12] ant git commit: whitespace
Posted by bo...@apache.org.
whitespace
Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/96dc65b2
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/96dc65b2
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/96dc65b2
Branch: refs/heads/master
Commit: 96dc65b2dab50095571927a088ddcf8c3f46ac19
Parents: fd4ff01
Author: Stefan Bodewig <bo...@apache.org>
Authored: Mon Feb 20 17:52:50 2017 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon Feb 20 17:52:50 2017 +0100
----------------------------------------------------------------------
.../apache/tools/ant/util/ScriptRunnerBase.java | 22 ++++++++++----------
.../ant/taskdefs/optional/RhinoScriptTest.java | 2 +-
2 files changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ant/blob/96dc65b2/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
index f78ee23..f2b6017 100644
--- a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
+++ b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
@@ -241,15 +241,15 @@ public abstract class ScriptRunnerBase {
final Charset charset;
if (null == encoding) {
- charset = null;
+ charset = null;
} else {
- charset = Charset.forName(encoding);
+ charset = Charset.forName(encoding);
}
try {
readSource(in, filename, charset);
} finally {
- FileUtils.close(in);
+ FileUtils.close(in);
}
}
@@ -283,14 +283,14 @@ public abstract class ScriptRunnerBase {
* @throws BuildException if the resource cannot be read
*/
public void loadResource(Resource sourceResource) {
- if (sourceResource instanceof StringResource) {
- script += ((StringResource) sourceResource).getValue();
- return;
- }
- if (sourceResource instanceof PropertyResource) {
- script += ((PropertyResource) sourceResource).getValue();
- return;
- }
+ if (sourceResource instanceof StringResource) {
+ script += ((StringResource) sourceResource).getValue();
+ return;
+ }
+ if (sourceResource instanceof PropertyResource) {
+ script += ((PropertyResource) sourceResource).getValue();
+ return;
+ }
String name = sourceResource.toLongString();
InputStream in = null;
http://git-wip-us.apache.org/repos/asf/ant/blob/96dc65b2/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
index 5b41d0f..b383ca9 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
@@ -35,7 +35,7 @@ public class RhinoScriptTest {
@Rule
public BuildFileRule buildRule = new BuildFileRule();
-
+
@Before
public void setUp() {
buildRule.configureProject("src/etc/testcases/taskdefs/optional/script.xml");