Uploaded image for project: 'OFBiz'
  1. OFBiz
  2. OFBIZ-8119

Character encoding issue found in file build.gradle

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: Trunk
    • Fix Version/s: 16.11.01
    • Component/s: ALL APPLICATIONS
    • Labels:
      None
    • Environment:

      Window10
      java version "1.8.0_101"

      Description

      I cann't build ofbiz when I run gradlew.
      I found utf-8 should be the default character encoding used by the comipiling work.

      eg.
      def defaultEncoding = 'UTF-8'
      tasks.withType(AbstractCompile).options.encoding = defaultEncoding
      tasks.withType(GroovyCompile).groovyOptions.encoding = defaultEncoding

      1. OFBIZ-8119_CharacterEncodingInBuildFile.patch
        0.5 kB
        fumiyoshi.to
      2. build-error.png
        27 kB
        fumiyoshi.to

        Issue Links

          Activity

          Hide
          taher Taher Alkhateeb added a comment -

          Thank you also for taking the time to research this, the code snippet you provided helped me in forging the committed solution, and it was also useful for me to learn some new notation.

          Show
          taher Taher Alkhateeb added a comment - Thank you also for taking the time to research this, the code snippet you provided helped me in forging the committed solution, and it was also useful for me to learn some new notation.
          Hide
          tofumiyoshi@gmail.com fumiyoshi.to added a comment -

          I confirmed that it works. thanks you very much.

          Show
          tofumiyoshi@gmail.com fumiyoshi.to added a comment - I confirmed that it works. thanks you very much.
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          Fixed at r1759092

          Show
          jacques.le.roux Jacques Le Roux added a comment - Fixed at r1759092
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          Yes was doing so

          I used // This is used for Windows to work correctly

          I pick yours

          Show
          jacques.le.roux Jacques Le Roux added a comment - Yes was doing so I used // This is used for Windows to work correctly I pick yours
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          Sorry fumiyoshi.to if ever you tried to understand why I previously referenced OFBIZ-7137 (now edited to OFBIZ-7938). I confused the issues in my notes. Anyway Taher's 2nd solution below works so we can use it and close here with OFBIZ-7938.

          Show
          jacques.le.roux Jacques Le Roux added a comment - Sorry fumiyoshi.to if ever you tried to understand why I previously referenced OFBIZ-7137 (now edited to OFBIZ-7938 ). I confused the issues in my notes. Anyway Taher's 2nd solution below works so we can use it and close here with OFBIZ-7938 .
          Hide
          taher Taher Alkhateeb added a comment -

          Okay so this confirmed my suspicion that the OS is the culprit. Windows does not like Unicode for some reason, one of the many things this os does not like to comply with.

          I suggest to add a comment to the code snippet something like:

          /* enforce UTF-8 java compilation
           * encoding on Windows platforms
           */
          
          Show
          taher Taher Alkhateeb added a comment - Okay so this confirmed my suspicion that the OS is the culprit. Windows does not like Unicode for some reason, one of the many things this os does not like to comply with. I suggest to add a comment to the code snippet something like: /* enforce UTF-8 java compilation * encoding on Windows platforms */
          Hide
          jacques.le.roux Jacques Le Roux added a comment - - edited

          Yippee, I can close OFBIZ-7938 and will commit Taher's 2nd proposed change

          Show
          jacques.le.roux Jacques Le Roux added a comment - - edited Yippee, I can close OFBIZ-7938 and will commit Taher's 2nd proposed change
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          The 1st does not work, the second does build, trying tests now..

          Show
          jacques.le.roux Jacques Le Roux added a comment - The 1st does not work, the second does build, trying tests now..
          Hide
          taher Taher Alkhateeb added a comment -

          Okay after a little of investigation I realized what you were trying to do with your patch:

          def defaultEncoding = 'UTF-8'
          tasks.withType(AbstractCompile)*.options*.encoding = defaultEncoding
          tasks.withType(GroovyCompile)*.groovyOptions*.encoding = defaultEncoding
          

          AbstractCompile is the parent of JavaCompile, GroovyCompile and other compile tasks, and so this code snippet iterates through this compilation syntax to try to enforce the character encoding on all compile tasks.
          GroovyCompile has an additional field for GroovyCompileOptions which extends from AbstractCompileOptions. But CompileOptions (java) also extends from AbstractCompileOptions. So the two separate classes need to set the encoding.

          Now, I think the following errors are present in the code:

          • The default encoding is already UTF-8, not sure that we need to enforce it unless something is wrong in your default encoding options on the OS?
          • GroovyCompileOptions setting for encoding is not needed because we aren't running any gradle plugins or compile tasks.

          There are two code snippets which you can try, and please tell me if either one works for you. I am listing the two so that if the first one does not work, then we know the problem is OS related in config settings:

          // try this first, if it works, then ignore the second one
          tasks.withType(JavaCompile) {
              options.encoding = System.getProperty('file.encoding')
          }
          
          // if the above does not work, try this
          tasks.withType(JavaCompile) {
              options.encoding = 'UTF-8'
          }
          
          Show
          taher Taher Alkhateeb added a comment - Okay after a little of investigation I realized what you were trying to do with your patch: def defaultEncoding = 'UTF-8' tasks.withType(AbstractCompile)*.options*.encoding = defaultEncoding tasks.withType(GroovyCompile)*.groovyOptions*.encoding = defaultEncoding AbstractCompile is the parent of JavaCompile, GroovyCompile and other compile tasks, and so this code snippet iterates through this compilation syntax to try to enforce the character encoding on all compile tasks. GroovyCompile has an additional field for GroovyCompileOptions which extends from AbstractCompileOptions. But CompileOptions (java) also extends from AbstractCompileOptions. So the two separate classes need to set the encoding. Now, I think the following errors are present in the code: The default encoding is already UTF-8, not sure that we need to enforce it unless something is wrong in your default encoding options on the OS? GroovyCompileOptions setting for encoding is not needed because we aren't running any gradle plugins or compile tasks. There are two code snippets which you can try, and please tell me if either one works for you. I am listing the two so that if the first one does not work, then we know the problem is OS related in config settings: // try this first, if it works, then ignore the second one tasks.withType(JavaCompile) { options.encoding = System .getProperty('file.encoding') } // if the above does not work, try this tasks.withType(JavaCompile) { options.encoding = 'UTF-8' }
          Hide
          jacques.le.roux Jacques Le Roux added a comment - - edited

          I don't mind setting the Environment Variable JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF-8. But I actually did that only for Gradle to work.

          I just stumbled upon https://discuss.gradle.org/t/test-failed-while-building-gradle-from-sources-because-of-java-tool-options-defined/4441 and I believe if we had UTF-8 set in Gradle it would fix OFBIZ-7137 (which seems to exist only for me, but would maybe exist for fumiyoshi.to too if he sets JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF-8)

          fumiyoshi.to, while Taher is working on this, could you please check you can reproduce OFBIZ-7938 by setting JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF-8? Thanks!

          Show
          jacques.le.roux Jacques Le Roux added a comment - - edited I don't mind setting the Environment Variable JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF-8. But I actually did that only for Gradle to work. I just stumbled upon https://discuss.gradle.org/t/test-failed-while-building-gradle-from-sources-because-of-java-tool-options-defined/4441 and I believe if we had UTF-8 set in Gradle it would fix OFBIZ-7137 (which seems to exist only for me, but would maybe exist for fumiyoshi.to too if he sets JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF-8) fumiyoshi.to , while Taher is working on this, could you please check you can reproduce OFBIZ-7938 by setting JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF-8? Thanks!
          Hide
          taher Taher Alkhateeb added a comment -

          Hold on, I actually like his solution, it's just not well done. I'll investigate some more

          Show
          taher Taher Alkhateeb added a comment - Hold on, I actually like his solution, it's just not well done. I'll investigate some more
          Hide
          taher Taher Alkhateeb added a comment -

          Yeah my total ignorance is showing

          Show
          taher Taher Alkhateeb added a comment - Yeah my total ignorance is showing
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          Hi fumiyoshi.to,

          I see you are using Windows, please try to set the Environment Variable JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF-8. This worked for me.

          Show
          jacques.le.roux Jacques Le Roux added a comment - Hi fumiyoshi.to, I see you are using Windows, please try to set the Environment Variable JAVA_TOOL_OPTIONS to -Dfile.encoding=UTF-8. This worked for me.
          Hide
          jacques.le.roux Jacques Le Roux added a comment -

          Taher, it's not Chinese but Japanese

          Show
          jacques.le.roux Jacques Le Roux added a comment - Taher, it's not Chinese but Japanese
          Hide
          taher Taher Alkhateeb added a comment -

          Also why are you adding groovy compile options? The groovy plugin is not used. How did you come up with this fix?

          Show
          taher Taher Alkhateeb added a comment - Also why are you adding groovy compile options? The groovy plugin is not used. How did you come up with this fix?
          Hide
          taher Taher Alkhateeb added a comment -

          hello, gradle encoding is already UTF-8 by default. I think some of your files are not in compliance. I can't tell for sure because the screenshot is in chinese.

          Show
          taher Taher Alkhateeb added a comment - hello, gradle encoding is already UTF-8 by default. I think some of your files are not in compliance. I can't tell for sure because the screenshot is in chinese.

            People

            • Assignee:
              taher Taher Alkhateeb
              Reporter:
              tofumiyoshi@gmail.com fumiyoshi.to
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development