groovy
  1. groovy
  2. GROOVY-1594

Bundle JSR 223 Support in Groovy

    Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0, 1.1-rc-3
    • Fix Version/s: 1.6-rc-1, 1.6-rc-2, 1.7.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      N/A
    • Number of attachments :
      1

      Description

      Now that Java 6 released, there's a lot of interest going around about the new JSR 223 scripting platform. Unfortunately, neither Java SE 6 nor the current Groovy builds support JSR 223-style Groovy out of the box.

      Fortunately, adding this to Groovy is trivial. The code is both simple and available from the JSR 223 reference implementation (https://scripting.dev.java.net/). The license permits redistributing as source or binary as long as mention that some code comes from Sun and release them from liability.

      Ideally, the Groovy project should integrate the three implementation classes and the service declaration into groovy-1.0.jar. If you do this, simply dropping Groovy into your classpath is enough to enable the Groovy engine. At the very least, we should bundle the RI's groovy-engine.jar into the groovy binary distribution. Finding and installing the Sun RI is a bit of a pain and will discourage would-be users.

      Behind the scenes, scripting engines get enabled by adding a file to the META-INF/services directory of a JAR as specified in the new Java 6 java.util.ServiceLoader (http://java.sun.com/javase/6/docs/api/java/util/ServiceLoader.html). This file just tells the JVM that it can find a service implementation in a specific class. For JSR 223, the implementation is just a concrete ScriptEngineFactory and a couple of support classes:

      https://scripting.dev.java.net/source/browse/scripting/engines/groovy/src/META-INF/services/javax.script.ScriptEngineFactory?rev=1.1.1.1&view=auto&content-type=text/vnd.viewcvs-markup

      https://scripting.dev.java.net/source/browse/scripting/engines/groovy/src/com/sun/script/groovy/GroovyScriptEngineFactory.java?rev=1.4&view=auto&content-type=text/vnd.viewcvs-markup

      https://scripting.dev.java.net/source/browse/scripting/engines/groovy/src/com/sun/script/groovy/GroovyCompiledScript.java?rev=1.1.1.1&view=auto&content-type=text/vnd.viewcvs-markup

      https://scripting.dev.java.net/source/browse/scripting/engines/groovy/src/com/sun/script/groovy/GroovyScriptEngine.java?rev=1.4&view=auto&content-type=text/vnd.viewcvs-markup

      I'm happy to volunteer any assistance that might help make this part of the Groovy distribution. However, adding these classes and the service definition to groovy-1.0.jar should be trivial and will provide a great service (pun intended).

        Activity

        Hide
        Sarah Gerweck added a comment -

        If you do this right, this new dependency should only occur at build time, and wouldn't exist if you do your builds in Java 6. You also shouldn't need JUnit just to do a build: you're just need something to declare the ScriptEngine API so the compiler can do its type checking.

        I haven't reviewed the patch, but you should be able to drop it in without any run-time requirements change. As long as you don't use the class, you won't need the JSR-223 support classes there.

        Show
        Sarah Gerweck added a comment - If you do this right, this new dependency should only occur at build time, and wouldn't exist if you do your builds in Java 6. You also shouldn't need JUnit just to do a build: you're just need something to declare the ScriptEngine API so the compiler can do its type checking. I haven't reviewed the patch, but you should be able to drop it in without any run-time requirements change. As long as you don't use the class, you won't need the JSR-223 support classes there.
        Hide
        Jim White added a comment -

        The original patch does break the JDK 1.4 build (my setup wasn't actually testing under JDK 1.4 before). That should be fixed now (changeset 14027).

        The remaining issue is managing the JSR-223 API implementation (LiveTribe). It is only needed for JDK 1.5, but I don't think it is causing any problem being present in JDK 1.4 and JDK 1.6. But do folks think there is something special we should do for those environments?

        Show
        Jim White added a comment - The original patch does break the JDK 1.4 build (my setup wasn't actually testing under JDK 1.4 before). That should be fixed now (changeset 14027). The remaining issue is managing the JSR-223 API implementation (LiveTribe). It is only needed for JDK 1.5, but I don't think it is causing any problem being present in JDK 1.4 and JDK 1.6. But do folks think there is something special we should do for those environments?
        Hide
        Jim White added a comment -

        In order to avoid confusing folks about whether they should use the livetribe-jsr223.jar or not (it is only needed by JDK 1.5 users), I've changed the dependency to use 'provided' scope. That will bring it in for compilation and testing but won't appear in runtime (even though it isn't needed for JDK 1.6 compile & test, it won't hurt anything and may actually be better). JDK 1.5 users will have to track this JAR down themselves (just as they do currently), but at least having it appear in the POM should help them out.

        Show
        Jim White added a comment - In order to avoid confusing folks about whether they should use the livetribe-jsr223.jar or not (it is only needed by JDK 1.5 users), I've changed the dependency to use 'provided' scope. That will bring it in for compilation and testing but won't appear in runtime (even though it isn't needed for JDK 1.6 compile & test, it won't hurt anything and may actually be better). JDK 1.5 users will have to track this JAR down themselves (just as they do currently), but at least having it appear in the POM should help them out.
        Hide
        Jim White added a comment -

        Merged to GROOVY_1_6_X (cs 14075).

        Show
        Jim White added a comment - Merged to GROOVY_1_6_X (cs 14075).
        Hide
        Jim White added a comment -

        Not tested very much, but seems OK so far.

        Show
        Jim White added a comment - Not tested very much, but seems OK so far.

          People

          • Assignee:
            Jim White
            Reporter:
            Sarah Gerweck
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: