Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-6203

GroovyScriptEngine does not take script base class into account

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.5
    • Fix Version/s: 2.4.7
    • Component/s: GroovyScriptEngine
    • Labels:
      None

      Description

      When configuring GroovyScriptEngine with a custom script base class, the script engine does not take it account:

      CompilerConfiguration cc = new CompilerConfiguration();
      
      cc.setScriptBaseClass(ScriptBase.class.getName());
      
      GroovyScriptEngine engine = new GroovyScriptEngine("file://.");
      
      engine.setConfig(cc);
      
      Script script = engine.createScript("test.groovy", new Binding());
      
      assertTrue(script instanceof ScriptBase); // fails
      
      

      This has been discussed here: http://groovy.329449.n5.nabble.com/setScriptBaseClass-does-not-work-for-GroovyScriptEngine-td5710646.html
      The workaround with setting the CompilerConfiguration on the GroovyClassLoader works.
      Also related: GROOVY-3281

        Issue Links

          Activity

          Hide
          nicoulaj Julien Nicoulaud added a comment -

          Corrected sample code (can't edit, sorry):

          CompilerConfiguration cc = new CompilerConfiguration();
          
          cc.setScriptBaseClass(ScriptBase.class.getName());
          
          GroovyScriptEngine engine = new GroovyScriptEngine("file://.");
          
          engine.setConfig(cc);
          
          Script script = engine.createScript("test.groovy", new Binding());
          
          assertTrue(script instanceof ScriptBase); // fails
          
          Show
          nicoulaj Julien Nicoulaud added a comment - Corrected sample code (can't edit, sorry): CompilerConfiguration cc = new CompilerConfiguration(); cc.setScriptBaseClass(ScriptBase.class.getName()); GroovyScriptEngine engine = new GroovyScriptEngine( "file: //." ); engine.setConfig(cc); Script script = engine.createScript( "test.groovy" , new Binding()); assertTrue(script instanceof ScriptBase); // fails
          Hide
          pschumacher Pascal Schumacher added a comment -

          Updated the sample code for Julien.

          Show
          pschumacher Pascal Schumacher added a comment - Updated the sample code for Julien.
          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user roded opened a pull request:

          https://github.com/apache/groovy/pull/335

          GROOVY-6203: GroovyScriptEngine does not take script base class into …

          …account

          https://issues.apache.org/jira/browse/GROOVY-6203

          The alternative as I see it was to remove the config's setter and add it to the constructors.
          Comments welcome.

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/roded/groovy master

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/groovy/pull/335.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #335


          commit a4b91d623024717d4a4ffb1f9f726b7386e0dea3
          Author: Roded Bahat <rodedb@gmail.com>
          Date: 2016-05-19T10:30:27Z

          GROOVY-6203: GroovyScriptEngine does not take script base class into account


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user roded opened a pull request: https://github.com/apache/groovy/pull/335 GROOVY-6203 : GroovyScriptEngine does not take script base class into … …account https://issues.apache.org/jira/browse/GROOVY-6203 The alternative as I see it was to remove the config's setter and add it to the constructors. Comments welcome. You can merge this pull request into a Git repository by running: $ git pull https://github.com/roded/groovy master Alternatively you can review and apply these changes as the patch at: https://github.com/apache/groovy/pull/335.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #335 commit a4b91d623024717d4a4ffb1f9f726b7386e0dea3 Author: Roded Bahat <rodedb@gmail.com> Date: 2016-05-19T10:30:27Z GROOVY-6203 : GroovyScriptEngine does not take script base class into account
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/groovy/pull/335

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/groovy/pull/335
          Hide
          pascalschumacher Pascal Schumacher added a comment -

          Pull request merged. Thanks!

          Show
          pascalschumacher Pascal Schumacher added a comment - Pull request merged. Thanks!

            People

            • Assignee:
              pascalschumacher Pascal Schumacher
              Reporter:
              nicoulaj Julien Nicoulaud
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development