This is an automated email from the ASF dual-hosted git repository. mbenson pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ant.git
The following commit(s) were added to refs/heads/master by this push: new c4552aa scriptdef += @setbeans c4552aa is described below commit c4552aaaf2932144e2d689a838a9a0db02c64741 Author: Matt Benson <mben...@apache.org> AuthorDate: Fri Feb 25 17:55:40 2022 -0600 scriptdef += @setbeans --- manual/Tasks/script.html | 6 +++--- manual/Tasks/scriptdef.html | 8 ++++++++ .../ant/taskdefs/optional/script/ScriptDef.java | 22 +++++++++++++++++++++- .../taskdefs/optional/script/scriptdef-test.xml | 10 ++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/manual/Tasks/script.html b/manual/Tasks/script.html index 94c8187..043d4c6 100644 --- a/manual/Tasks/script.html +++ b/manual/Tasks/script.html @@ -101,9 +101,9 @@ In particular all targets should have different location values.</p> <tr> <td>setbeans</td> <td>This attribute controls whether to set variables for all properties, references and targets - in the running script. If this attribute is <q>false</q>, only the the <code>project</code> - and <code>self</code> variables are set. If this attribute is <q>true</q> all the variables - are set. <em>Since Ant 1.7</em></td> + in the running script. If this attribute is <q>false</q>, only the <code>project</code> and + <code>self</code> variables are set. If this attribute is <q>true</q> all the variables are + set. <em>Since Ant 1.7</em></td> <td>No; defaults to <q>true</q></td> </tr> <tr> diff --git a/manual/Tasks/scriptdef.html b/manual/Tasks/scriptdef.html index a741fba..ba88bd1 100644 --- a/manual/Tasks/scriptdef.html +++ b/manual/Tasks/scriptdef.html @@ -132,6 +132,14 @@ the <a href="script.html"><code><script></code></a> task.</p> </td> <td>No</td> </tr> + <tr> + <td>setbeans</td> + <td>This attribute controls whether to set variables for all properties, references and targets + in the running script. If this attribute is <q>false</q>, only the <code>project</code> and + <code>self</code> variables are set. If this attribute is <q>true</q> all the variables are + set. + <td>No; default <q>false</q> for backward compatibility</td> + </tr> </table> <h3>Parameters specified as nested elements</h3> 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 f1c5d4e..da8ea10 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 @@ -68,6 +68,13 @@ public class ScriptDef extends DefBase { private Map<String, NestedElement> nestedElementMap; /** + * Create a new {@link ScriptDef}. + */ + public ScriptDef() { + helper.setSetBeans(false); + } + + /** * Set the project. * @param project the project that this definition belongs to. */ @@ -75,7 +82,6 @@ public class ScriptDef extends DefBase { public void setProject(Project project) { super.setProject(project); helper.setProjectComponent(this); - helper.setSetBeans(false); } /** @@ -448,6 +454,20 @@ public class ScriptDef extends DefBase { } /** + * Set the setbeans attribute. + * If this is true, <script> will create variables in the + * script instance for all + * properties, targets and references of the current project. + * It this is false, only the project and self variables will + * be set. + * The default is true. + * @param setBeans the value to set. + */ + public void setSetBeans(boolean setBeans) { + helper.setSetBeans(setBeans); + } + + /** * Sets the script text. * * @param text a component of the script text to be added. diff --git a/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml b/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml index ed87a34..62ddda6 100644 --- a/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml +++ b/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml @@ -155,4 +155,14 @@ <scripttest foo="bar" /> </au:expectfailure> </target> + + <target name="testSetbeans" if="prereqs-ok"> + <js setbeans="true"> + project.setNewProperty('property', sourceProperty) + </js> + <property name="sourceProperty" value="live" /> + <scripttest /> + <assertPropSet /> + </target> + </project>