diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2018-02-05 14:50:45 +0100 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2018-02-05 16:46:39 +0000 |
commit | 1b48f0161754bb3ffa453d3c55a9d9497fd20111 (patch) | |
tree | 87c6d845283e5b4aed1a8afbe564a39c5903138d /share | |
parent | 4cc46c923b3ed7e69d1edfba32b11a9b9008bcd1 (diff) |
Java: Adapt to Java 9 changes
- tools.jar and rt.jar are gone
- The -bootclasspath option is not allowed when targeting Java 9
- JavaCompiler.isSupportedOption() (erroneously?) returns 1 instead of 0
for -Xlint
- version number related changes:
- major version has jumped to 9
- javac prints the version number to stdout rather than stderr
- version number no longer contains a forth component
- The -source and -target options take only the major version
Change-Id: I0b23c8868db7aeaa06785ee43c1efd9fcb1bc9d2
Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'share')
-rw-r--r-- | share/qbs/modules/java/JavaModule.qbs | 15 | ||||
-rw-r--r-- | share/qbs/modules/java/io/qt/qbs/tools/utils/JavaCompilerOptions.java | 6 | ||||
-rw-r--r-- | share/qbs/modules/java/utils.js | 17 |
3 files changed, 28 insertions, 10 deletions
diff --git a/share/qbs/modules/java/JavaModule.qbs b/share/qbs/modules/java/JavaModule.qbs index dcf6c8ba2..928684a4f 100644 --- a/share/qbs/modules/java/JavaModule.qbs +++ b/share/qbs/modules/java/JavaModule.qbs @@ -34,6 +34,7 @@ import qbs.ModUtils import qbs.Probes import qbs.Process import qbs.TextFile +import qbs.Utilities import "utils.js" as JavaUtils @@ -66,7 +67,7 @@ Module { property string jdkPath: jdk.path - version: compilerVersion + version: [compilerVersionMajor, compilerVersionMinor, compilerVersionPatch].join(".") property string compilerVersion: jdkVersionProbe.version ? jdkVersionProbe.version[1] : undefined property var compilerVersionParts: compilerVersion ? compilerVersion.split(/[\._]/).map(function(item) { return parseInt(item, 10); }) : [] @@ -151,12 +152,16 @@ Module { } property path runtimeJarPath: { + if (compilerVersionMajor >= 9) + return undefined; if (classesJarPath) return classesJarPath; return FileInfo.joinPaths(jdkPath, "jre", "lib", "rt.jar"); } property path toolsJarPath: { + if (compilerVersionMajor >= 9) + return undefined; if (classesJarPath) return classesJarPath; return FileInfo.joinPaths(jdkPath, "lib", "tools.jar"); @@ -169,13 +174,15 @@ Module { validator.setRequiredProperty("compilerVersionParts", compilerVersionParts); validator.setRequiredProperty("compilerVersionMajor", compilerVersionMajor); validator.setRequiredProperty("compilerVersionMinor", compilerVersionMinor); - validator.setRequiredProperty("compilerVersionUpdate", compilerVersionUpdate); + if (Utilities.versionCompare(version, "9") < 0) + validator.setRequiredProperty("compilerVersionUpdate", compilerVersionUpdate); validator.addVersionValidator("compilerVersion", compilerVersion - ? compilerVersion.replace("_", ".") : undefined, 4, 4); + ? compilerVersion.replace("_", ".") : undefined, 3, 4); validator.addRangeValidator("compilerVersionMajor", compilerVersionMajor, 1); validator.addRangeValidator("compilerVersionMinor", compilerVersionMinor, 0); validator.addRangeValidator("compilerVersionPatch", compilerVersionPatch, 0); - validator.addRangeValidator("compilerVersionUpdate", compilerVersionUpdate, 0); + if (Utilities.versionCompare(version, "9") < 0) + validator.addRangeValidator("compilerVersionUpdate", compilerVersionUpdate, 0); validator.validate(); } diff --git a/share/qbs/modules/java/io/qt/qbs/tools/utils/JavaCompilerOptions.java b/share/qbs/modules/java/io/qt/qbs/tools/utils/JavaCompilerOptions.java index a6195f05f..7bb5b41b0 100644 --- a/share/qbs/modules/java/io/qt/qbs/tools/utils/JavaCompilerOptions.java +++ b/share/qbs/modules/java/io/qt/qbs/tools/utils/JavaCompilerOptions.java @@ -61,11 +61,15 @@ public class JavaCompilerOptions { argumentCount = fileManager.isSupportedOption(arguments[i]); if (argumentCount >= 0) { + + // isSupportedOption() returns 1 for -Xlint* in Java 9. Bug? + if (arguments[i].startsWith("-Xlint")) + argumentCount = 0; + for (int j = 0; j < argumentCount + 1; ++j) { if (i + j >= arguments.length) { throw new IllegalArgumentException(arguments[i]); } - recognizedOptions.add(arguments[i + j]); } diff --git a/share/qbs/modules/java/utils.js b/share/qbs/modules/java/utils.js index be117d98e..52c0e880a 100644 --- a/share/qbs/modules/java/utils.js +++ b/share/qbs/modules/java/utils.js @@ -136,8 +136,10 @@ function findJdkVersion(compilerFilePath) { var p = new Process(); try { p.exec(compilerFilePath, ["-version"]); - var re = /^javac (([0-9]+(?:\.[0-9]+){2,2})_([0-9]+))$/m; + var re = /^javac (([0-9]+(?:\.[0-9]+){2,2})(_([0-9]+))?)$/m; var match = p.readStdErr().trim().match(re); + if (!match) + match = p.readStdOut().trim().match(re); if (match !== null) return match; } finally { @@ -194,8 +196,10 @@ function javacArguments(product, inputs, overrides) { if (languageVersion) args.push("-source", languageVersion); var bootClassPaths = getModuleProperties(product, "bootClassPaths", overrides); - if (bootClassPaths && bootClassPaths.length > 0) + if (bootClassPaths && bootClassPaths.length > 0 + && (!runtimeVersion || Utilities.versionCompare(runtimeVersion, "9") < 0)) { args.push("-bootclasspath", bootClassPaths.join(pathListSeparator)); + } if (!getModuleProperty(product, "enableWarnings", overrides)) args.push("-nowarn"); if (getModuleProperty(product, "warningsAsErrors", overrides)) @@ -255,8 +259,10 @@ function helperOverrideArgs(product, tool) { // compiled with. Both are irrelevant here since the resulting tool will only be run // with the same JDK as it was built with, and we know in advance the source is // compatible with all Java language versions from 1.6 and above. - var jdkVersion = [ModUtils.moduleProperty(product, "compilerVersionMajor"), - ModUtils.moduleProperty(product, "compilerVersionMinor")].join("."); + var jdkVersionArray = [product.java.compilerVersionMajor]; + if (product.java.compilerVersionMajor < 9) + jdkVersionArray.push(product.java.compilerVersionMinor); + var jdkVersion = jdkVersionArray.join("."); overrides["languageVersion"] = jdkVersion; overrides["runtimeVersion"] = jdkVersion; @@ -273,7 +279,8 @@ function helperOverrideArgs(product, tool) { // Inject the current JDK's runtime classes into the boot class path when building/running the // dependency scanner. This is normally not necessary but is important for Android platforms // where android.jar is the only JAR on the boot classpath and JSR 199 is unavailable. - overrides["bootClassPaths"] = [ModUtils.moduleProperty(product, "runtimeJarPath")].concat( + var rtJarPath = product.java.runtimeJarPath; + overrides["bootClassPaths"] = (rtJarPath ? [rtJarPath] : []).concat( ModUtils.moduleProperty(product, "bootClassPaths")); return overrides; } |