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

CompilerConfiguration: improve target bytecode selection

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 5.0.0-alpha-1
    • None
    • None

    Description

      The current implementation of CompilerConfiguration#setTargetBytecode(String) is to use the default version (currently "1.8") if the specified version is not supported. This can be a problem in joint compilation situations. If javac supports JDK19 or whatever comes along and groovyc only supports up to JDK17, then a target setting will be JDK19 for Java and JDK8 for Groovy.

      In groovy-eclipse, I have been selecting the nearest version. So if the user asks for "19" and "17" is supported, they'll get that. And if the user asks for "1.3" (hypothetical) then they'll get "1.4".  And if the user still uses "9.0" or "11.0" notation, they'll get what they expect.

          public void setTargetBytecode(final String version) {
              setTargetBytecodeIfValid(version);
          }
      
          private void setTargetBytecodeIfValid(final String version) {
              /* GRECLIPSE edit
              if (JDK_TO_BYTECODE_VERSION_MAP.containsKey(version)) {
                  this.targetBytecode = version;
              }
              */
              int index;
              try { ALLOWED_JDKS[5] = "1.9"; // 9 is out of order for binary search
                  index = Arrays.binarySearch(ALLOWED_JDKS, !version.startsWith("1") ? "1." + version : version);
              } finally {
                  ALLOWED_JDKS[5] = "9";
              }
              if (index >= 0) {
                  targetBytecode = ALLOWED_JDKS[index];
              } else {
                  index = Math.abs(index) - 2; // closest version
                  targetBytecode = ALLOWED_JDKS[Math.max(0, index)];
              }
              // GRECLIPSE end
          }
      

      Note: the current algorithm breaks down when "20" or greater is supplied.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              emilles Eric Milles
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1.5h
                  1.5h