Peter Reilly | 3 Feb 2004 14:58
Favicon

[Patch] Support for the groovy language with the ant <script> task

Hi,

I have been looking at the groovy language:
http://groovy.codehaus.org/
and the <script> task.

The included patch will allow groovy to
be one of the supported languages for <script> allowing
the following:

    <script language="groovy"><![CDATA[
      z = <<<END
      this is a multi
      line string
END

      println(z);
      list = [1, 2, 3]
      println(list[0..2])
      map=["a":1, "b":2]
      println("a is " + map["a"])

    ]]></script>

printing out:

Declaring bean: g3 value: g3
Declaring bean: s2 value: s2
Declaring bean: self value: org.apache.tools.ant.taskdefs.optional.Script <at> 11d0a4f
Declaring bean: s5 value: s5
Declaring bean: project value: org.apache.tools.ant.Project <at> 18fd984
Declaring bean: s4 value: s4
Declaring bean: b3 value: b3
Declaring bean: g value: g
Declaring bean: s3 value: s3
Declaring bean: b value: b
Declaring bean: basedir value: /home/preilly/learning/ant
Declaring bean: s value: s
      this is a multi
      line string
[1, 2, 3]
a is 1

(The "Declaring bean" prints are due to a printf  in groovy - 1.0.beta-3). (org.codehaus.groovy.bsf.GroovyEngine)

The patch are two changes:

   Script.java :       the Groovy language does not like "<ANT>" to be the name of the script
                       changed to "ANT" (For some reason it attempts to make a class? for the name).

   ScriptDef.java:     Changed from "script <name>" to "script_name"

   ScriptRunner.java : add groovy to the BSF supported languages (in the same way that beanshell used
                                   to be added to BSF).

  
I would like to make the changes to ANT CVS and possiblely to the ant 1.6 branch.

Peter

Gmane