Support JDK >= 12 in CtSymClassBinder and enable JDK [12,15] on travis. PiperOrigin-RevId: 335220773
diff --git a/.travis.yml b/.travis.yml index 8113f5f..8d948f1 100644 --- a/.travis.yml +++ b/.travis.yml
@@ -5,6 +5,10 @@ - openjdk9 - openjdk10 - openjdk11 + - openjdk12 + - openjdk13 + - openjdk14 + - openjdk15 - openjdk-ea matrix:
diff --git a/java/com/google/turbine/binder/CtSymClassBinder.java b/java/com/google/turbine/binder/CtSymClassBinder.java index a8968e2..17ea34e 100644 --- a/java/com/google/turbine/binder/CtSymClassBinder.java +++ b/java/com/google/turbine/binder/CtSymClassBinder.java
@@ -33,6 +33,7 @@ import com.google.turbine.binder.sym.ModuleSymbol; import com.google.turbine.zip.Zip; import java.io.IOException; +import java.lang.reflect.Method; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -81,6 +82,10 @@ modules.put(new ModuleSymbol(moduleInfo.name()), moduleInfo); continue; } + // remove module path prefix introduced in https://bugs.openjdk.java.net/browse/JDK-8209865 + if (MAJOR >= 12) { + idx = name.indexOf('/', idx + 1); + } ClassSymbol sym = new ClassSymbol(name.substring(idx + 1, name.length() - ".sig".length())); map.putIfAbsent( sym, new BytecodeBoundClass(sym, toByteArrayOrDie(ze), benv, ctSym + "!" + ze.name())); @@ -124,4 +129,23 @@ } }); } + + private static final int MAJOR = getMajor(); + + private static int getMajor() { + try { + Method versionMethod = Runtime.class.getMethod("version"); + Object version = versionMethod.invoke(null); + return (int) version.getClass().getMethod("major").invoke(version); + } catch (Exception e) { + // continue below + } + + int version = (int) Double.parseDouble(System.getProperty("java.class.version")); + if (49 <= version && version <= 52) { + return version - (49 - 5); + } + throw new IllegalStateException( + "Unknown Java version: " + System.getProperty("java.specification.version")); + } }
diff --git a/javatests/com/google/turbine/processing/AbstractTurbineTypesTest.java b/javatests/com/google/turbine/processing/AbstractTurbineTypesTest.java index 8233697..471ce42 100644 --- a/javatests/com/google/turbine/processing/AbstractTurbineTypesTest.java +++ b/javatests/com/google/turbine/processing/AbstractTurbineTypesTest.java
@@ -22,6 +22,7 @@ import static com.google.common.truth.Truth.assertWithMessage; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.Collectors.joining; +import static javax.lang.model.SourceVersion.RELEASE_8; import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; @@ -54,6 +55,7 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.atomic.AtomicInteger; +import javax.lang.model.SourceVersion; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; import javax.lang.model.element.ExecutableElement; @@ -365,7 +367,9 @@ /* out= */ null, fileManager, /* diagnosticListener= */ null, - /* options= */ ImmutableList.of(), + /* options= */ SourceVersion.latestSupported().compareTo(RELEASE_8) > 0 + ? ImmutableList.of("--release", "8") + : ImmutableList.of(), /* classes= */ ImmutableList.of(), compilationUnits);