Groovy
  1. Groovy
  2. GROOVY-4521

Inconsistency between CompilerConfiguration, groovy -c and groovysh ?

    Details

      Description

      Given the following script, saved as enc_test.groovy

      import org.codehaus.groovy.control.CompilerConfiguration
      println "File source encoding is probably set to " + CompilerConfiguration.DEFAULT.getSourceEncoding()
      

      I would assume all three executions below to print "UTF-8", but they don't:

      $ groovy -c UTF-8 enc_test.groovy
      File source encoding is probably set to MacRoman
      
      $ groovy -Dgroovy.source.encoding=UTF-8 enc_test.groovy
      File source encoding is probably set to MacRoman
      
      $ groovysh -Dgroovy.source.encoding=UTF-8
      groovy:000> org.codehaus.groovy.control.CompilerConfiguration.DEFAULT.getSourceEncoding()
      ===> UTF-8
      

      The reason I was printing this info was to track down an encoding issue I had; turns out the -c flag actually works for me (i.e my sources are properly decoded) (while the -Dgroovy.source.encoding option doesn't), but I was looking for a way to ensure my scripts are executed with -c UTF-8, but the above snippet obviously doesn't help.

        Activity

        Grégory Joseph created issue -
        Roshan Dawrani made changes -
        Field Original Value New Value
        Assignee Roshan Dawrani [ roshandawrani ]
        Hide
        Roshan Dawrani added a comment -

        The consistency between groovy and groovysh is fixed now.

        Source encoding on CompilerConfiguration.DEFAULT is manipulatable using the system property groovy.source.encoding and it now works with both groovy/groovysh as shown below.

        $groovy -Dgroovy.source.encoding=UTF-8 enc_test.groovy
        File source encoding is probably set to UTF-8
        
        $groovysh -Dgroovy.source.encoding=UTF-8
        groovy:000> org.codehaus.groovy.control.CompilerConfiguration.DEFAULT.getSourceEncoding()
        ===> UTF-8
        

        "groovy -c " allows you to override the CompilerConfiguration that is made-up from system properties. So, it also works correctly (as you already noticed), but it won't modify the source encoding on CompilerConfiguration.DEFAULT configuration.

        Show
        Roshan Dawrani added a comment - The consistency between groovy and groovysh is fixed now. Source encoding on CompilerConfiguration.DEFAULT is manipulatable using the system property groovy.source.encoding and it now works with both groovy/groovysh as shown below. $groovy -Dgroovy.source.encoding=UTF-8 enc_test.groovy File source encoding is probably set to UTF-8 $groovysh -Dgroovy.source.encoding=UTF-8 groovy:000> org.codehaus.groovy.control.CompilerConfiguration.DEFAULT.getSourceEncoding() ===> UTF-8 "groovy -c " allows you to override the CompilerConfiguration that is made-up from system properties. So, it also works correctly (as you already noticed), but it won't modify the source encoding on CompilerConfiguration.DEFAULT configuration.
        Roshan Dawrani made changes -
        Fix Version/s 1.7.6 [ 16749 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.8-beta-3 [ 16750 ]
        Hide
        Grégory Joseph added a comment -

        Sounds good, thanks!

        Now is there a safe way to get the current source encoding at runtime? Can I access the CompilerConfiguration instance that was used to compile/execute my script ?

        Show
        Grégory Joseph added a comment - Sounds good, thanks! Now is there a safe way to get the current source encoding at runtime? Can I access the CompilerConfiguration instance that was used to compile/execute my script ?
        Hide
        Roshan Dawrani added a comment -

        No, as far as I know, that particular CompilerConfiguration instance is not exposed.

        Show
        Roshan Dawrani added a comment - No, as far as I know, that particular CompilerConfiguration instance is not exposed.
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12733457 ] Default workflow, editable Closed status [ 12745208 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12970976 ] Default workflow, editable Closed status [ 12978759 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open Resolved Resolved
        2d 16h 41m 1 Roshan Dawrani 24/Nov/10 23:30
        Resolved Resolved Closed Closed
        20d 17h 25m 1 Paul King 15/Dec/10 16:56

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Grégory Joseph
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development