Fix compilation against JRE 9 on JPS
Write the modular JDK (9+) path to the module.xml file passed to the compiler from the JPS plugin. This path is then recorded in the compiler configuration in KotlinToJVMBytecodeCompiler.configureSourceRoots. This is needed because in JPS plugin, we pass "-no-jdk" and thus no JDK home path was recorded in the compiler configuration in K2JVMCompiler.setupJdkClasspathRoots. Presence of JDK home path in the configuration is crucial for JDK 9 support (see KotlinCoreEnvironment.Companion.createApplicationEnvironment), because classes there can only be loaded with the special "jrt" file system, not as .class files in .jar files #KT-17801 Fixed
This commit is contained in:
@@ -21,10 +21,12 @@ import com.intellij.openapi.util.Condition
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.io.FileUtil.toSystemIndependentName
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import com.intellij.openapi.vfs.StandardFileSystems
|
||||
import com.intellij.testFramework.LightVirtualFile
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import com.intellij.util.ArrayUtil
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import com.intellij.util.io.URLUtil
|
||||
import com.intellij.util.io.ZipUtil
|
||||
import org.jetbrains.jps.ModuleChunk
|
||||
import org.jetbrains.jps.api.CanceledStatus
|
||||
@@ -45,6 +47,8 @@ import org.jetbrains.jps.model.JpsModuleRootModificationUtil
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType
|
||||
import org.jetbrains.jps.model.java.JpsJavaDependencyScope
|
||||
import org.jetbrains.jps.model.java.JpsJavaExtensionService
|
||||
import org.jetbrains.jps.model.java.JpsJavaSdkType
|
||||
import org.jetbrains.jps.model.library.JpsOrderRootType
|
||||
import org.jetbrains.jps.model.module.JpsModule
|
||||
import org.jetbrains.jps.util.JpsPathUtil
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
@@ -899,6 +903,18 @@ class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
||||
KotlinTestUtils.assertEqualsToFile(expectedFile, actual.toString())
|
||||
}
|
||||
|
||||
fun testJre9() {
|
||||
val path = KotlinTestUtils.getJre9HomeIfPossible()?.absolutePath ?: return
|
||||
|
||||
val jdk = myModel.global.addSdk(JDK_NAME, path, "9", JpsJavaSdkType.INSTANCE)
|
||||
jdk.addRoot(StandardFileSystems.JRT_PROTOCOL_PREFIX + path + URLUtil.JAR_SEPARATOR + "java.base", JpsOrderRootType.COMPILED)
|
||||
|
||||
loadProject(workDir.absolutePath + File.separator + PROJECT_NAME + ".ipr")
|
||||
addKotlinRuntimeDependency()
|
||||
|
||||
buildAllModules().assertSuccessful()
|
||||
}
|
||||
|
||||
private fun BuildResult.checkErrors() {
|
||||
val actualErrors = getMessages(BuildMessage.Kind.ERROR)
|
||||
.map { it as CompilerMessage }
|
||||
|
||||
@@ -46,6 +46,7 @@ class ClasspathOrderTest : TestCaseWithTmpdir() {
|
||||
listOf(sourceDir),
|
||||
listOf(JvmSourceRoot(sourceDir)),
|
||||
listOf(PathUtil.getKotlinPathsForDistDirectory().runtimePath),
|
||||
null,
|
||||
JavaModuleBuildTargetType.PRODUCTION.typeId,
|
||||
JavaModuleBuildTargetType.PRODUCTION.isTests,
|
||||
setOf(),
|
||||
|
||||
+28
-8
@@ -33,10 +33,11 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
Arrays.asList(new File("s1"), new File("s2")),
|
||||
Collections.singletonList(new JvmSourceRoot(new File("java"), null)),
|
||||
Arrays.asList(new File("cp1"), new File("cp2")),
|
||||
null,
|
||||
JavaModuleBuildTargetType.PRODUCTION.getTypeId(),
|
||||
JavaModuleBuildTargetType.PRODUCTION.isTests(),
|
||||
Collections.<File>emptySet(),
|
||||
Collections.<File>emptyList()
|
||||
Collections.emptySet(),
|
||||
Collections.emptyList()
|
||||
).asText().toString();
|
||||
KotlinTestUtils.assertEqualsToFile(new File("idea/testData/modules.xml/basic.xml"), actual);
|
||||
}
|
||||
@@ -46,12 +47,13 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
"name",
|
||||
"output",
|
||||
Arrays.asList(new File("s1"), new File("s2")),
|
||||
Collections.<JvmSourceRoot>emptyList(),
|
||||
Collections.emptyList(),
|
||||
Arrays.asList(new File("cp1"), new File("cp2")),
|
||||
null,
|
||||
JavaModuleBuildTargetType.PRODUCTION.getTypeId(),
|
||||
JavaModuleBuildTargetType.PRODUCTION.isTests(),
|
||||
Collections.singleton(new File("cp1")),
|
||||
Collections.<File>emptyList()
|
||||
Collections.emptyList()
|
||||
).asText().toString();
|
||||
KotlinTestUtils.assertEqualsToFile(new File("idea/testData/modules.xml/filtered.xml"), actual);
|
||||
}
|
||||
@@ -62,25 +64,43 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
"name",
|
||||
"output",
|
||||
Arrays.asList(new File("s1"), new File("s2")),
|
||||
Collections.<JvmSourceRoot>emptyList(),
|
||||
Collections.emptyList(),
|
||||
Arrays.asList(new File("cp1"), new File("cp2")),
|
||||
null,
|
||||
JavaModuleBuildTargetType.PRODUCTION.getTypeId(),
|
||||
JavaModuleBuildTargetType.PRODUCTION.isTests(),
|
||||
Collections.singleton(new File("cp1")),
|
||||
Collections.<File>emptyList()
|
||||
Collections.emptyList()
|
||||
);
|
||||
builder.addModule(
|
||||
"name2",
|
||||
"output2",
|
||||
Arrays.asList(new File("s12"), new File("s22")),
|
||||
Collections.<JvmSourceRoot>emptyList(),
|
||||
Collections.emptyList(),
|
||||
Arrays.asList(new File("cp12"), new File("cp22")),
|
||||
null,
|
||||
JavaModuleBuildTargetType.TEST.getTypeId(),
|
||||
JavaModuleBuildTargetType.TEST.isTests(),
|
||||
Collections.singleton(new File("cp12")),
|
||||
Collections.<File>emptyList()
|
||||
Collections.emptyList()
|
||||
);
|
||||
String actual = builder.asText().toString();
|
||||
KotlinTestUtils.assertEqualsToFile(new File("idea/testData/modules.xml/multiple.xml"), actual);
|
||||
}
|
||||
|
||||
public void testModularJdkRoot() throws Exception {
|
||||
String actual = new KotlinModuleXmlBuilder().addModule(
|
||||
"name",
|
||||
"output",
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList(),
|
||||
new File("/path/to/modular/jdk"),
|
||||
JavaModuleBuildTargetType.PRODUCTION.getTypeId(),
|
||||
JavaModuleBuildTargetType.PRODUCTION.isTests(),
|
||||
Collections.emptySet(),
|
||||
Collections.emptyList()
|
||||
).asText().toString();
|
||||
KotlinTestUtils.assertEqualsToFile(new File("idea/testData/modules.xml/modularJdkRoot.xml"), actual);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user