From 02bef14710560c034d45b9726c21bc133589558d Mon Sep 17 00:00:00 2001 From: Nikita Bobko Date: Tue, 21 Dec 2021 17:45:35 +0100 Subject: [PATCH] Refactor how JPS finds it's home. Now it's more reliable Part of KTIJ-11633 --- .../kotlin/jps/build/KotlinBuilder.kt | 35 +++++++------------ 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index 1adc5ec86e3..e0f15e5b1d1 100644 --- a/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -574,17 +574,8 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { build() } - val paths = computeKotlinPathsForJpsPlugin() - if (paths == null || !paths.homePath.exists()) { - messageCollector.report( - ERROR, "Cannot find kotlinc home. Make sure the plugin is properly installed, " + - "or specify $JPS_KOTLIN_HOME_PROPERTY system property" - ) - return null - } - return JpsCompilerEnvironment( - paths, + computeKotlinPathsForJpsPlugin(messageCollector) ?: return null, compilerServices, classesToLoadByParent, messageCollector, @@ -595,23 +586,23 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { // When JPS is run on TeamCity, it can not rely on Kotlin plugin layout, // so the path to Kotlin is specified in a system property - private fun computeKotlinPathsForJpsPlugin(): KotlinPaths? { + private fun computeKotlinPathsForJpsPlugin(messageCollector: MessageCollectorAdapter): KotlinPaths? { if (System.getProperty("kotlin.jps.tests").equals("true", ignoreCase = true)) { return PathUtil.kotlinPathsForDistDirectory } - val jpsKotlinHome = System.getProperty(JPS_KOTLIN_HOME_PROPERTY) - if (jpsKotlinHome != null) { - return KotlinPathsFromHomeDir(File(jpsKotlinHome)) + val jpsKotlinHome = System.getProperty(JPS_KOTLIN_HOME_PROPERTY)?.let { File(it) } + return when { + jpsKotlinHome == null -> { + messageCollector.report(ERROR, "Make sure that '$JPS_KOTLIN_HOME_PROPERTY' system property is set in JPS process") + null + } + jpsKotlinHome.exists() -> KotlinPathsFromHomeDir(jpsKotlinHome) + else -> { + messageCollector.report(ERROR, "Cannot find kotlinc home at $jpsKotlinHome") + null + } } - - val jar = PathUtil.pathUtilJar.takeIf(File::exists) - if (jar?.name == "kotlin-jps-plugin.jar") { - val pluginHome = jar.parentFile.parentFile.parentFile - return KotlinPathsFromHomeDir(File(pluginHome, PathUtil.HOME_FOLDER_NAME)) - } - - return null } private fun getGeneratedFiles(