From 63243b99fa16682a5331830c634afd2fe8298f4a Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Wed, 19 Apr 2017 18:18:38 +0300 Subject: [PATCH] Kapt3: Check if the 'tools.jar' is present in the plugin classpath (KT-17456) Kapt3 won't work without the 'tools.jar' file provided, but we shouldn't throw an exception in this case. This commit adds the warning message (and disables Kapt if it can't be used). --- .../src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt index 724215a5f7a..ec2350f6825 100644 --- a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt +++ b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/Kapt3Plugin.kt @@ -159,6 +159,10 @@ class Kapt3CommandLineProcessor : CommandLineProcessor { } class Kapt3ComponentRegistrar : ComponentRegistrar { + private companion object { + private const val JAVAC_CONTEXT_CLASS = "com.sun.tools.javac.util.Context" + } + fun decodeOptions(options: String): Map { val map = LinkedHashMap() @@ -184,6 +188,13 @@ class Kapt3ComponentRegistrar : ComponentRegistrar { ?: PrintingMessageCollector(System.err, MessageRenderer.PLAIN_FULL_PATHS, isVerbose) val logger = KaptLogger(isVerbose, messageCollector) + try { + Class.forName(JAVAC_CONTEXT_CLASS) + } catch (e: ClassNotFoundException) { + logger.warn("'$JAVAC_CONTEXT_CLASS' class can't be found ('tools.jar' is absent in the plugin classpath). Kapt won't work.") + return + } + val sourcesOutputDir = configuration.get(Kapt3ConfigurationKeys.SOURCE_OUTPUT_DIR)?.let(::File) val classFilesOutputDir = configuration.get(Kapt3ConfigurationKeys.CLASS_OUTPUT_DIR)?.let(::File) val stubsOutputDir = configuration.get(Kapt3ConfigurationKeys.STUBS_OUTPUT_DIR)?.let(::File)