Do not add JDK .jar roots if the JDK is modular (9+)
Files like ant-javafx.jar, deploy.jar, java.jnlp.jar, javafx-swt.jar etc should not be added to the classpath if JDK home points to a JDK 9 distribution
This commit is contained in:
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.cli.jvm.config.JvmModulePathRoot
|
|||||||
import org.jetbrains.kotlin.cli.jvm.config.addJavaSourceRoot
|
import org.jetbrains.kotlin.cli.jvm.config.addJavaSourceRoot
|
||||||
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
|
import org.jetbrains.kotlin.cli.jvm.config.addJvmClasspathRoots
|
||||||
import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots
|
import org.jetbrains.kotlin.cli.jvm.config.jvmClasspathRoots
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.modules.CoreJrtFileSystem
|
||||||
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
|
import org.jetbrains.kotlin.cli.jvm.plugins.PluginCliParser
|
||||||
import org.jetbrains.kotlin.cli.jvm.repl.ReplFromTerminal
|
import org.jetbrains.kotlin.cli.jvm.repl.ReplFromTerminal
|
||||||
import org.jetbrains.kotlin.codegen.CompilationException
|
import org.jetbrains.kotlin.codegen.CompilationException
|
||||||
@@ -404,22 +405,24 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
|||||||
return OK
|
return OK
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.jdkHome != null) {
|
val (jdkHome, classesRoots) = if (arguments.jdkHome != null) {
|
||||||
val jdkHome = File(arguments.jdkHome)
|
val jdkHome = File(arguments.jdkHome)
|
||||||
configuration.put(JVMConfigurationKeys.JDK_HOME, jdkHome)
|
|
||||||
val classesRoots = PathUtil.getJdkClassesRoots(jdkHome)
|
|
||||||
configuration.addJvmClasspathRoots(classesRoots)
|
|
||||||
|
|
||||||
messageCollector.report(LOGGING, "Using JDK home directory $jdkHome")
|
messageCollector.report(LOGGING, "Using JDK home directory $jdkHome")
|
||||||
|
jdkHome to PathUtil.getJdkClassesRoots(jdkHome)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
File(System.getProperty("java.home")) to PathUtil.getJdkClassesRootsFromCurrentJre()
|
||||||
|
}
|
||||||
|
|
||||||
|
configuration.put(JVMConfigurationKeys.JDK_HOME, jdkHome)
|
||||||
|
|
||||||
|
if (!CoreJrtFileSystem.isModularJdk(jdkHome)) {
|
||||||
|
configuration.addJvmClasspathRoots(classesRoots)
|
||||||
if (classesRoots.isEmpty()) {
|
if (classesRoots.isEmpty()) {
|
||||||
messageCollector.report(ERROR, "No class roots are found in the JDK path: $jdkHome")
|
messageCollector.report(ERROR, "No class roots are found in the JDK path: $jdkHome")
|
||||||
return COMPILATION_ERROR
|
return COMPILATION_ERROR
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
configuration.put(JVMConfigurationKeys.JDK_HOME, File(System.getProperty("java.home")))
|
|
||||||
configuration.addJvmClasspathRoots(PathUtil.getJdkClassesRootsFromCurrentJre())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (t: Throwable) {
|
catch (t: Throwable) {
|
||||||
MessageCollectorUtil.reportException(messageCollector, t)
|
MessageCollectorUtil.reportException(messageCollector, t)
|
||||||
|
|||||||
@@ -50,13 +50,17 @@ class CoreJrtFileSystem(private val fileSystem: FileSystem) : DeprecatedVirtualF
|
|||||||
FileSystems.newFileSystem(rootUri, mapOf("java.home" to jdkHome.absolutePath))
|
FileSystems.newFileSystem(rootUri, mapOf("java.home" to jdkHome.absolutePath))
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val jrtFsJar = File(jdkHome, "lib/jrt-fs.jar")
|
val jrtFsJar = loadJrtFsJar(jdkHome) ?: return null
|
||||||
if (!jrtFsJar.exists()) return null
|
|
||||||
|
|
||||||
val classLoader = URLClassLoader(arrayOf(jrtFsJar.toURI().toURL()), null)
|
val classLoader = URLClassLoader(arrayOf(jrtFsJar.toURI().toURL()), null)
|
||||||
FileSystems.newFileSystem(rootUri, emptyMap<String, Nothing>(), classLoader)
|
FileSystems.newFileSystem(rootUri, emptyMap<String, Nothing>(), classLoader)
|
||||||
}
|
}
|
||||||
return CoreJrtFileSystem(fileSystem)
|
return CoreJrtFileSystem(fileSystem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun loadJrtFsJar(jdkHome: File): File? =
|
||||||
|
File(jdkHome, "lib/jrt-fs.jar").takeIf(File::exists)
|
||||||
|
|
||||||
|
fun isModularJdk(jdkHome: File): Boolean =
|
||||||
|
loadJrtFsJar(jdkHome) != null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
compiler/testData/javaModules/jdkModulesFromNamed/main/test.kt:11:24: error: unresolved reference: httpserver
|
compiler/testData/javaModules/jdkModulesFromNamed/main/test.kt:11:24: error: unresolved reference: httpserver
|
||||||
val s: com.sun.net.httpserver.HttpServer? = null
|
val s: com.sun.net.httpserver.HttpServer? = null
|
||||||
^
|
^
|
||||||
|
compiler/testData/javaModules/jdkModulesFromNamed/main/test.kt:19:20: error: unresolved reference: javafx
|
||||||
|
val x: com.sun.javafx.tools.ant.AntLog? = null
|
||||||
|
^
|
||||||
COMPILATION_ERROR
|
COMPILATION_ERROR
|
||||||
|
|||||||
@@ -14,4 +14,8 @@ fun main(args: Array<String>) {
|
|||||||
// Module oracle.desktop
|
// Module oracle.desktop
|
||||||
val a: com.oracle.awt.AWTUtils? = null
|
val a: com.oracle.awt.AWTUtils? = null
|
||||||
println(a)
|
println(a)
|
||||||
|
|
||||||
|
// No module, this class is declared in $JDK_9/lib/ant-javafx.jar
|
||||||
|
val x: com.sun.javafx.tools.ant.AntLog? = null
|
||||||
|
println(x)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
OK
|
compiler/testData/javaModules/jdkModulesFromUnnamed/main/test.kt:19:33: error: unresolved reference: ant
|
||||||
|
val x: com.sun.javafx.tools.ant.AntLog? = null
|
||||||
|
^
|
||||||
|
COMPILATION_ERROR
|
||||||
|
|||||||
@@ -14,4 +14,8 @@ fun main(args: Array<String>) {
|
|||||||
// Module oracle.desktop
|
// Module oracle.desktop
|
||||||
val a: com.oracle.awt.AWTUtils? = null
|
val a: com.oracle.awt.AWTUtils? = null
|
||||||
println(a)
|
println(a)
|
||||||
|
|
||||||
|
// No module, this class is declared in $JDK_9/lib/ant-javafx.jar
|
||||||
|
val x: com.sun.javafx.tools.ant.AntLog? = null
|
||||||
|
println(x)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
|||||||
.replace("\\", "/")
|
.replace("\\", "/")
|
||||||
.replace(KotlinCompilerVersion.VERSION, "$VERSION$");
|
.replace(KotlinCompilerVersion.VERSION, "$VERSION$");
|
||||||
|
|
||||||
return normalizedOutputWithoutExitCode + exitCode;
|
return normalizedOutputWithoutExitCode + exitCode + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTest(@NotNull String fileName, @NotNull CLITool<?> compiler) throws Exception {
|
private void doTest(@NotNull String fileName, @NotNull CLITool<?> compiler) throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user