From 61e52f0bfee12486f8276198f41e7bc30735c277 Mon Sep 17 00:00:00 2001 From: Vladimir Koshelev Date: Sun, 2 Jul 2017 03:22:23 +0300 Subject: [PATCH] Improve a reported message if -jdk-home path does not exist. Fix KT-18794 --- .../cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt | 4 ++++ compiler/testData/cli/jvm/jdkPathDoesNotExist.args | 5 +++++ compiler/testData/cli/jvm/jdkPathDoesNotExist.out | 2 ++ .../tests/org/jetbrains/kotlin/cli/CliTestGenerated.java | 6 ++++++ 4 files changed, 17 insertions(+) create mode 100644 compiler/testData/cli/jvm/jdkPathDoesNotExist.args create mode 100644 compiler/testData/cli/jvm/jdkPathDoesNotExist.out diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index 1949b68ee19..bd942984163 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -407,6 +407,10 @@ class K2JVMCompiler : CLICompiler() { val (jdkHome, classesRoots) = if (arguments.jdkHome != null) { val jdkHome = File(arguments.jdkHome) + if (!jdkHome.exists()) { + messageCollector.report(ERROR, "JDK home directory does not exist: $jdkHome") + return COMPILATION_ERROR + } messageCollector.report(LOGGING, "Using JDK home directory $jdkHome") jdkHome to PathUtil.getJdkClassesRoots(jdkHome) } diff --git a/compiler/testData/cli/jvm/jdkPathDoesNotExist.args b/compiler/testData/cli/jvm/jdkPathDoesNotExist.args new file mode 100644 index 00000000000..f620cc138fe --- /dev/null +++ b/compiler/testData/cli/jvm/jdkPathDoesNotExist.args @@ -0,0 +1,5 @@ +$TESTDATA_DIR$/simple.kt +-d +$TEMP_DIR$ +-jdk-home +$TESTDATA_DIR$/abacaba diff --git a/compiler/testData/cli/jvm/jdkPathDoesNotExist.out b/compiler/testData/cli/jvm/jdkPathDoesNotExist.out new file mode 100644 index 00000000000..155c2f6891b --- /dev/null +++ b/compiler/testData/cli/jvm/jdkPathDoesNotExist.out @@ -0,0 +1,2 @@ +error: JDK home directory does not exist: compiler/testData/cli/jvm/abacaba +COMPILATION_ERROR diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java index 41a4639ae0a..34b6da70052 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -224,6 +224,12 @@ public class CliTestGenerated extends AbstractCliTest { doJvmTest(fileName); } + @TestMetadata("jdkPathDoesNotExist.args") + public void testJdkPathDoesNotExist() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jdkPathDoesNotExist.args"); + doJvmTest(fileName); + } + @TestMetadata("jvm8Target.args") public void testJvm8Target() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/jvm8Target.args");