diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt index 1de36544a15..067fe7f6bbc 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt @@ -24,8 +24,6 @@ import java.io.File import java.util.regex.Pattern object PathUtil { - const val JPS_KOTLIN_HOME_PROPERTY = "jps.kotlin.home" - const val JS_LIB_JAR_NAME = "kotlin-stdlib-js.jar" const val JS_LIB_10_JAR_NAME = "kotlin-jslib.jar" const val ALLOPEN_PLUGIN_JAR_NAME = "allopen-compiler-plugin.jar" @@ -53,7 +51,7 @@ object PathUtil { val KOTLIN_STDLIB_JS_JAR_PATTERN: Pattern = Pattern.compile("kotlin-stdlib-js.*\\.jar") val KOTLIN_JS_LIBRARY_JAR_PATTERN: Pattern = Pattern.compile("kotlin-js-library.*\\.jar") - private const val HOME_FOLDER_NAME = "kotlinc" + const val HOME_FOLDER_NAME = "kotlinc" private val NO_PATH = File("") @JvmStatic @@ -63,23 +61,6 @@ object PathUtil { else KotlinPathsFromHomeDir(compilerPathForIdeaPlugin) - // 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 val kotlinPathsForJpsPlugin: KotlinPaths - get() { - val jpsKotlinHome = System.getProperty(JPS_KOTLIN_HOME_PROPERTY) - return if (jpsKotlinHome != null) { - KotlinPathsFromHomeDir(File(jpsKotlinHome)) - } - else KotlinPathsFromHomeDir(compilerPathForJpsPlugin) - } - - val kotlinPathsForJpsPluginOrJpsTests: KotlinPaths - get() = if ("true".equals(System.getProperty("kotlin.jps.tests"), ignoreCase = true)) { - kotlinPathsForDistDirectory - } - else kotlinPathsForJpsPlugin - @JvmStatic val kotlinPathsForCompiler: KotlinPaths get() = if (!pathUtilJar.isFile) { @@ -105,19 +86,6 @@ object PathUtil { return NO_PATH } - private val compilerPathForJpsPlugin: File - get() { - val jar = pathUtilJar - if (!jar.exists()) return NO_PATH - - if (jar.name == "kotlin-jps-plugin.jar") { - val pluginHome = jar.parentFile.parentFile.parentFile - return File(pluginHome, HOME_FOLDER_NAME) - } - - return NO_PATH - } - private val compilerPathForIdeaPlugin: File get() { val jar = pathUtilJar diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment.kt b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment.kt index 9579bc1a1e1..58cbe194574 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsCompilerEnvironment.kt @@ -16,28 +16,18 @@ package org.jetbrains.kotlin.compilerRunner -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.ERROR import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.config.Services import org.jetbrains.kotlin.preloading.ClassCondition import org.jetbrains.kotlin.utils.KotlinPaths -import org.jetbrains.kotlin.utils.PathUtil class JpsCompilerEnvironment( val kotlinPaths: KotlinPaths, services: Services, val classesToLoadByParent: ClassCondition, messageCollector: MessageCollector, - override val outputItemsCollector: OutputItemsCollectorImpl + outputItemsCollector: OutputItemsCollectorImpl ) : CompilerEnvironment(services, messageCollector, outputItemsCollector) { - fun success(): Boolean { - return kotlinPaths.homePath.exists() - } - - fun reportErrorsTo(messageCollector: MessageCollector) { - if (!kotlinPaths.homePath.exists()) { - messageCollector.report(ERROR, "Cannot find kotlinc home: " + kotlinPaths.homePath + ". Make sure plugin is properly installed, " + - "or specify " + PathUtil.JPS_KOTLIN_HOME_PROPERTY + " system property") - } - } + override val outputItemsCollector: OutputItemsCollectorImpl + get() = super.outputItemsCollector as OutputItemsCollectorImpl } diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index 3cfc091740a..54399c116b9 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -68,9 +68,7 @@ import org.jetbrains.kotlin.modules.TargetId import org.jetbrains.kotlin.preloading.ClassCondition import org.jetbrains.kotlin.progress.CompilationCanceledException import org.jetbrains.kotlin.progress.CompilationCanceledStatus -import org.jetbrains.kotlin.utils.JsLibraryUtils -import org.jetbrains.kotlin.utils.PathUtil -import org.jetbrains.kotlin.utils.keysToMap +import org.jetbrains.kotlin.utils.* import org.jetbrains.org.objectweb.asm.ClassReader import java.io.File import java.util.* @@ -82,6 +80,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { val LOG = Logger.getInstance("#org.jetbrains.kotlin.jps.build.KotlinBuilder") const val JVM_BUILD_META_INFO_FILE_NAME = "jvm-build-meta-info.txt" const val SKIP_CACHE_VERSION_CHECK_PROPERTY = "kotlin.jps.skip.cache.version.check" + const val JPS_KOTLIN_HOME_PROPERTY = "jps.kotlin.home" } private val statisticsLogger = TeamcityStatisticsLogger() @@ -243,11 +242,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { val project = projectDescriptor.project val lookupTracker = getLookupTracker(project) val incrementalCaches = getIncrementalCaches(chunk, context) - val environment = createCompileEnvironment(incrementalCaches, lookupTracker, context, messageCollector) - if (!environment.success()) { - environment.reportErrorsTo(messageCollector) - return ABORT - } + val environment = createCompileEnvironment(incrementalCaches, lookupTracker, context, messageCollector) ?: return ABORT val commonArguments = compilerArgumentsForChunk(chunk).apply { reportOutputFiles = true @@ -458,7 +453,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) { lookupTracker: LookupTracker, context: CompileContext, messageCollector: MessageCollectorAdapter - ): JpsCompilerEnvironment { + ): JpsCompilerEnvironment? { val compilerServices = with(Services.Builder()) { register(IncrementalCompilationComponents::class.java, IncrementalCompilationComponentsImpl(incrementalCaches.mapKeys { TargetId(it.key) }, @@ -471,8 +466,15 @@ 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( - PathUtil.kotlinPathsForJpsPluginOrJpsTests, + paths, compilerServices, ClassCondition { className -> className.startsWith("org.jetbrains.kotlin.load.kotlin.incremental.components.") @@ -488,6 +490,27 @@ 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? { + 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 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( chunk: ModuleChunk, outputItemCollector: OutputItemsCollectorImpl