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).
This commit is contained in:
Yan Zhulanow
2017-04-19 18:18:38 +03:00
committed by Yan Zhulanow
parent 20e362e363
commit 63243b99fa
@@ -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<String, String> {
val map = LinkedHashMap<String, String>()
@@ -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)