ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 52101] Could we please have ant properties in scope in javascript under <script/>
Date Tue, 06 Dec 2011 18:36:53 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=52101

--- Comment #3 from Jesse Glick <jglick@netbeans.org> 2011-12-06 18:36:53 UTC ---
Note that ScriptRunnerBase.bindToComponent already does

        addBeans(project.getProperties());

meaning that this works:

        <property name="foobie" value="bletch"/>
        <script language="javascript">
            println(foobie)
        <interpreted that, but it /script>

but this does not:

        <property name="foo.bie" value="bletch"/>
        <script language="javascript">
            println(foo.bie)
        </script>

The problem is that addBean will only define "variables" whose names look like
Java identifiers, and this of course excludes typical dotted properties (which
Rhino would anyway treat as nested lookups). This could be solved using
java.util.Map for languages that interpret Java maps (Groovy etc. I think).
Unfortunately Rhino does not; and

Index: src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
===================================================================
--- src/main/org/apache/tools/ant/util/ScriptRunnerBase.java    (revision
1204648)
+++ src/main/org/apache/tools/ant/util/ScriptRunnerBase.java    (working copy)
@@ -35,6 +35,7 @@
 import java.util.Map;
 import java.util.HashMap;
 import java.util.Iterator;
+import sun.org.mozilla.javascript.internal.NativeObject;

 /**
  * This is a common abstract base case for script runners.
@@ -98,6 +99,13 @@

         if (isValid) {
             beans.put(key, bean);
+        } else {
+            int dot = key.lastIndexOf('.');
+            if (dot != -1) {
+                NativeObject o = new NativeObject();
+                o.defineProperty(key.substring(dot + 1), bean,
NativeObject.READONLY);
+                addBean(key.substring(0, dot), o);
+            }
         }
     }

as per [1] might work (on Rhino only!) if it were compilable, but it is not.

[1] http://stackoverflow.com/a/7575789/12916

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

Mime
View raw message