From 01a05a5495049668c0255c9b6f42adb17245a32b Mon Sep 17 00:00:00 2001 From: Vadim Brilyantov Date: Wed, 3 Apr 2019 19:34:06 +0300 Subject: [PATCH] Move daemon jar from compiler --- .../incremental}/IncrementalModuleInfo.kt | 2 +- build.gradle.kts | 5 +- compiler/build.gradle.kts | 9 +- compiler/compiler-runner/build.gradle.kts | 6 +- compiler/daemon/build.gradle.kts | 43 +++- .../daemon/daemon-client-new/build.gradle.kts | 15 +- .../experimental/KotlinCompilerClient.kt | 35 +-- .../daemon/daemon-client/build.gradle.kts | 6 +- .../daemon/daemon-common-new/build.gradle.kts | 4 +- .../daemon/common/experimental/ClientUtils.kt | 6 +- ...entalCompilerServicesFacadeAsyncWrapper.kt | 1 - ...ementalCompilerServicesFacadeClientSide.kt | 2 - ...ementalCompilerServicesFacadeRMIWrapper.kt | 2 - ...ementalCompilerServicesFacadeServerSide.kt | 3 - .../common/experimental/NetworkUtils.kt | 77 +----- .../common/experimental/RemoteStreamAsync.kt | 29 --- .../RemoteStreamAsyncClientSide.kt | 12 - .../RemoteStreamAsyncServerSide.kt | 43 ---- .../experimental/RemoteStreamAsyncWrapper.kt | 41 ---- .../socketInfrastructure/Client.kt | 5 +- .../daemon/daemon-common/build.gradle.kts | 3 +- .../daemon/common/CompilationOptions.kt | 1 + .../kotlin/daemon/common/NetworkUtils.kt | 18 +- .../kotlin/daemon/common/PerfUtils.kt | 44 ++-- .../kotlin/daemon/CompileServiceImpl.kt | 54 ++--- .../kotlin/daemon/KotlinCompileDaemon.kt | 223 ++++++++++-------- .../kotlin/daemon/KotlinRemoteReplService.kt | 27 +-- .../CompileServiceServerSideImpl.kt | 10 +- .../experimental/KotlinCompileDaemon.kt | 205 ++++------------ .../experimental/KotlinRemoteReplService.kt | 11 +- .../experimental/RemoteOutputStreamClient.kt | 27 --- .../experimental/RemoteReplStateFacadeImpl.kt | 4 +- .../build.gradle.kts | 2 +- .../multiproject/ModulesApiHistory.kt | 4 +- .../ModulesApiHistoryAndroidTest.kt | 4 +- compiler/tests-common/build.gradle.kts | 4 +- .../kotlin/daemon/CompilerApiTest.kt | 4 +- .../integration/CompilerApiTest.kt | 6 +- .../integration/CompilerDaemonTest.kt | 16 +- .../unit/ClientSerializationTest.kt | 2 +- .../experimental/unit/ConnectionsTest.kt | 8 +- .../org/jetbrains/kotlin/utils/KotlinPaths.kt | 5 +- .../org/jetbrains/kotlin/utils/PathUtil.kt | 3 + idea/build.gradle.kts | 4 +- .../complexBuildGradleKts/build.gradle.kts | 4 +- jps-plugin/build.gradle.kts | 5 +- .../compilerRunner/JpsKotlinCompilerRunner.kt | 3 +- .../build.gradle.kts | 3 +- .../build.gradle.kts | 2 +- libraries/scripting/jvm-host/build.gradle.kts | 2 +- .../kotlin-gradle-plugin/build.gradle.kts | 2 +- .../GradleKotlinCompilerRunner.kt | 16 +- .../GradleKotlinCompilerWork.kt | 3 +- .../kotlin/gradle/tasks/jarSearchingUtil.kt | 14 +- .../tools/kotlin-script-util/build.gradle.kts | 2 +- .../third_party/testdata/findbugs_license.txt | 4 +- nj2k/nj2k-services/build.gradle.kts | 2 +- .../source-sections-compiler/build.gradle.kts | 2 +- .../build.gradle.kts | 8 +- prepare/compiler-embeddable/build.gradle.kts | 1 + prepare/compiler/build.gradle.kts | 13 +- prepare/compiler/build.gradle.kts.182 | 13 +- prepare/compiler/build.gradle.kts.as34 | 13 +- prepare/idea-plugin/build.gradle.kts | 8 +- prepare/jps-plugin/build.gradle.kts | 4 +- .../kotlin-daemon-embeddable/build.gradle.kts | 28 +++ settings.gradle | 13 +- 67 files changed, 441 insertions(+), 759 deletions(-) rename {compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common => build-common/src/org/jetbrains/kotlin/incremental}/IncrementalModuleInfo.kt (95%) delete mode 100644 compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsync.kt delete mode 100644 compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsyncClientSide.kt delete mode 100644 compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsyncServerSide.kt delete mode 100644 compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsyncWrapper.kt delete mode 100644 compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/RemoteOutputStreamClient.kt create mode 100644 prepare/kotlin-daemon-embeddable/build.gradle.kts diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/IncrementalModuleInfo.kt b/build-common/src/org/jetbrains/kotlin/incremental/IncrementalModuleInfo.kt similarity index 95% rename from compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/IncrementalModuleInfo.kt rename to build-common/src/org/jetbrains/kotlin/incremental/IncrementalModuleInfo.kt index dbfd2552fed..a49ec4eb04a 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/IncrementalModuleInfo.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/IncrementalModuleInfo.kt @@ -3,7 +3,7 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.daemon.common +package org.jetbrains.kotlin.incremental import java.io.File import java.io.Serializable diff --git a/build.gradle.kts b/build.gradle.kts index 14ee819eb76..5c636763df7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -172,6 +172,8 @@ extra["versions.jflex"] = "1.7.0" extra["versions.markdown"] = "0.1.25" extra["versions.trove4j"] = "1.0.20181211" extra["versions.kotlin-native-shared"] = "1.0-dev-57" + +// NOTE: please, also change KTOR_NAME in pathUtil.kt and all versions in corresponding jar names in daemon tests. extra["versions.ktor-network"] = "1.0.1" if (!project.hasProperty("versions.kotlin-native")) { @@ -210,9 +212,6 @@ extra["compilerModules"] = arrayOf( ":compiler:frontend.common", ":compiler:frontend.java", ":compiler:cli-common", - ":compiler:daemon-common", - ":compiler:daemon-common-new", - ":compiler:daemon", ":compiler:ir.tree", ":compiler:ir.psi2ir", ":compiler:ir.backend.common", diff --git a/compiler/build.gradle.kts b/compiler/build.gradle.kts index f871c6259e8..25466ea8c65 100644 --- a/compiler/build.gradle.kts +++ b/compiler/build.gradle.kts @@ -40,6 +40,7 @@ dependencies { testCompile(kotlinStdlib()) + testCompile(project(":kotlin-daemon")) testCompile(commonDep("junit:junit")) testCompileOnly(project(":kotlin-test:kotlin-test-jvm")) testCompileOnly(project(":kotlin-test:kotlin-test-junit")) @@ -54,7 +55,7 @@ dependencies { testCompile(project(":kotlin-script-util")) testCompileOnly(projectRuntimeJar(":kotlin-daemon-client-new")) testCompileOnly(project(":kotlin-reflect-api")) - testCompile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8")) { isTransitive = false } + testCompile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } testCompile(commonDep("io.ktor", "ktor-network")) { ktorExcludesForDaemon.forEach { (group, module) -> exclude(group = group, module = module) @@ -68,9 +69,9 @@ dependencies { testRuntime(project(":kotlin-reflect")) testRuntime(project(":kotlin-daemon-client-new")) - testRuntime(project(":compiler:daemon")) // + - testRuntime(project(":compiler:daemon-common-new")) // + - testRuntime(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8")) { + testRuntime(project(":kotlin-daemon")) // + + testRuntime(project(":daemon-common-new")) // + + testRuntime(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } testRuntime(commonDep("io.ktor", "ktor-network")) { diff --git a/compiler/compiler-runner/build.gradle.kts b/compiler/compiler-runner/build.gradle.kts index 15023c3b2e1..a92cf72e479 100644 --- a/compiler/compiler-runner/build.gradle.kts +++ b/compiler/compiler-runner/build.gradle.kts @@ -13,13 +13,13 @@ dependencies { compileOnly(project(":compiler:cli-common")) compileOnly(project(":kotlin-preloader")) compileOnly(project(":compiler:frontend.java")) - compileOnly(project(":compiler:daemon-common")) - compileOnly(project(":compiler:daemon-common-new")) + compileOnly(project(":daemon-common")) + compileOnly(project(":daemon-common-new")) compile(projectRuntimeJar(":kotlin-daemon-client")) compileOnly(project(":compiler:util")) compileOnly(intellijCoreDep()) { includeJars("intellij-core") } runtimeOnly(projectRuntimeJar(":kotlin-compiler-embeddable")) - compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8")) { isTransitive = false } + compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } } sourceSets { diff --git a/compiler/daemon/build.gradle.kts b/compiler/daemon/build.gradle.kts index 74aae8690c2..72bb221183c 100644 --- a/compiler/daemon/build.gradle.kts +++ b/compiler/daemon/build.gradle.kts @@ -1,28 +1,36 @@ -import com.sun.javafx.scene.CameraHelper.project -import org.gradle.internal.impldep.org.junit.experimental.categories.Categories.CategoryFilter.exclude -import org.jetbrains.kotlin.gradle.dsl.Coroutines +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +description = "Kotlin Daemon New" plugins { kotlin("jvm") id("jps-compatible") } +jvmTarget = "1.8" + val ktorExcludesForDaemon : List> by rootProject.extra dependencies { compile(project(":compiler:cli")) compile(project(":compiler:cli-js")) - compile(project(":compiler:daemon-common")) - compile(project(":compiler:daemon-common-new")) + compile(project(":daemon-common-new")) compile(project(":compiler:incremental-compilation-impl")) - compile(project(":kotlin-build-common")) compile(commonDep("org.fusesource.jansi", "jansi")) compile(commonDep("org.jline", "jline")) compileOnly(intellijCoreDep()) { includeJars("intellij-core") } - compileOnly(intellijDep()) { includeIntellijCoreJarDependencies(project) } runtime(project(":kotlin-reflect")) - compileOnly(project(":kotlin-reflect-api")) - compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8")) { isTransitive = false } + + embedded(project(":daemon-common")) { isTransitive = false } + embedded(project(":daemon-common-new")) { isTransitive = false } + compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { + isTransitive = false + } compile(commonDep("io.ktor", "ktor-network")) { ktorExcludesForDaemon.forEach { (group, module) -> exclude(group = group, module = module) @@ -34,6 +42,17 @@ sourceSets { "main" { projectDefault() } "test" {} } -kotlin { - experimental.coroutines = Coroutines.ENABLE -} \ No newline at end of file + +publish() + +noDefaultJar() + +runtimeJar(task("shadowJar")) { + from(mainSourceSet.output) +} + +sourcesJar() + +javadocJar() + +dist() diff --git a/compiler/daemon/daemon-client-new/build.gradle.kts b/compiler/daemon/daemon-client-new/build.gradle.kts index ca5bd7323e9..16e7abcfa3f 100644 --- a/compiler/daemon/daemon-client-new/build.gradle.kts +++ b/compiler/daemon/daemon-client-new/build.gradle.kts @@ -32,20 +32,20 @@ val ktorExcludesForDaemon : List> by rootProject.extra dependencies { compileOnly(project(":compiler:util")) compileOnly(project(":compiler:cli-common")) - compileOnly(project(":compiler:daemon-common-new")) + compileOnly(project(":daemon-common-new")) compileOnly(project(":kotlin-reflect-api")) compileOnly(project(":kotlin-daemon-client")) - embeddedComponents(project(":kotlin-daemon-client")) { isTransitive = false } + embedded(project(":kotlin-daemon-client")) { isTransitive = false } compileOnly(project(":js:js.frontend")) compileOnly(commonDep("net.rubygrapefruit", "native-platform")) compileOnly(intellijDep()) { includeIntellijCoreJarDependencies(project) } - embeddedComponents(project(":compiler:daemon-common")) { isTransitive = false } - embeddedComponents(commonDep("net.rubygrapefruit", "native-platform")) + embedded(project(":daemon-common")) { isTransitive = false } + embedded(commonDep("net.rubygrapefruit", "native-platform")) nativePlatformVariants.forEach { - embeddedComponents(commonDep("net.rubygrapefruit", "native-platform", "-$it")) + embedded(commonDep("net.rubygrapefruit", "native-platform", "-$it")) } - compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8")) { + compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } compile(commonDep("io.ktor", "ktor-network")) { @@ -66,7 +66,6 @@ noDefaultJar() runtimeJar(task("shadowJar")) { from(mainSourceSet.output) - fromEmbeddedComponents() } sourcesJar() @@ -74,5 +73,3 @@ sourcesJar() javadocJar() dist() - -ideaPlugin() diff --git a/compiler/daemon/daemon-client-new/src/org/jetbrains/kotlin/daemon/client/experimental/KotlinCompilerClient.kt b/compiler/daemon/daemon-client-new/src/org/jetbrains/kotlin/daemon/client/experimental/KotlinCompilerClient.kt index 09d0a218077..cf75408bfad 100644 --- a/compiler/daemon/daemon-client-new/src/org/jetbrains/kotlin/daemon/client/experimental/KotlinCompilerClient.kt +++ b/compiler/daemon/daemon-client-new/src/org/jetbrains/kotlin/daemon/client/experimental/KotlinCompilerClient.kt @@ -45,7 +45,6 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient { val verboseReporting = System.getProperty(COMPILE_DAEMON_VERBOSE_REPORT_PROPERTY) != null private val log = Logger.getLogger("KotlinCompilerClient") - private fun String.info(msg: String) = {}()//log.info("[$this] : $msg") override fun getOrCreateClientFlagFile(daemonOptions: DaemonOptions): File = // for jps property is passed from IDEA to JPS in KotlinBuildProcessParametersProvider @@ -64,7 +63,6 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient { autostart: Boolean, checkId: Boolean ): CompileServiceAsync? { - log.info("in connectToCompileService") val flagFile = getOrCreateClientFlagFile(daemonOptions) return connectToCompileService( compilerId, @@ -84,7 +82,6 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient { reportingTargets: DaemonReportingTargets, autostart: Boolean ): CompileServiceAsync? { - log.info("connectToCompileService") return connectAndLease( compilerId, clientAliveFlagFile, @@ -112,14 +109,9 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient { reportingTargets, autostart ) { isLastAttempt -> - - log.info("connectAndLease") - fun CompileServiceAsync.leaseImpl(): Deferred = GlobalScope.async { // the newJVMOptions could be checked here for additional parameters, if needed - log.info("trying registerClient") - println("trying registerClient") try { registerClient(clientAliveFlagFile.absolutePath) } catch (e: Throwable) { @@ -149,7 +141,6 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient { service.leaseImpl().await() } else { if (!isLastAttempt && autostart) { - log.info("starting daemon...") if (startDaemon(compilerId, newJVMOptions, daemonOptions, reportingTargets)) { reportingTargets.report(DaemonReportCategory.DEBUG, "new daemon started, trying to find it") } @@ -189,7 +180,6 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient { port: Int, profiler: Profiler ): Int = profiler.withMeasure(this) { - log.info("Compile") val services = BasicCompilerServicesWithResultsFacadeServerServerSide( messageCollector, outputsCollector, @@ -431,24 +421,13 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient { daemonJVMOptions: DaemonJVMOptions, report: (DaemonReportCategory, String) -> Unit ): Deferred> = GlobalScope.async { - log.info("tryFindSuitableDaemonOrNewOpts") - registryDir.mkdirs() val timestampMarker = createTempFile("kotlin-daemon-client-tsmarker", directory = registryDir) val aliveWithMetadata = try { - log.info("walkDaemonsAsync... : ${registryDir.path}") - walkDaemonsAsync(registryDir, compilerId, timestampMarker, report = report).also { - log.info( - "daemons (${it.size}): ${it.map { "daemon(params : " + it.jvmOptions.jvmParams.joinToString(", ") + ")" }.joinToString( - ", ", "[", "]" - )}" - ) - } + walkDaemonsAsync(registryDir, compilerId, timestampMarker, report = report) } finally { timestampMarker.delete() } - log.info("daemons : ${aliveWithMetadata.map { it.daemon::class.java.name }}") - log.info("aliveWithMetadata: ${aliveWithMetadata.map { it.daemon::class.java.name }}") val comparator = compareBy(DaemonJVMOptionsMemoryComparator(), { it.jvmOptions }) .thenBy { when (it.daemon) { @@ -475,17 +454,13 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient { daemonOptions: DaemonOptions, reportingTargets: DaemonReportingTargets ): Boolean { - log.info("in startDaemon() - 0") val javaExecutable = File(File(System.getProperty("java.home"), "bin"), "java") - log.info("in startDaemon() - 0.1") val serverHostname = System.getProperty(JAVA_RMI_SERVER_HOSTNAME) ?: error("$JAVA_RMI_SERVER_HOSTNAME is not set!") - log.info("in startDaemon() - 0.2") val platformSpecificOptions = listOf( // hide daemon window "-Djava.awt.headless=true", "-D$JAVA_RMI_SERVER_HOSTNAME=$serverHostname" ) - log.info("in startDaemon() - 0.3") val args = listOf( javaExecutable.absolutePath, "-cp", compilerId.compilerClasspath.joinToString(File.pathSeparator) ) + @@ -494,13 +469,10 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient { COMPILER_DAEMON_CLASS_FQN_EXPERIMENTAL + daemonOptions.mappers.flatMap { it.toArgs(COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) } + compilerId.mappers.flatMap { it.toArgs(COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) } - log.info("in startDaemon() - 1") reportingTargets.report(DaemonReportCategory.DEBUG, "starting the daemon as: " + args.joinToString(" ")) val processBuilder = ProcessBuilder(args) - log.info("in startDaemon() - 2") processBuilder.redirectErrorStream(true) // assuming daemon process is deaf and (mostly) silent, so do not handle streams - log.info("daemon = launchProcessWithFallback") val daemon = launchProcessWithFallback(processBuilder, reportingTargets, "daemon client") @@ -548,12 +520,9 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient { } } ?: DAEMON_DEFAULT_STARTUP_TIMEOUT_MS if (daemonOptions.runFilesPath.isNotEmpty()) { - log.info("daemonOptions.runFilesPath.isNotEmpty") val succeeded = isEchoRead.tryAcquire(daemonStartupTimeout, TimeUnit.MILLISECONDS) - log.info("succeeded : $succeeded") return when { !isProcessAlive(daemon) -> { - log.info("!isProcessAlive(daemon)") reportingTargets.report( DaemonReportCategory.INFO, "Daemon terminated unexpectedly with error code: ${daemon.exitValue()}" @@ -561,14 +530,12 @@ class KotlinCompilerClient : KotlinCompilerDaemonClient { false } !succeeded -> { - log.info("isProcessAlive!") reportingTargets.report(DaemonReportCategory.INFO, "Unable to get response from daemon in $daemonStartupTimeout ms") false } else -> true } } else - log.info("!daemonOptions.runFilesPath.isNotEmpty") // without startEcho defined waiting for max timeout Thread.sleep(daemonStartupTimeout) return true diff --git a/compiler/daemon/daemon-client/build.gradle.kts b/compiler/daemon/daemon-client/build.gradle.kts index 293453f43e1..cebe128fb44 100644 --- a/compiler/daemon/daemon-client/build.gradle.kts +++ b/compiler/daemon/daemon-client/build.gradle.kts @@ -23,19 +23,19 @@ val nativePlatformVariants = listOf( dependencies { compileOnly(project(":compiler:util")) compileOnly(project(":compiler:cli-common")) - compileOnly(project(":compiler:daemon-common")) + compileOnly(project(":daemon-common")) compileOnly(project(":kotlin-reflect-api")) compileOnly(project(":js:js.frontend")) compileOnly(commonDep("net.rubygrapefruit", "native-platform")) compileOnly(intellijDep()) { includeIntellijCoreJarDependencies(project) } - embedded(project(":compiler:daemon-common")) { isTransitive = false } + embedded(project(":daemon-common")) { isTransitive = false } embedded(commonDep("net.rubygrapefruit", "native-platform")) nativePlatformVariants.forEach { embedded(commonDep("net.rubygrapefruit", "native-platform", "-$it")) } runtime(project(":kotlin-reflect")) - compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8")) { + compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } } diff --git a/compiler/daemon/daemon-common-new/build.gradle.kts b/compiler/daemon/daemon-common-new/build.gradle.kts index 295af070405..4d162ef553d 100644 --- a/compiler/daemon/daemon-common-new/build.gradle.kts +++ b/compiler/daemon/daemon-common-new/build.gradle.kts @@ -25,12 +25,12 @@ dependencies { compile(project(":core:descriptors.jvm")) compile(project(":compiler:util")) compile(project(":compiler:cli-common")) - compileOnly(project(":compiler:daemon-common")) + compileOnly(project(":daemon-common")) compile(kotlinStdlib()) compileOnly(project(":js:js.frontend")) compileOnly(intellijCoreDep()) { includeJars("intellij-core") } compileOnly(intellijDep()) { includeIntellijCoreJarDependencies(project) } - compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8")) { + compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } compile(commonDep("io.ktor", "ktor-network")) { diff --git a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/ClientUtils.kt b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/ClientUtils.kt index 40d025953a9..35415c3a177 100644 --- a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/ClientUtils.kt +++ b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/ClientUtils.kt @@ -99,9 +99,9 @@ private inline fun tryConnectToDaemonByRMI(port: Int, report: (DaemonReportCateg val daemon = runBlocking { runWithTimeout(2 * DAEMON_PERIODIC_CHECK_INTERVAL_MS) { LocateRegistry.getRegistry( - LoopbackNetworkInterface.loopbackInetAddressName, + org.jetbrains.kotlin.daemon.common.LoopbackNetworkInterface.loopbackInetAddressName, port, - LoopbackNetworkInterface.clientLoopbackSocketFactoryRMI + org.jetbrains.kotlin.daemon.common.LoopbackNetworkInterface.clientLoopbackSocketFactory )?.lookup(COMPILER_SERVICE_RMI_NAME) } } @@ -134,7 +134,7 @@ private suspend fun tryConnectToDaemonBySockets( log.info("OK - daemon($port) connected to server!!!") daemon } catch (e: Throwable) { - report(DaemonReportCategory.INFO, "kcannot find or connect to socket") + report(DaemonReportCategory.INFO, "cannot find or connect to socket, exception:\n${e.javaClass.name}:${e.message}") daemon.close() null } diff --git a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeAsyncWrapper.kt b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeAsyncWrapper.kt index 8316354cddf..8dbb9c66f26 100644 --- a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeAsyncWrapper.kt +++ b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeAsyncWrapper.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.daemon.common.experimental import org.jetbrains.kotlin.daemon.common.IncrementalCompilerServicesFacade -import org.jetbrains.kotlin.daemon.common.SimpleDirtyData import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.Client import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.DefaultClientRMIWrapper import java.io.File diff --git a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeClientSide.kt b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeClientSide.kt index ee926b54fa1..f7de20d40bc 100644 --- a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeClientSide.kt +++ b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeClientSide.kt @@ -6,8 +6,6 @@ package org.jetbrains.kotlin.daemon.common.experimental import org.jetbrains.kotlin.daemon.common.IncrementalCompilerServicesFacadeAsync -import org.jetbrains.kotlin.daemon.common.SimpleDirtyData -import org.jetbrains.kotlin.daemon.common.experimental.IncrementalCompilerServicesFacadeServerSide.* import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.Client import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.DefaultClient import java.io.File diff --git a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeRMIWrapper.kt b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeRMIWrapper.kt index 03c97682912..7d21ed3ffe2 100644 --- a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeRMIWrapper.kt +++ b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeRMIWrapper.kt @@ -7,8 +7,6 @@ package org.jetbrains.kotlin.daemon.common.experimental import kotlinx.coroutines.runBlocking import org.jetbrains.kotlin.daemon.common.IncrementalCompilerServicesFacade -import org.jetbrains.kotlin.daemon.common.SimpleDirtyData -import java.io.File import java.io.Serializable class IncrementalCompilerServicesFacadeRMIWrapper(val clientSide: IncrementalCompilerServicesFacadeClientSide) : diff --git a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeServerSide.kt b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeServerSide.kt index 71b7f72f5fb..a16024f494d 100644 --- a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeServerSide.kt +++ b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/IncrementalCompilerServicesFacadeServerSide.kt @@ -6,9 +6,6 @@ package org.jetbrains.kotlin.daemon.common.experimental import org.jetbrains.kotlin.daemon.common.IncrementalCompilerServicesFacadeAsync -import org.jetbrains.kotlin.daemon.common.SimpleDirtyData -import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.Server -import java.io.File interface IncrementalCompilerServicesFacadeServerSide : IncrementalCompilerServicesFacadeAsync, CompilerServicesFacadeBaseServerSide \ No newline at end of file diff --git a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/NetworkUtils.kt b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/NetworkUtils.kt index 4ffc1d95dd7..d857f774e91 100644 --- a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/NetworkUtils.kt +++ b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/NetworkUtils.kt @@ -18,58 +18,11 @@ import java.rmi.server.RMIServerSocketFactory import java.util.* -// copyed from original(org.jetbrains.kotlin.daemon.common.NetworkUtils) TODO -// unique part : -// - AbstractClientLoopbackSocketFactory / ServerLoopbackSocketFactoryRMI / ServerLoopbackSocketFactoryKtor - Ktor-Sockets instead of java sockets -// - findPortAndCreateSocket -// TODO: get rid of copy-paste here - -object LoopbackNetworkInterface { - - const val IPV4_LOOPBACK_INET_ADDRESS = "127.0.0.1" - const val IPV6_LOOPBACK_INET_ADDRESS = "::1" - - // size of the requests queue for daemon services, so far seems that we don't need any big numbers here - // but if we'll start getting "connection refused" errors, that could be the first place to try to fix it - val SERVER_SOCKET_BACKLOG_SIZE by lazy { - System.getProperty(DAEMON_RMI_SOCKET_BACKLOG_SIZE_PROPERTY)?.toIntOrNull() ?: DEFAULT_SERVER_SOCKET_BACKLOG_SIZE - } - val SOCKET_CONNECT_ATTEMPTS by lazy { - System.getProperty(DAEMON_RMI_SOCKET_CONNECT_ATTEMPTS_PROPERTY)?.toIntOrNull() ?: DEFAULT_SOCKET_CONNECT_ATTEMPTS - } - val SOCKET_CONNECT_INTERVAL_MS by lazy { - System.getProperty(DAEMON_RMI_SOCKET_CONNECT_INTERVAL_PROPERTY)?.toLongOrNull() ?: DEFAULT_SOCKET_CONNECT_INTERVAL_MS - } - - val serverLoopbackSocketFactoryRMI by lazy { ServerLoopbackSocketFactoryRMI() } - val clientLoopbackSocketFactoryRMI by lazy { ClientLoopbackSocketFactoryRMI() } +object LoopbackNetworkInterfaceKtor { val serverLoopbackSocketFactoryKtor by lazy { ServerLoopbackSocketFactoryKtor() } val clientLoopbackSocketFactoryKtor by lazy { ClientLoopbackSocketFactoryKtor() } - // TODO switch to InetAddress.getLoopbackAddress on java 7+ - val loopbackInetAddressName by lazy { - try { - if (InetAddress.getByName(null) is Inet6Address) IPV6_LOOPBACK_INET_ADDRESS else IPV4_LOOPBACK_INET_ADDRESS - } catch (e: IOException) { - // getLocalHost may fail for unknown reasons in some situations, the fallback is to assume IPv4 for now - // TODO consider some other ways to detect default to IPv6 addresses in this case - IPV4_LOOPBACK_INET_ADDRESS - } - } - - // base socket factories by default don't implement equals properly (see e.g. http://stackoverflow.com/questions/21555710/rmi-and-jmx-socket-factories) - // so implementing it in derived classes using the fact that they are singletons - - class ServerLoopbackSocketFactoryRMI : RMIServerSocketFactory, Serializable { - override fun equals(other: Any?): Boolean = other === this || super.equals(other) - override fun hashCode(): Int = super.hashCode() - - @Throws(IOException::class) - override fun createServerSocket(port: Int): java.net.ServerSocket = - ServerSocket(port, SERVER_SOCKET_BACKLOG_SIZE, InetAddress.getByName(null)) - } - val selectorMgr = ActorSelectorManager(Dispatchers.IO) class ServerLoopbackSocketFactoryKtor : Serializable { @@ -83,31 +36,7 @@ object LoopbackNetworkInterface { .bind(InetSocketAddress(InetAddress.getByName(null), port)) // TODO : NO BACKLOG SIZE CHANGE =( } - abstract class AbstractClientLoopbackSocketFactory : Serializable { - override fun equals(other: Any?): Boolean = other === this || super.equals(other) - override fun hashCode(): Int = super.hashCode() - - abstract protected fun socketCreate(host: String, port: Int): SocketType - - @Throws(IOException::class) - fun createSocket(host: String, port: Int): SocketType { - var attemptsLeft = SOCKET_CONNECT_ATTEMPTS - while (true) { - try { - return socketCreate(host, port) - } catch (e: ConnectException) { - if (--attemptsLeft <= 0) throw e - } - Thread.sleep(SOCKET_CONNECT_INTERVAL_MS) - } - } - } - - class ClientLoopbackSocketFactoryRMI : AbstractClientLoopbackSocketFactory(), RMIClientSocketFactory { - override fun socketCreate(host: String, port: Int): Socket = Socket(InetAddress.getByName(null), port) - } - - class ClientLoopbackSocketFactoryKtor : AbstractClientLoopbackSocketFactory() { + class ClientLoopbackSocketFactoryKtor : LoopbackNetworkInterface.AbstractClientLoopbackSocketFactory() { override fun socketCreate(host: String, port: Int): io.ktor.network.sockets.Socket = runBlocking { aSocket(selectorMgr).tcp().connect(InetSocketAddress(host, port)) } } @@ -126,7 +55,7 @@ fun findPortForSocket(attempts: Int, portRangeStart: Int, portRangeEnd: Int): Se try { return ServerSocketWrapper( port, - LoopbackNetworkInterface.serverLoopbackSocketFactoryKtor.createServerSocket(port) + LoopbackNetworkInterfaceKtor.serverLoopbackSocketFactoryKtor.createServerSocket(port) ) } catch (e: Exception) { // assuming that the socketPort is already taken diff --git a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsync.kt b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsync.kt deleted file mode 100644 index 923c5c9174a..00000000000 --- a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsync.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.daemon.common.experimental - -interface RemoteOutputStreamAsync { - - /** closeStream() name is chosen since Clients are AutoClosable now - * and Client-implementations of RemoteOutputStreamAsync have conflict of 'close' name **/ - suspend fun closeStream() - - suspend fun write(data: ByteArray, offset: Int, length: Int) - - suspend fun write(dataByte: Int) -} - -interface RemoteInputStreamAsync { - - /** closeStream() name is chosen since Clients are AutoClosable now - * and Client-implementations of RemoteInputStreamAsync have conflict of 'close' name **/ - suspend fun closeStream() - - suspend fun read(length: Int): ByteArray - - suspend fun read(): Int - -} \ No newline at end of file diff --git a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsyncClientSide.kt b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsyncClientSide.kt deleted file mode 100644 index b29fa395b4c..00000000000 --- a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsyncClientSide.kt +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.daemon.common.experimental - -import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.Client - -interface RemoteOutputStreamAsyncClientSide : RemoteOutputStreamAsync, Client - -interface RemoteInputStreamClientSide : RemoteInputStreamAsync, Client diff --git a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsyncServerSide.kt b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsyncServerSide.kt deleted file mode 100644 index 0c890955a82..00000000000 --- a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsyncServerSide.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.daemon.common.experimental - -import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.ByteWriteChannelWrapper -import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.Server - - -interface RemoteOutputStreamAsyncServerSide : RemoteOutputStreamAsync, Server { - // Query messages: - class CloseMessage : Server.Message() { - override suspend fun processImpl(server: RemoteOutputStreamAsyncServerSide, sendReply: (Any?) -> Unit) = - server.closeStream() - } - - class WriteMessage(val data: ByteArray, val offset: Int = -1, val length: Int = -1) : - Server.Message() { - override suspend fun processImpl(server: RemoteOutputStreamAsyncServerSide, sendReply: (Any?) -> Unit) = - server.write(data, offset, length) - } - - class WriteIntMessage(val dataByte: Int) : Server.Message() { - override suspend fun processImpl(server: RemoteOutputStreamAsyncServerSide, sendReply: (Any?) -> Unit) = - server.write(dataByte) - } -} - - -interface RemoteInputStreamServerSide : RemoteInputStreamAsync, Server { - // Query messages: - class CloseMessage : Server.Message() { - override suspend fun processImpl(server: RemoteInputStreamServerSide, sendReply: (Any?) -> Unit) = - server.closeStream() - } - - class ReadMessage(val length: Int = -1) : Server.Message() { - override suspend fun processImpl(server: RemoteInputStreamServerSide, sendReply: (Any?) -> Unit) = - sendReply(if (length == -1) server.read() else server.read(length)) - } -} \ No newline at end of file diff --git a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsyncWrapper.kt b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsyncWrapper.kt deleted file mode 100644 index e313b26f33d..00000000000 --- a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/RemoteStreamAsyncWrapper.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.daemon.common.experimental - -import org.jetbrains.kotlin.daemon.common.RemoteInputStream -import org.jetbrains.kotlin.daemon.common.RemoteOutputStream -import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.Client -import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.DefaultClientRMIWrapper - -class RemoteOutputStreamAsyncWrapper(val rmiOutput: RemoteOutputStream) : RemoteOutputStreamAsyncClientSide, - Client by DefaultClientRMIWrapper() { - - override suspend fun closeStream() = - rmiOutput.close() - - override suspend fun write(data: ByteArray, offset: Int, length: Int) = - rmiOutput.write(data, offset, length) - - override suspend fun write(dataByte: Int) = - rmiOutput.write(dataByte) - -} - -class RemoteInputStreamAsyncWrapper(private val rmiInput: RemoteInputStream) : RemoteInputStreamClientSide, - Client by DefaultClientRMIWrapper() { - - override suspend fun closeStream() = - rmiInput.close() - - override suspend fun read() = - rmiInput.read() - - override suspend fun read(length: Int) = - rmiInput.read(length) -} - -fun RemoteOutputStream.toClient() = RemoteOutputStreamAsyncWrapper(this) -fun RemoteInputStream.toClient() = RemoteInputStreamAsyncWrapper(this) \ No newline at end of file diff --git a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/socketInfrastructure/Client.kt b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/socketInfrastructure/Client.kt index be61accbe71..8735f7b93d2 100644 --- a/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/socketInfrastructure/Client.kt +++ b/compiler/daemon/daemon-common-new/src/org/jetbrains/kotlin/daemon/common/experimental/socketInfrastructure/Client.kt @@ -3,7 +3,8 @@ package org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure import io.ktor.network.sockets.Socket import kotlinx.coroutines.channels.* import kotlinx.coroutines.* -import org.jetbrains.kotlin.daemon.common.experimental.LoopbackNetworkInterface +import org.jetbrains.kotlin.daemon.common.LoopbackNetworkInterface +import org.jetbrains.kotlin.daemon.common.experimental.LoopbackNetworkInterfaceKtor import sun.net.ConnectionResetException import java.beans.Transient import java.io.IOException @@ -198,7 +199,7 @@ abstract class DefaultAuthorizableClient( try { - socket = LoopbackNetworkInterface.clientLoopbackSocketFactoryKtor.createSocket( + socket = LoopbackNetworkInterfaceKtor.clientLoopbackSocketFactoryKtor.createSocket( serverHost, serverPort ) diff --git a/compiler/daemon/daemon-common/build.gradle.kts b/compiler/daemon/daemon-common/build.gradle.kts index 81d88d0757e..44d19607f83 100644 --- a/compiler/daemon/daemon-common/build.gradle.kts +++ b/compiler/daemon/daemon-common/build.gradle.kts @@ -10,11 +10,12 @@ dependencies { compile(project(":core:descriptors.jvm")) compile(project(":compiler:util")) compile(project(":compiler:cli-common")) + compile(project(":kotlin-build-common")) compile(kotlinStdlib()) compileOnly(project(":js:js.frontend")) compileOnly(intellijCoreDep()) { includeJars("intellij-core") } compileOnly(intellijDep()) { includeIntellijCoreJarDependencies(project) } - compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-jdk8")) { + compile(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } } diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationOptions.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationOptions.kt index 22a05153ace..640082b79ad 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationOptions.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompilationOptions.kt @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.daemon.common +import org.jetbrains.kotlin.incremental.IncrementalModuleInfo import java.io.File import java.io.Serializable import java.util.* diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/NetworkUtils.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/NetworkUtils.kt index e69b597b851..946c5b25c93 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/NetworkUtils.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/NetworkUtils.kt @@ -73,25 +73,31 @@ object LoopbackNetworkInterface { override fun createServerSocket(port: Int): ServerSocket = ServerSocket(port, SERVER_SOCKET_BACKLOG_SIZE, InetAddress.getByName(null)) } - - class ClientLoopbackSocketFactory : RMIClientSocketFactory, Serializable { + abstract class AbstractClientLoopbackSocketFactory : Serializable { override fun equals(other: Any?): Boolean = other === this || super.equals(other) override fun hashCode(): Int = super.hashCode() + abstract protected fun socketCreate(host: String, port: Int): SocketType + @Throws(IOException::class) - override fun createSocket(host: String, port: Int): Socket { + fun createSocket(host: String, port: Int): SocketType { var attemptsLeft = SOCKET_CONNECT_ATTEMPTS while (true) { try { - return Socket(InetAddress.getByName(null), port) - } - catch (e: ConnectException) { + return socketCreate(host, port) + } catch (e: ConnectException) { if (--attemptsLeft <= 0) throw e } Thread.sleep(SOCKET_CONNECT_INTERVAL_MS) } } } + + + class ClientLoopbackSocketFactory : AbstractClientLoopbackSocketFactory(), RMIClientSocketFactory { + override fun socketCreate(host: String, port: Int): Socket = Socket(InetAddress.getByName(null), port) + } + } diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/PerfUtils.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/PerfUtils.kt index ef8791d0a2b..d8d3b6b855a 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/PerfUtils.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/PerfUtils.kt @@ -93,22 +93,22 @@ inline fun usedMemory(withGC: Boolean): Long { } -inline fun beginWithMeasureWallTime(perfCounters: PerfCounters) = listOf(System.nanoTime()) +inline fun beginMeasureWallTime() = listOf(System.nanoTime()) -inline fun endWithMeasureWallTime(perfCounters: PerfCounters, startState: List) { +inline fun endMeasureWallTime(perfCounters: PerfCounters, startState: List) { val (startTime) = startState perfCounters.addMeasurement(time = System.nanoTime() - startTime) // TODO: add support for time wrapping } -inline fun beginWithMeasureWallAndThreadTimes(perfCounters: PerfCounters, threadMXBean: ThreadMXBean): List { +inline fun beginMeasureWallAndThreadTimes(perfCounters: PerfCounters, threadMXBean: ThreadMXBean): List { val startTime = System.nanoTime() val startThreadTime = threadMXBean.threadCpuTime() val startThreadUserTime = threadMXBean.threadUserTime() return listOf(startTime, startThreadTime, startThreadUserTime) } -inline fun endWithMeasureWallAndThreadTimes(perfCounters: PerfCounters, threadMXBean: ThreadMXBean, startState: List) { +inline fun endMeasureWallAndThreadTimes(perfCounters: PerfCounters, threadMXBean: ThreadMXBean, startState: List) { val (startTime, startThreadTime, startThreadUserTime) = startState // TODO: add support for time wrapping @@ -117,12 +117,12 @@ inline fun endWithMeasureWallAndThreadTimes(perfCounters: PerfCounters, threadMX threadUser = threadMXBean.threadUserTime() - startThreadUserTime) } -inline fun beginWithMeasureWallAndThreadTimes(perfCounters: PerfCounters) = - beginWithMeasureWallAndThreadTimes(perfCounters, ManagementFactory.getThreadMXBean()) -inline fun endWithMeasureWallAndThreadTimes(perfCounters: PerfCounters, startState: List) = - endWithMeasureWallAndThreadTimes(perfCounters, ManagementFactory.getThreadMXBean(), startState) +inline fun beginMeasureWallAndThreadTimes(perfCounters: PerfCounters) = + beginMeasureWallAndThreadTimes(perfCounters, ManagementFactory.getThreadMXBean()) +inline fun endMeasureWallAndThreadTimes(perfCounters: PerfCounters, startState: List) = + endMeasureWallAndThreadTimes(perfCounters, ManagementFactory.getThreadMXBean(), startState) -inline fun beginWithMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean = false, threadMXBean: ThreadMXBean): List { +inline fun beginMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean = false, threadMXBean: ThreadMXBean): List { val startMem = usedMemory(withGC) val startTime = System.nanoTime() val startThreadTime = threadMXBean.threadCpuTime() @@ -131,7 +131,7 @@ inline fun beginWithMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounter return listOf(startMem, startTime, startThreadTime, startThreadUserTime) } -inline fun endWithMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean = false, threadMXBean: ThreadMXBean, startState: List){ +inline fun endMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean = false, threadMXBean: ThreadMXBean, startState: List){ val (startMem, startTime, startThreadTime, startThreadUserTime) = startState // TODO: add support for time wrapping @@ -141,11 +141,11 @@ inline fun endWithMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, memory = usedMemory(withGC) - startMem) } -inline fun beginWithMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean) = - beginWithMeasureWallAndThreadTimesAndMemory(perfCounters, withGC, ManagementFactory.getThreadMXBean()) +inline fun beginMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean) = + beginMeasureWallAndThreadTimesAndMemory(perfCounters, withGC, ManagementFactory.getThreadMXBean()) -inline fun endWithMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean, startState: List) = - endWithMeasureWallAndThreadTimesAndMemory(perfCounters, withGC, ManagementFactory.getThreadMXBean(), startState) +inline fun endMeasureWallAndThreadTimesAndMemory(perfCounters: PerfCounters, withGC: Boolean, startState: List) = + endMeasureWallAndThreadTimesAndMemory(perfCounters, withGC, ManagementFactory.getThreadMXBean(), startState) class DummyProfiler : Profiler { @@ -166,27 +166,27 @@ abstract class TotalProfiler : Profiler { class WallTotalProfiler : TotalProfiler() { @Suppress("OVERRIDE_BY_INLINE") - override inline fun beginMeasure(obj: Any?) = beginWithMeasureWallTime(total) + override inline fun beginMeasure(obj: Any?) = beginMeasureWallTime() @Suppress("OVERRIDE_BY_INLINE") - override inline fun endMeasure(obj: Any?, startState: List) = endWithMeasureWallTime(total, startState) + override inline fun endMeasure(obj: Any?, startState: List) = endMeasureWallTime(total, startState) } class WallAndThreadTotalProfiler : TotalProfiler() { @Suppress("OVERRIDE_BY_INLINE") - override inline fun beginMeasure(obj: Any?) = beginWithMeasureWallAndThreadTimes(total, threadMXBean) + override inline fun beginMeasure(obj: Any?) = beginMeasureWallAndThreadTimes(total, threadMXBean) @Suppress("OVERRIDE_BY_INLINE") - override inline fun endMeasure(obj: Any?, startState: List) = endWithMeasureWallAndThreadTimes(total, threadMXBean, startState) + override inline fun endMeasure(obj: Any?, startState: List) = endMeasureWallAndThreadTimes(total, threadMXBean, startState) } class WallAndThreadAndMemoryTotalProfiler(val withGC: Boolean) : TotalProfiler() { @Suppress("OVERRIDE_BY_INLINE") override inline fun beginMeasure(obj: Any?) = - beginWithMeasureWallAndThreadTimesAndMemory(total, withGC, threadMXBean) + beginMeasureWallAndThreadTimesAndMemory(total, withGC, threadMXBean) @Suppress("OVERRIDE_BY_INLINE") override inline fun endMeasure(obj: Any?, startState: List) = - endWithMeasureWallAndThreadTimesAndMemory(total, withGC, threadMXBean, startState) + endMeasureWallAndThreadTimesAndMemory(total, withGC, threadMXBean, startState) } @@ -198,8 +198,8 @@ class WallAndThreadByClassProfiler() : TotalProfiler() { @Suppress("OVERRIDE_BY_INLINE") override inline fun beginMeasure(obj: Any?) = - beginWithMeasureWallAndThreadTimes(counters.getOrPut(obj?.javaClass?.name, { SimplePerfCountersWithTotal(total) }), threadMXBean) + beginMeasureWallAndThreadTimes(counters.getOrPut(obj?.javaClass?.name, { SimplePerfCountersWithTotal(total) }), threadMXBean) @Suppress("OVERRIDE_BY_INLINE") override inline fun endMeasure(obj: Any?, startState: List) = - endWithMeasureWallAndThreadTimes(counters.getOrPut(obj?.javaClass?.name, { SimplePerfCountersWithTotal(total) }), threadMXBean, startState) + endMeasureWallAndThreadTimes(counters.getOrPut(obj?.javaClass?.name, { SimplePerfCountersWithTotal(total) }), threadMXBean, startState) } diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt index 68312737bd0..645687e38a3 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt @@ -41,10 +41,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler import org.jetbrains.kotlin.config.Services import org.jetbrains.kotlin.daemon.common.* -import org.jetbrains.kotlin.daemon.report.CompileServicesFacadeMessageCollector -import org.jetbrains.kotlin.daemon.report.DaemonMessageReporter -import org.jetbrains.kotlin.daemon.report.DaemonMessageReporterPrintStreamAdapter -import org.jetbrains.kotlin.daemon.report.getICReporter +import org.jetbrains.kotlin.daemon.report.* import org.jetbrains.kotlin.incremental.* import org.jetbrains.kotlin.incremental.components.ExpectActualTracker import org.jetbrains.kotlin.incremental.components.LookupTracker @@ -389,7 +386,6 @@ abstract class CompileServiceImplBase( val exitCode = checkedCompile(daemonMessageReporter, rpcProfiler) { body(eventManager, rpcProfiler).code } - log.fine("got exitCode") CompileService.CallResult.Good(exitCode) } finally { eventManager.fireCompilationFinished() @@ -413,7 +409,7 @@ abstract class CompileServiceImplBase( val endMem = if (daemonOptions.reportPerf) usedMemory(withGC = false) else 0L - log.info("Done with result " + res.toString()) + log.info("Done with result $res") if (daemonOptions.reportPerf) { val pc = profiler.getTotalCounters() @@ -467,10 +463,13 @@ abstract class CompileServiceImplBase( // ) // } - fun startDaemonLife() { + fun startDaemonElections() { timer.schedule(10) { exceptionLoggingTimerThread { initiateElections() } } + } + + fun configurePeriodicActivities() { timer.schedule(delay = DAEMON_PERIODIC_CHECK_INTERVAL_MS, period = DAEMON_PERIODIC_CHECK_INTERVAL_MS) { exceptionLoggingTimerThread { periodicAndAfterSessionCheck() } } @@ -516,21 +515,11 @@ abstract class CompileServiceImplBase( } } - protected inline fun withValidReplImpl( - sessionId: Int, - body: KotlinJvmReplServiceT.() -> R - ): CompileService.CallResult = - withValidClientOrSessionProxy(sessionId) { session -> - (session?.data as? KotlinJvmReplServiceT?)?.let { - CompileService.CallResult.Good(it.body()) - } ?: CompileService.CallResult.Error("Not a REPL session $sessionId") - } - protected fun execJsIncrementalCompiler( args: K2JSCompilerArguments, incrementalCompilationOptions: IncrementalCompilationOptions, compilerMessageCollector: MessageCollector, - reporter: ICReporter + reporter: RemoteICReporter ): ExitCode { val allKotlinFiles = arrayListOf() val freeArgsWithoutKotlinFiles = arrayListOf() @@ -561,7 +550,7 @@ abstract class CompileServiceImplBase( return try { compiler.compile(allKotlinFiles, args, compilerMessageCollector, changedFiles) } finally { - (reporter as RemoteICReporter).flush() + reporter.flush() } } @@ -569,18 +558,8 @@ abstract class CompileServiceImplBase( k2jvmArgs: K2JVMCompilerArguments, incrementalCompilationOptions: IncrementalCompilationOptions, compilerMessageCollector: MessageCollector, - reporter: ICReporter + reporter: RemoteICReporter ): ExitCode { - val moduleFile = k2jvmArgs.buildFile?.let(::File) - assert(moduleFile?.exists() ?: false) { "Module does not exist ${k2jvmArgs.buildFile}" } - - // todo: pass javaSourceRoots and allKotlinFiles using IncrementalCompilationOptions - val parsedModule = run { - val bytesOut = ByteArrayOutputStream() - val printStream = PrintStream(bytesOut) - val mc = PrintingMessageCollector(printStream, MessageRenderer.PLAIN_FULL_PATHS, false) - val parsedModule = ModuleXmlParser.parseModuleScript(k2jvmArgs.buildFile!!, mc) - parsedModule val allKotlinExtensions = (DEFAULT_KOTLIN_SOURCE_FILES_EXTENSIONS + (incrementalCompilationOptions.kotlinScriptExtensions ?: emptyArray())).distinct() val dotExtensions = allKotlinExtensions.map { ".$it" } @@ -614,27 +593,22 @@ abstract class CompileServiceImplBase( } } - val outputFiles = incrementalCompilationOptions.outputFiles.toMutableList() - incrementalCompilationOptions.classpathFqNamesHistory?.let { outputFiles.add(it) } - val compiler = IncrementalJvmCompilerRunner( workingDir, reporter, buildHistoryFile = incrementalCompilationOptions.multiModuleICSettings.buildHistoryFile, - outputFiles = outputFiles, + outputFiles = incrementalCompilationOptions.outputFiles, usePreciseJavaTracking = incrementalCompilationOptions.usePreciseJavaTracking, modulesApiHistory = modulesApiHistory, - kotlinSourceFilesExtensions = allKotlinExtensions, - classpathFqNamesHistory = incrementalCompilationOptions.classpathFqNamesHistory + kotlinSourceFilesExtensions = allKotlinExtensions ) return try { compiler.compile(allKotlinFiles, k2jvmArgs, compilerMessageCollector, changedFiles) } finally { - (reporter as RemoteICReporter).flush() + reporter.flush() } } - @JvmName("withValidReplImpl1") protected inline fun withValidReplImpl( sessionId: Int, body: KotlinJvmReplServiceT.() -> CompileService.CallResult @@ -838,7 +812,7 @@ class CompileServiceImpl( ) val messageCollector = KeepFirstErrorMessageCollector(compilerMessagesStream) val repl = KotlinJvmReplService( - disposable, port, templateClasspath, templateClassName, + disposable, port, compilerId, templateClasspath, templateClassName, messageCollector, operationsTracer ) val sessionId = state.sessions.leaseSession(ClientOrSessionProxy(aliveFlagPath, repl, disposable)) @@ -922,7 +896,7 @@ class CompileServiceImpl( val disposable = Disposer.newDisposable() val messageCollector = CompileServicesFacadeMessageCollector(servicesFacade, compilationOptions) val repl = KotlinJvmReplService( - disposable, port, templateClasspath, templateClassName, + disposable, port, compilerId, templateClasspath, templateClassName, messageCollector, null ) val sessionId = state.sessions.leaseSession(ClientOrSessionProxy(aliveFlagPath, repl, disposable)) diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinCompileDaemon.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinCompileDaemon.kt index de4295063f8..08f82468bb7 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinCompileDaemon.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinCompileDaemon.kt @@ -55,22 +55,21 @@ class LogStream(name: String) : OutputStream() { } } -object KotlinCompileDaemon { - +abstract class KotlinCompileDaemonBase { init { val logTime: String = SimpleDateFormat("yyyy-MM-dd.HH-mm-ss-SSS").format(Date()) val (logPath: String, fileIsGiven: Boolean) = System.getProperty(COMPILE_DAEMON_LOG_PATH_PROPERTY)?.trimQuotes()?.let { Pair(it, File(it).isFile) } ?: Pair("%t", false) val cfg: String = - "handlers = java.util.logging.FileHandler\n" + - "java.util.logging.FileHandler.level = ALL\n" + - "java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter\n" + - "java.util.logging.FileHandler.encoding = UTF-8\n" + - "java.util.logging.FileHandler.limit = ${if (fileIsGiven) 0 else (1 shl 20)}\n" + // if file is provided - disabled, else - 1Mb - "java.util.logging.FileHandler.count = ${if (fileIsGiven) 1 else 3}\n" + - "java.util.logging.FileHandler.append = $fileIsGiven\n" + - "java.util.logging.FileHandler.pattern = ${if (fileIsGiven) logPath else (logPath + File.separator + "$COMPILE_DAEMON_DEFAULT_FILES_PREFIX.$logTime.%u%g.log")}\n" + - "java.util.logging.SimpleFormatter.format = %1\$tF %1\$tT.%1\$tL [%3\$s] %4\$s: %5\$s%n\n" + "handlers = java.util.logging.FileHandler\n" + + "java.util.logging.FileHandler.level = ALL\n" + + "java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter\n" + + "java.util.logging.FileHandler.encoding = UTF-8\n" + + "java.util.logging.FileHandler.limit = ${if (fileIsGiven) 0 else (1 shl 20)}\n" + // if file is provided - disabled, else - 1Mb + "java.util.logging.FileHandler.count = ${if (fileIsGiven) 1 else 3}\n" + + "java.util.logging.FileHandler.append = $fileIsGiven\n" + + "java.util.logging.FileHandler.pattern = ${if (fileIsGiven) logPath else (logPath + File.separator + "$COMPILE_DAEMON_DEFAULT_FILES_PREFIX.$logTime.%u%g.log")}\n" + + "java.util.logging.SimpleFormatter.format = %1\$tF %1\$tT.%1\$tL [%3\$s] %4\$s: %5\$s%n\n" LogManager.getLogManager().readConfiguration(cfg.byteInputStream()) } @@ -78,19 +77,32 @@ object KotlinCompileDaemon { val log by lazy { Logger.getLogger("daemon") } private fun loadVersionFromResource(): String? { - (KotlinCompileDaemon::class.java.classLoader as? URLClassLoader) - ?.findResource("META-INF/MANIFEST.MF") - ?.let { - try { - return Manifest(it.openStream()).mainAttributes.getValue("Implementation-Version") ?: null - } - catch (e: IOException) {} + (KotlinCompileDaemonBase::class.java.classLoader as? URLClassLoader) + ?.findResource("META-INF/MANIFEST.MF") + ?.let { + try { + return Manifest(it.openStream()).mainAttributes.getValue("Implementation-Version") ?: null } + catch (e: IOException) {} + } return null } - @JvmStatic - fun main(args: Array) { + protected open fun runSynchronized(block: () -> T) = block() + + protected abstract fun getCompileServiceAndPort( + compilerSelector: CompilerSelector, + compilerId: CompilerId, + daemonOptions: DaemonOptions, + daemonJVMOptions: DaemonJVMOptions, + timer: Timer + ) : Pair + + protected open fun runCompileService(compileService: CompileServiceImplBase) : Any? = null + + protected open fun awaitServerRun(serverRun: Any?) {} + + protected fun mainImpl(args: Array) { ensureServerHostnameIsSetUp() val jvmArguments = ManagementFactory.getRuntimeMXBean().inputArguments @@ -103,84 +115,107 @@ object KotlinCompileDaemon { val compilerId = CompilerId() val daemonOptions = DaemonOptions() + runSynchronized { + var serverRun: Any? + try { + val daemonJVMOptions = configureDaemonJVMOptions(inheritMemoryLimits = true, + inheritOtherJvmOptions = true, + inheritAdditionalProperties = true) - try { - val daemonJVMOptions = configureDaemonJVMOptions(inheritMemoryLimits = true, - inheritOtherJvmOptions = true, - inheritAdditionalProperties = true) + val filteredArgs = args.asIterable().filterExtractProps(compilerId, daemonOptions, prefix = COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) - val filteredArgs = args.asIterable().filterExtractProps(compilerId, daemonOptions, prefix = COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX) - - if (filteredArgs.any()) { - val helpLine = "usage: " - log.info(helpLine) - println(helpLine) - throw IllegalArgumentException("Unknown arguments: " + filteredArgs.joinToString(" ")) - } - - log.info("starting daemon") - - // TODO: find minimal set of permissions and restore security management - // note: may be not needed anymore since (hopefully) server is now loopback-only - // if (System.getSecurityManager() == null) - // System.setSecurityManager (RMISecurityManager()) - // - // setDaemonPermissions(daemonOptions.port) - - val (registry, port) = findPortAndCreateRegistry(COMPILE_DAEMON_FIND_PORT_ATTEMPTS, COMPILE_DAEMON_PORTS_RANGE_START, COMPILE_DAEMON_PORTS_RANGE_END) - - val compilerSelector = object : CompilerSelector { - private val jvm by lazy { K2JVMCompiler() } - private val js by lazy { K2JSCompiler() } - private val metadata by lazy { K2MetadataCompiler() } - override fun get(targetPlatform: CompileService.TargetPlatform): CLICompiler<*> = when (targetPlatform) { - CompileService.TargetPlatform.JVM -> jvm - CompileService.TargetPlatform.JS -> js - CompileService.TargetPlatform.METADATA -> metadata + if (filteredArgs.any()) { + val helpLine = "usage: " + log.info(helpLine) + println(helpLine) + throw IllegalArgumentException("Unknown arguments: " + filteredArgs.joinToString(" ")) } + + log.info("starting daemon") + + // TODO: find minimal set of permissions and restore security management + // note: may be not needed anymore since (hopefully) server is now loopback-only + // if (System.getSecurityManager() == null) + // System.setSecurityManager (RMISecurityManager()) + // + // setDaemonPermissions(daemonOptions.port) + + val compilerSelector = object : CompilerSelector { + private val jvm by lazy { K2JVMCompiler() } + private val js by lazy { K2JSCompiler() } + private val metadata by lazy { K2MetadataCompiler() } + override fun get(targetPlatform: CompileService.TargetPlatform): CLICompiler<*> = when (targetPlatform) { + CompileService.TargetPlatform.JVM -> jvm + CompileService.TargetPlatform.JS -> js + CompileService.TargetPlatform.METADATA -> metadata + } + } + // timer with a daemon thread, meaning it should not prevent JVM to exit normally + val timer = Timer(true) + val (compilerService, port) = getCompileServiceAndPort(compilerSelector, compilerId, daemonOptions, daemonJVMOptions, timer) + compilerService.startDaemonElections() + compilerService.configurePeriodicActivities() + serverRun = runCompileService(compilerService) + + println(COMPILE_DAEMON_IS_READY_MESSAGE) + log.info("daemon is listening on port: $port") + + // this supposed to stop redirected streams reader(s) on the client side and prevent some situations with hanging threads, but doesn't work reliably + // TODO: implement more reliable scheme + System.out.close() + System.err.close() + + System.setErr(PrintStream(LogStream("stderr"))) + System.setOut(PrintStream(LogStream("stdout"))) } - // timer with a daemon thread, meaning it should not prevent JVM to exit normally - val timer = Timer(true) - val compilerService = CompileServiceImpl(registry = registry, - compiler = compilerSelector, - compilerId = compilerId, - daemonOptions = daemonOptions, - daemonJVMOptions = daemonJVMOptions, - port = port, - timer = timer, - onShutdown = { - if (daemonOptions.forceShutdownTimeoutMilliseconds != COMPILE_DAEMON_TIMEOUT_INFINITE_MS) { - // running a watcher thread that ensures that if the daemon is not exited normally (may be due to RMI leftovers), it's forced to exit - timer.schedule(daemonOptions.forceShutdownTimeoutMilliseconds) { - cancel() - log.info("force JVM shutdown") - exitProcess(0) - } - } - else { - timer.cancel() - } - }) - compilerService.startDaemonLife() - - println(COMPILE_DAEMON_IS_READY_MESSAGE) - log.info("daemon is listening on port: $port") - - // this supposed to stop redirected streams reader(s) on the client side and prevent some situations with hanging threads, but doesn't work reliably - // TODO: implement more reliable scheme - System.out.close() - System.err.close() - - System.setErr(PrintStream(LogStream("stderr"))) - System.setOut(PrintStream(LogStream("stdout"))) - } - catch (e: Exception) { - System.err.println("Exception: " + e.message) - e.printStackTrace(System.err) - // repeating it to log for the cases when stderr is not redirected yet - log.log(Level.INFO, "Exception: ", e) - // TODO consider exiting without throwing - throw e + catch (e: Exception) { + System.err.println("Exception: " + e.message) + e.printStackTrace(System.err) + // repeating it to log for the cases when stderr is not redirected yet + log.log(Level.INFO, "Exception: ", e) + // TODO consider exiting without throwing + throw e + } + awaitServerRun(serverRun) } } +} + +object KotlinCompileDaemon : KotlinCompileDaemonBase() { + + @JvmStatic + fun main(args: Array) { + mainImpl(args) + } + + override fun getCompileServiceAndPort( + compilerSelector: CompilerSelector, + compilerId: CompilerId, + daemonOptions: DaemonOptions, + daemonJVMOptions: DaemonJVMOptions, + timer: Timer + ) = run { + val (registry, port) = findPortAndCreateRegistry(COMPILE_DAEMON_FIND_PORT_ATTEMPTS, COMPILE_DAEMON_PORTS_RANGE_START, COMPILE_DAEMON_PORTS_RANGE_END) + val compilerService = CompileServiceImpl(registry = registry, + compiler = compilerSelector, + compilerId = compilerId, + daemonOptions = daemonOptions, + daemonJVMOptions = daemonJVMOptions, + port = port, + timer = timer, + onShutdown = { + if (daemonOptions.forceShutdownTimeoutMilliseconds != COMPILE_DAEMON_TIMEOUT_INFINITE_MS) { + // running a watcher thread that ensures that if the daemon is not exited normally (may be due to RMI leftovers), it's forced to exit + timer.schedule(daemonOptions.forceShutdownTimeoutMilliseconds) { + cancel() + log.info("force JVM shutdown") + exitProcess(0) + } + } + else { + timer.cancel() + } + }) + Pair(compilerService, port) + } } \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt index 7859c6fbdee..600565c7784 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt @@ -42,7 +42,8 @@ import kotlin.concurrent.write abstract class KotlinJvmReplServiceBase( disposable: Disposable, - val compilerId: CompilerId,templateClasspath: List, + val compilerId: CompilerId, + templateClasspath: List, templateClassName: String, protected val messageCollector: MessageCollector ) : ReplCompileAction, ReplCheckAction, CreateReplStageStateAction { @@ -60,27 +61,6 @@ abstract class KotlinJvmReplServiceBase( configureScripting(compilerId) } - protected fun makeScriptDefinition(templateClasspath: List, templateClassName: String): KotlinScriptDefinition? { - val classloader = URLClassLoader(templateClasspath.map { it.toURI().toURL() }.toTypedArray(), this::class.java.classLoader) - - try { - val cls = classloader.loadClass(templateClassName) - val def = KotlinScriptDefinitionFromAnnotatedTemplate(cls.kotlin, emptyMap()) - messageCollector.report(INFO, "New script definition $templateClassName: files pattern = \"${def.scriptFilePattern}\", " + - "resolver = ${def.dependencyResolver.javaClass.name}") - return def - } - catch (ex: ClassNotFoundException) { - messageCollector.report(ERROR, "Cannot find script definition template class $templateClassName") - } - catch (ex: Exception) { - messageCollector.report(ERROR, "Error processing script definition template $templateClassName: ${ex.message}") - } - return null - } - - private val scriptDef = makeScriptDefinition(templateClasspath, templateClassName) - protected val replCompiler: ReplCompiler? by lazy { try { val projectEnvironment = @@ -142,12 +122,13 @@ abstract class KotlinJvmReplServiceBase( open class KotlinJvmReplService( disposable: Disposable, val portForServers: Int, + compilerId: CompilerId, templateClasspath: List, templateClassName: String, messageCollector: MessageCollector, @Deprecated("drop it") protected val operationsTracer: RemoteOperationsTracer? -) : KotlinJvmReplServiceBase(disposable, templateClasspath, templateClassName, messageCollector) { +) : KotlinJvmReplServiceBase(disposable, compilerId, templateClasspath, templateClassName, messageCollector) { override fun before(s: String) { operationsTracer?.before(s) diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/CompileServiceServerSideImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/CompileServiceServerSideImpl.kt index 235c316fbb6..cfdbfc8f78d 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/CompileServiceServerSideImpl.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/CompileServiceServerSideImpl.kt @@ -331,10 +331,12 @@ class CompileServiceServerSideImpl( compilationOptions, servicesFacade, compilationResults, - hasIncrementalCaches = CompilerCallbackServicesFacadeClientSide::hasIncrementalCaches, + hasIncrementalCaches = { hasIncrementalCaches() }, createMessageCollector = ::CompileServicesFacadeMessageCollector, createReporter = ::DaemonMessageReporterAsync, - createServices = this::createCompileServices, + createServices = { facade: CompilerCallbackServicesFacadeClientSide, eventMgr, profiler -> + createCompileServices(facade, eventMgr, profiler) + }, getICReporter = ::getICReporterAsync ) @@ -353,7 +355,7 @@ class CompileServiceServerSideImpl( val messageCollector = CompileServicesFacadeMessageCollector(servicesFacade, compilationOptions) val repl = KotlinJvmReplServiceAsync( - disposable, serverSocketWithPort, templateClasspath, templateClassName, + disposable, serverSocketWithPort, compilerId, templateClasspath, templateClassName, messageCollector ) val sessionId = state.sessions.leaseSession(ClientOrSessionProxy(aliveFlagPath, repl, disposable)) @@ -407,7 +409,7 @@ class CompileServiceServerSideImpl( System.setProperty(KOTLIN_COMPILER_ENVIRONMENT_KEEPALIVE_PROPERTY, "true") // TODO UNCOMMENT THIS : this.toRMIServer(daemonOptions, compilerId) // also create RMI server in order to support old clients - rmiServer = this.toRMIServer(daemonOptions, compilerId) +// rmiServer = this.toRMIServer(daemonOptions, compilerId) KeepAliveServer.runServer() } diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/KotlinCompileDaemon.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/KotlinCompileDaemon.kt index 0f467d991ac..5d398980992 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/KotlinCompileDaemon.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/KotlinCompileDaemon.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.cli.common.environment.setIdeaIoUseFallback import org.jetbrains.kotlin.cli.js.K2JSCompiler import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler import org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler +import org.jetbrains.kotlin.daemon.CompileServiceImplBase import org.jetbrains.kotlin.daemon.CompilerSelector import org.jetbrains.kotlin.daemon.common.* import org.jetbrains.kotlin.daemon.common.experimental.findPortForSocket @@ -29,174 +30,54 @@ import java.util.logging.Level import java.util.logging.LogManager import java.util.logging.Logger import kotlin.concurrent.schedule +import org.jetbrains.kotlin.daemon.KotlinCompileDaemonBase +import org.jetbrains.kotlin.daemon.common.experimental.CompileServiceServerSide +object KotlinCompileDaemon : KotlinCompileDaemonBase() { + override fun runSynchronized(block: () -> T) = runBlocking { block() } -class LogStream(name: String) : OutputStream() { - - val log by lazy { Logger.getLogger(name) } - - val lineBuf = StringBuilder() - - override fun write(byte: Int) { - if (byte.toChar() == '\n') flush() - else lineBuf.append(byte.toChar()) - } - - override fun flush() { - log.info(lineBuf.toString()) - lineBuf.setLength(0) - } -} - -object KotlinCompileDaemon { - - init { - - val logTime: String = SimpleDateFormat("yyyy-MM-dd.HH-mm-ss-SSS").format(Date()) - val (logPath: String, fileIsGiven: Boolean) = - System.getProperty(COMPILE_DAEMON_LOG_PATH_PROPERTY)?.trimQuotes()?.let { Pair(it, File(it).isFile) } ?: Pair("%t", false) - val cfg: String = - "handlers = java.util.logging.FileHandler\n" + - "java.util.logging.FileHandler.level = ALL\n" + - "java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter\n" + - "java.util.logging.FileHandler.encoding = UTF-8\n" + - "java.util.logging.FileHandler.limit = ${if (fileIsGiven) 0 else (1 shl 20)}\n" + // if file is provided - disabled, else - 1Mb - "java.util.logging.FileHandler.count = ${if (fileIsGiven) 1 else 3}\n" + - "java.util.logging.FileHandler.append = $fileIsGiven\n" + - "java.util.logging.FileHandler.pattern = ${if (fileIsGiven) logPath else (logPath + File.separator + "$COMPILE_DAEMON_DEFAULT_FILES_PREFIX.$logTime.%u%g.log")}\n" + - "java.util.logging.SimpleFormatter.format = %1\$tF %1\$tT.%1\$tL [%3\$s] %4\$s: %5\$s%n\n" - - LogManager.getLogManager().readConfiguration(cfg.byteInputStream()) - } - - val log by lazy { Logger.getLogger("daemon") } - - private fun loadVersionFromResource(): String? { - (KotlinCompileDaemon::class.java.classLoader as? URLClassLoader) - ?.findResource("META-INF/MANIFEST.MF") - ?.let { - try { - return Manifest(it.openStream()).mainAttributes.getValue("Implementation-Version") ?: null - } catch (e: IOException) { + override fun getCompileServiceAndPort( + compilerSelector: CompilerSelector, + compilerId: CompilerId, + daemonOptions: DaemonOptions, + daemonJVMOptions: DaemonJVMOptions, + timer: Timer + ) = run { + val port = findPortForSocket( + COMPILE_DAEMON_FIND_PORT_ATTEMPTS, + COMPILE_DAEMON_PORTS_RANGE_START, + COMPILE_DAEMON_PORTS_RANGE_END + ) + val compilerService = CompileServiceServerSideImpl( + port, + compilerSelector, + compilerId, + daemonOptions, + daemonJVMOptions, + port.port, + timer, + { + if (daemonOptions.forceShutdownTimeoutMilliseconds != COMPILE_DAEMON_TIMEOUT_INFINITE_MS) { + // running a watcher thread that ensures that if the daemon is not exited normally (may be due to RMI leftovers), it's forced to exit + timer.schedule(daemonOptions.forceShutdownTimeoutMilliseconds) { + cancel() + log.info("force JVM shutdown") + System.exit(0) + } + } else { + timer.cancel() } - } - return null + }) + Pair(compilerService, port.port) + } + + override fun runCompileService(compileService: CompileServiceImplBase) = (compileService as CompileServiceServerSide).runServer() + override fun awaitServerRun(serverRun: Any?) { + runBlocking { (serverRun as Deferred?)?.await() } } @JvmStatic fun main(args: Array) { - ensureServerHostnameIsSetUp() - - val jvmArguments = ManagementFactory.getRuntimeMXBean().inputArguments - - log.info("Kotlin compiler daemon version " + (loadVersionFromResource() ?: "")) - log.info("daemon JVM args: " + jvmArguments.joinToString(" ")) - log.info("daemon args: " + args.joinToString(" ")) - - setIdeaIoUseFallback() - - val compilerId = CompilerId() - val daemonOptions = DaemonOptions() - - runBlocking { - - var serverRun: Deferred? - - try { - val daemonJVMOptions = configureDaemonJVMOptions( - inheritMemoryLimits = true, - inheritOtherJvmOptions = true, - inheritAdditionalProperties = true - ) - - val filteredArgs = args.asIterable() - .filterExtractProps( - compilerId, - daemonOptions, - prefix = COMPILE_DAEMON_CMDLINE_OPTIONS_PREFIX - ) - - if (filteredArgs.any()) { - val helpLine = "usage: " - - log.info(helpLine) - println(helpLine) - throw IllegalArgumentException("Unknown arguments: " + filteredArgs.joinToString(" ")) - } - - log.info("starting daemon") - - // TODO: find minimal set of permissions and restore security management - // note: may be not needed anymore since (hopefully) server is now loopback-only - // if (System.getSecurityManager() == null) - // System.setSecurityManager (RMISecurityManager()) - // - // setDaemonPermissions(daemonOptions.socketPort) - - val port = findPortForSocket( - COMPILE_DAEMON_FIND_PORT_ATTEMPTS, - COMPILE_DAEMON_PORTS_RANGE_START, - COMPILE_DAEMON_PORTS_RANGE_END - ) - - - val compilerSelector = object : CompilerSelector { - private val jvm by lazy { K2JVMCompiler() } - private val js by lazy { K2JSCompiler() } - private val metadata by lazy { K2MetadataCompiler() } - override fun get(targetPlatform: CompileService.TargetPlatform): CLICompiler<*> = when (targetPlatform) { - CompileService.TargetPlatform.JVM -> jvm - CompileService.TargetPlatform.JS -> js - CompileService.TargetPlatform.METADATA -> metadata - } - } - - // timer with a daemon thread, meaning it should not prevent JVM to exit normally - val timer = Timer(true) - val compilerService = CompileServiceServerSideImpl( - port, - compilerSelector, - compilerId, - daemonOptions, - daemonJVMOptions, - port.port, - timer, - { - if (daemonOptions.forceShutdownTimeoutMilliseconds != COMPILE_DAEMON_TIMEOUT_INFINITE_MS) { - // running a watcher thread that ensures that if the daemon is not exited normally (may be due to RMI leftovers), it's forced to exit - timer.schedule(daemonOptions.forceShutdownTimeoutMilliseconds) { - cancel() - log.info("force JVM shutdown") - System.exit(0) - } - } else { - timer.cancel() - } - }) - compilerService.startDaemonLife() - serverRun = compilerService.runServer() - - - println(COMPILE_DAEMON_IS_READY_MESSAGE) - log.info("daemon is listening on port: ${port.port}") - - // this supposed to stop redirected streams reader(s) on the client side and prevent some situations with hanging threads, but doesn't work reliably - // TODO: implement more reliable scheme - System.out.close() - System.err.close() - - System.setErr(PrintStream(LogStream("stderr"))) - System.setOut(PrintStream(LogStream("stdout"))) - } catch (e: Exception) { - log.log(Level.ALL, "Exception: " + e.message) - e.printStackTrace(System.err) - // repeating it to log for the cases when stderr is not redirected yet - log.log(Level.INFO, "Exception: ", e) - // TODO consider exiting without throwing - throw e - } - serverRun.await() - } + mainImpl(args) } - } \ No newline at end of file diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/KotlinRemoteReplService.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/KotlinRemoteReplService.kt index 4d5cbfe4927..f30e3ddbb24 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/KotlinRemoteReplService.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/KotlinRemoteReplService.kt @@ -8,9 +8,9 @@ package org.jetbrains.kotlin.daemon.experimental import com.intellij.openapi.Disposable import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.cli.common.repl.IReplStageState -import org.jetbrains.kotlin.cli.jvm.repl.GenericReplCompilerState import org.jetbrains.kotlin.daemon.KotlinJvmReplServiceBase import org.jetbrains.kotlin.daemon.common.CompileService +import org.jetbrains.kotlin.daemon.common.CompilerId import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.ServerSocketWrapper import org.jetbrains.kotlin.daemon.getValidId import java.io.File @@ -21,20 +21,17 @@ import kotlin.concurrent.write open class KotlinJvmReplServiceAsync( disposable: Disposable, val portForServers: ServerSocketWrapper, + compilerId: CompilerId, templateClasspath: List, templateClassName: String, messageCollector: MessageCollector -) : KotlinJvmReplServiceBase(disposable, templateClasspath, templateClassName, messageCollector) { +) : KotlinJvmReplServiceBase(disposable, compilerId, templateClasspath, templateClassName, messageCollector) { protected val states = WeakHashMap() // used as (missing) WeakHashSet suspend fun createRemoteState(port: ServerSocketWrapper = portForServers): RemoteReplStateFacadeServerSide = statesLock.write { val id = getValidId(stateIdCounter) { id -> states.none { it.key.getId() == id } } - val stateFacade = RemoteReplStateFacadeServerSide( - id, - createState().asState(GenericReplCompilerState::class.java), - port - ) + val stateFacade = RemoteReplStateFacadeServerSide(id, createState(), port) stateFacade.runServer() states.put(stateFacade, true) stateFacade diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/RemoteOutputStreamClient.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/RemoteOutputStreamClient.kt deleted file mode 100644 index a2944a1efe6..00000000000 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/RemoteOutputStreamClient.kt +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.daemon.experimental - -import kotlinx.coroutines.runBlocking -import org.jetbrains.kotlin.daemon.common.experimental.RemoteOutputStreamAsyncClientSide -import org.jetbrains.kotlin.daemon.common.DummyProfiler -import org.jetbrains.kotlin.daemon.common.Profiler -import org.jetbrains.kotlin.daemon.common.withMeasure -import java.io.OutputStream - -class RemoteOutputStreamClient(val remote: RemoteOutputStreamAsyncClientSide, val profiler: Profiler = DummyProfiler()) : OutputStream() { - override fun write(data: ByteArray) = runBlocking { - profiler.withMeasure(this) { remote.write(data, 0, data.size) } - } - - override fun write(data: ByteArray, offset: Int, length: Int) = runBlocking { - profiler.withMeasure(this) { remote.write(data, offset, length) } - } - - override fun write(byte: Int) = runBlocking { - profiler.withMeasure(this) { remote.write(byte) } - } -} diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/RemoteReplStateFacadeImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/RemoteReplStateFacadeImpl.kt index cd3baae7538..dd7e8e16069 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/RemoteReplStateFacadeImpl.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/experimental/RemoteReplStateFacadeImpl.kt @@ -7,7 +7,7 @@ package org.jetbrains.kotlin.daemon.experimental import io.ktor.network.sockets.Socket import org.jetbrains.kotlin.cli.common.repl.ILineId -import org.jetbrains.kotlin.cli.jvm.repl.GenericReplCompilerState +import org.jetbrains.kotlin.cli.common.repl.IReplStageState import org.jetbrains.kotlin.daemon.common.COMPILE_DAEMON_FIND_PORT_ATTEMPTS import org.jetbrains.kotlin.daemon.common.experimental.* import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.* @@ -15,7 +15,7 @@ import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.* @Suppress("UNCHECKED_CAST") class RemoteReplStateFacadeServerSide( val _id: Int, - val state: GenericReplCompilerState, + val state: IReplStageState<*>, override val serverSocketWithPort: ServerSocketWrapper = findPortForSocket( COMPILE_DAEMON_FIND_PORT_ATTEMPTS, REPL_SERVER_PORTS_RANGE_START, diff --git a/compiler/incremental-compilation-impl/build.gradle.kts b/compiler/incremental-compilation-impl/build.gradle.kts index e35840fdf29..c46b7bb6f8b 100644 --- a/compiler/incremental-compilation-impl/build.gradle.kts +++ b/compiler/incremental-compilation-impl/build.gradle.kts @@ -14,7 +14,7 @@ dependencies { compile(project(":compiler:cli")) compile(project(":compiler:cli-js")) compile(project(":kotlin-build-common")) - compile(project(":compiler:daemon-common")) + compile(project(":daemon-common")) compileOnly(intellijCoreDep()) { includeJars("intellij-core") } testCompile(commonDep("junit:junit")) diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/multiproject/ModulesApiHistory.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/multiproject/ModulesApiHistory.kt index 8b3bf7b119c..bee7467d76f 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/multiproject/ModulesApiHistory.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/multiproject/ModulesApiHistory.kt @@ -5,8 +5,8 @@ package org.jetbrains.kotlin.incremental.multiproject -import org.jetbrains.kotlin.daemon.common.IncrementalModuleEntry -import org.jetbrains.kotlin.daemon.common.IncrementalModuleInfo +import org.jetbrains.kotlin.incremental.IncrementalModuleEntry +import org.jetbrains.kotlin.incremental.IncrementalModuleInfo import org.jetbrains.kotlin.incremental.util.Either import java.io.File import java.nio.file.Path diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/multiproject/ModulesApiHistoryAndroidTest.kt b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/multiproject/ModulesApiHistoryAndroidTest.kt index bf6d555c16c..bb3ec09aacc 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/multiproject/ModulesApiHistoryAndroidTest.kt +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/multiproject/ModulesApiHistoryAndroidTest.kt @@ -5,8 +5,8 @@ package org.jetbrains.kotlin.incremental.multiproject -import org.jetbrains.kotlin.daemon.common.IncrementalModuleEntry -import org.jetbrains.kotlin.daemon.common.IncrementalModuleInfo +import org.jetbrains.kotlin.incremental.IncrementalModuleEntry +import org.jetbrains.kotlin.incremental.IncrementalModuleInfo import org.jetbrains.kotlin.incremental.util.Either import org.junit.Before import org.junit.Rule diff --git a/compiler/tests-common/build.gradle.kts b/compiler/tests-common/build.gradle.kts index 02ce517fb90..cc3c5540a70 100644 --- a/compiler/tests-common/build.gradle.kts +++ b/compiler/tests-common/build.gradle.kts @@ -26,8 +26,8 @@ dependencies { testCompile(project(":compiler:light-classes")) testCompile(project(":compiler:serialization")) testCompile(project(":kotlin-preloader")) - testCompile(project(":compiler:daemon-common")) - testCompile(project(":compiler:daemon-common-new")) + testCompile(project(":daemon-common")) + testCompile(project(":daemon-common-new")) testCompile(project(":js:js.serializer")) testCompile(project(":js:js.frontend")) testCompile(project(":js:js.translator")) diff --git a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerApiTest.kt b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerApiTest.kt index 67f1cc6fb89..3d74f89678d 100644 --- a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerApiTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerApiTest.kt @@ -40,7 +40,9 @@ class CompilerApiTest : KotlinIntegrationTestBase() { private val compilerLibDir = getCompilerLib() val compilerClassPath = listOf( - File(compilerLibDir, "kotlin-compiler.jar")) + File(compilerLibDir, "kotlin-compiler.jar"), + File(compilerLibDir, "kotlin-daemon.jar") + ) val compilerId by lazy(LazyThreadSafetyMode.NONE) { CompilerId.makeCompilerId(compilerClassPath) } private fun compileLocally(messageCollector: TestMessageCollector, vararg args: String): Pair> { diff --git a/compiler/tests/org/jetbrains/kotlin/daemon/experimental/integration/CompilerApiTest.kt b/compiler/tests/org/jetbrains/kotlin/daemon/experimental/integration/CompilerApiTest.kt index 2c8e30417e9..378f4b4d446 100644 --- a/compiler/tests/org/jetbrains/kotlin/daemon/experimental/integration/CompilerApiTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/daemon/experimental/integration/CompilerApiTest.kt @@ -36,7 +36,7 @@ private val logFiles = arrayListOf() class CompilerApiTest : KotlinIntegrationTestBase() { val kotlinCompilerClient = KotlinCompilerDaemonClient - .instantiate(DaemonProtocolVariant.RMI) // TODO(SOCKETS) + .instantiate(DaemonProtocolVariant.SOCKETS) // TODO(SOCKETS) private val compilerLibDir = getCompilerLib() @@ -72,7 +72,9 @@ class CompilerApiTest : KotlinIntegrationTestBase() { } val compilerClassPath = listOf( - File(compilerLibDir, "kotlin-compiler.jar") + File(compilerLibDir, "kotlin-compiler.jar"), + File(compilerLibDir, "kotlin-daemon.jar"), + File(compilerLibDir, "ktor-network-1.0.1.jar") ) val scriptRuntimeClassPath = listOf( File(compilerLibDir, "kotlin-runtime.jar"), diff --git a/compiler/tests/org/jetbrains/kotlin/daemon/experimental/integration/CompilerDaemonTest.kt b/compiler/tests/org/jetbrains/kotlin/daemon/experimental/integration/CompilerDaemonTest.kt index 34c8afab97a..03ecc4b61d5 100644 --- a/compiler/tests/org/jetbrains/kotlin/daemon/experimental/integration/CompilerDaemonTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/daemon/experimental/integration/CompilerDaemonTest.kt @@ -50,7 +50,7 @@ import kotlin.script.templates.ScriptTemplateDefinition import kotlin.test.fail import org.jetbrains.kotlin.daemon.client.experimental.* import org.jetbrains.kotlin.daemon.common.experimental.* -import org.jetbrains.kotlin.daemon.common.experimental.LoopbackNetworkInterface +import org.jetbrains.kotlin.utils.KotlinPaths val TIMEOUT_DAEMON_RUNNER_EXIT_MS = 10000L @@ -84,9 +84,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { data class CompilerResults(val resultCode: Int, val out: String) - val compilerClassPath = listOf( - File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-compiler.jar") - ) + val compilerClassPath = getKotlinPaths().classPath(KotlinPaths.ClassPaths.Compiler) val scriptingCompilerClassPath = listOf( File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-scripting-compiler.jar"), @@ -96,7 +94,8 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { val daemonClientClassPath = listOf( File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-daemon-client-new.jar"), - File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-compiler.jar") + File(KotlinIntegrationTestBase.getCompilerLib(), "kotlin-compiler.jar"), + File(KotlinIntegrationTestBase.getCompilerLib(), "ktor-network-1.0.1.jar") ) val compilerId by lazy(LazyThreadSafetyMode.NONE) { CompilerId.makeCompilerId(compilerClassPath) } @@ -156,7 +155,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { private fun run(logName: String, vararg args: String): Int = runJava(getTestBaseDir(), logName, *args) - fun makeTestDaemonOptions(testName: String, shutdownDelay: Int = 5) = + fun makeTestDaemonOptions(testName: String, shutdownDelay: Int = 5000) = DaemonOptions( runFilesPath = File(tmpdir, testName).absolutePath, shutdownDelayMilliseconds = shutdownDelay.toLong(), @@ -1306,7 +1305,10 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { port = serverPort, timer = timer, onShutdown = onShutdown - ).startDaemonLife() + ).let { + it.startDaemonElections() + it.configurePeriodicActivities() + } println("old daemon init: port = $serverPort") } } diff --git a/compiler/tests/org/jetbrains/kotlin/daemon/experimental/unit/ClientSerializationTest.kt b/compiler/tests/org/jetbrains/kotlin/daemon/experimental/unit/ClientSerializationTest.kt index e7f51db1314..730d86daa82 100644 --- a/compiler/tests/org/jetbrains/kotlin/daemon/experimental/unit/ClientSerializationTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/daemon/experimental/unit/ClientSerializationTest.kt @@ -10,7 +10,7 @@ import io.ktor.network.selector.SelectorManager import io.ktor.network.sockets.aSocket import kotlinx.coroutines.* import org.jetbrains.kotlin.daemon.common.experimental.CompilerServicesFacadeBaseClientSideImpl -import org.jetbrains.kotlin.daemon.common.experimental.LoopbackNetworkInterface.selectorMgr +import org.jetbrains.kotlin.daemon.common.experimental.LoopbackNetworkInterfaceKtor.selectorMgr import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.DefaultClient import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.ServerBase import org.jetbrains.kotlin.daemon.common.experimental.socketInfrastructure.openIO diff --git a/compiler/tests/org/jetbrains/kotlin/daemon/experimental/unit/ConnectionsTest.kt b/compiler/tests/org/jetbrains/kotlin/daemon/experimental/unit/ConnectionsTest.kt index eb1d62711a4..1fd6cbf3b61 100644 --- a/compiler/tests/org/jetbrains/kotlin/daemon/experimental/unit/ConnectionsTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/daemon/experimental/unit/ConnectionsTest.kt @@ -139,7 +139,8 @@ class ConnectionsTest : KotlinIntegrationTestBase() { onShutdown ).let { log.info("service created") - it.startDaemonLife() + it.startDaemonElections() + it.configurePeriodicActivities() it.runServer() } } @@ -170,7 +171,10 @@ class ConnectionsTest : KotlinIntegrationTestBase() { port = serverPort, timer = timer, onShutdown = onShutdown - ).startDaemonLife() + ).let { + it.startDaemonElections() + it.configurePeriodicActivities() + } } val comparator = compareByDescending( diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.kt b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.kt index fbd2d1dec2a..88e7bce068f 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/KotlinPaths.kt @@ -98,11 +98,14 @@ interface KotlinPaths { ScriptingLib(PathUtil.KOTLIN_SCRIPTING_COMMON_NAME), ScriptingJvmLib(PathUtil.KOTLIN_SCRIPTING_JVM_NAME), CoroutinesCore(PathUtil.KOTLINX_COROUTINES_CORE_NAME), + KotlinDaemon(PathUtil.KOTLIN_DAEMON_NAME), + Ktor(PathUtil.KTOR_NAME), } + // TODO: Maybe we need separate classpaths for compilers with and without the daemon enum class ClassPaths(val contents: List = emptyList()) { Empty(), - Compiler(Jar.Compiler, Jar.StdLib, Jar.Reflect, Jar.ScriptRuntime, Jar.Trove4j), + Compiler(Jar.Compiler, Jar.StdLib, Jar.Reflect, Jar.ScriptRuntime, Jar.Trove4j, Jar.KotlinDaemon, Jar.Ktor), CompilerWithScripting(Compiler, Jar.ScriptingPlugin, Jar.ScriptingImpl, Jar.ScriptingLib, Jar.ScriptingJvmLib) ; diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt index 44c66b6ae2e..eeb64f56841 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt @@ -65,6 +65,9 @@ object PathUtil { const val KOTLIN_SCRIPTING_COMMON_JAR = "$KOTLIN_SCRIPTING_COMMON_NAME.jar" const val KOTLIN_SCRIPTING_JVM_NAME = "kotlin-scripting-jvm" const val KOTLIN_SCRIPTING_JVM_JAR = "$KOTLIN_SCRIPTING_JVM_NAME.jar" + const val KOTLIN_DAEMON_NAME = "kotlin-daemon" + const val KTOR_NAME = "ktor-network-1.0.1" + const val KOTLIN_DAEMON_JAR = "$KOTLIN_SCRIPTING_JVM_NAME.jar" const val KOTLIN_SCRIPTING_COMPILER_PLUGIN_NAME = "kotlin-scripting-compiler" const val KOTLIN_SCRIPTING_COMPILER_PLUGIN_JAR = "$KOTLIN_SCRIPTING_COMPILER_PLUGIN_NAME.jar" const val KOTLINX_COROUTINES_CORE_NAME = "kotlinx-coroutines-core" diff --git a/idea/build.gradle.kts b/idea/build.gradle.kts index 88c107a4101..99b78117110 100644 --- a/idea/build.gradle.kts +++ b/idea/build.gradle.kts @@ -26,8 +26,8 @@ dependencies { compile(project(":compiler:light-classes")) compile(project(":compiler:util")) compile(project(":kotlin-build-common")) - compile(project(":compiler:daemon-common")) - compile(project(":compiler:daemon-common-new")) + compile(project(":daemon-common")) + compile(project(":daemon-common-new")) compile(projectRuntimeJar(":kotlin-daemon-client")) compile(project(":kotlin-compiler-runner")) { isTransitive = false } compile(project(":compiler:plugin-api")) diff --git a/idea/testData/gradle/highlighting/complexBuildGradleKts/build.gradle.kts b/idea/testData/gradle/highlighting/complexBuildGradleKts/build.gradle.kts index db95dba7cb6..1589efb3200 100644 --- a/idea/testData/gradle/highlighting/complexBuildGradleKts/build.gradle.kts +++ b/idea/testData/gradle/highlighting/complexBuildGradleKts/build.gradle.kts @@ -123,8 +123,8 @@ extra["compilerModules"] = arrayOf( ":compiler:frontend.java", ":compiler:frontend.script", ":compiler:cli-common", - ":compiler:daemon-common", - ":compiler:daemon", + ":daemon-common", + ":daemon", ":compiler:ir.tree", ":compiler:ir.psi2ir", ":compiler:ir.backend.common", diff --git a/jps-plugin/build.gradle.kts b/jps-plugin/build.gradle.kts index ab25685df11..0d818f1d28d 100644 --- a/jps-plugin/build.gradle.kts +++ b/jps-plugin/build.gradle.kts @@ -10,9 +10,10 @@ dependencies { compile(project(":core:descriptors")) compile(project(":core:descriptors.jvm")) compile(project(":kotlin-compiler-runner")) - compile(project(":compiler:daemon-common")) - compile(project(":compiler:daemon-common-new")) + compile(project(":daemon-common")) + compile(project(":daemon-common-new")) compile(projectRuntimeJar(":kotlin-daemon-client")) + compile(projectRuntimeJar(":kotlin-daemon")) compile(project(":compiler:frontend.java")) compile(project(":js:js.frontend")) compile(projectRuntimeJar(":kotlin-preloader")) diff --git a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt index 09b44cbf83f..5088cfe0fc3 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/compilerRunner/JpsKotlinCompilerRunner.kt @@ -338,8 +338,9 @@ class JpsKotlinCompilerRunner { environment.progressReporter.progress("connecting to daemon") val libPath = CompilerRunnerUtil.getLibPath(environment.kotlinPaths, environment.messageCollector) val compilerPath = File(libPath, "kotlin-compiler.jar") + val daemonJarPath = File(libPath, "kotlin-daemon.jar") val toolsJarPath = CompilerRunnerUtil.jdkToolsJar - val compilerId = CompilerId.makeCompilerId(listOfNotNull(compilerPath, toolsJarPath)) + val compilerId = CompilerId.makeCompilerId(listOfNotNull(compilerPath, toolsJarPath, daemonJarPath)) val daemonOptions = configureDaemonOptions() val additionalJvmParams = mutableListOf() diff --git a/libraries/examples/kotlin-jsr223-daemon-local-eval-example/build.gradle.kts b/libraries/examples/kotlin-jsr223-daemon-local-eval-example/build.gradle.kts index 961e43ccee6..5457e9e402b 100644 --- a/libraries/examples/kotlin-jsr223-daemon-local-eval-example/build.gradle.kts +++ b/libraries/examples/kotlin-jsr223-daemon-local-eval-example/build.gradle.kts @@ -18,6 +18,7 @@ dependencies { testCompile(project(":kotlin-script-runtime")) testCompile(project(":kotlin-script-util")) testCompile(projectRuntimeJar(":kotlin-daemon-client")) + testCompile(projectRuntimeJar(":kotlin-daemon")) testCompile(projectRuntimeJar(":kotlin-compiler-embeddable")) testCompile(commonDep("junit:junit")) testCompile(project(":kotlin-test:kotlin-test-junit")) @@ -30,7 +31,7 @@ dependencies { compilerClasspath(commonDep("org.jetbrains.intellij.deps", "trove4j")) compileOnly(project(":compiler:cli-common")) // TODO: fix import (workaround for jps build) testCompileOnly(project(":core:util.runtime")) // TODO: fix import (workaround for jps build) - testCompileOnly(project(":compiler:daemon-common")) // TODO: fix import (workaround for jps build) + testCompileOnly(project(":daemon-common")) // TODO: fix import (workaround for jps build) } projectTest { diff --git a/libraries/examples/kotlin-jsr223-local-example/build.gradle.kts b/libraries/examples/kotlin-jsr223-local-example/build.gradle.kts index 9648adc3f9a..3e49cfde6fe 100644 --- a/libraries/examples/kotlin-jsr223-local-example/build.gradle.kts +++ b/libraries/examples/kotlin-jsr223-local-example/build.gradle.kts @@ -22,7 +22,7 @@ dependencies { testRuntime(project(":kotlin-reflect")) compileOnly(project(":compiler:cli-common")) // TODO: fix import (workaround for jps build) testCompileOnly(project(":core:util.runtime")) // TODO: fix import (workaround for jps build) - testCompileOnly(project(":compiler:daemon-common")) // TODO: fix import (workaround for jps build) + testCompileOnly(project(":daemon-common")) // TODO: fix import (workaround for jps build) testRuntime(project(":kotlin-scripting-compiler-embeddable")) } diff --git a/libraries/scripting/jvm-host/build.gradle.kts b/libraries/scripting/jvm-host/build.gradle.kts index b64c4550ebb..aeca70a40c3 100644 --- a/libraries/scripting/jvm-host/build.gradle.kts +++ b/libraries/scripting/jvm-host/build.gradle.kts @@ -20,7 +20,7 @@ dependencies { runtime(project(":kotlin-reflect")) testCompile(projectTests(":compiler:tests-common")) testCompile(commonDep("junit")) - testCompile(project(":compiler:daemon-common")) // TODO: fix import (workaround for jps build) + testCompile(project(":daemon-common")) // TODO: fix import (workaround for jps build) } sourceSets { diff --git a/libraries/tools/kotlin-gradle-plugin/build.gradle.kts b/libraries/tools/kotlin-gradle-plugin/build.gradle.kts index 3f1f59fa978..6fff2a763f8 100644 --- a/libraries/tools/kotlin-gradle-plugin/build.gradle.kts +++ b/libraries/tools/kotlin-gradle-plugin/build.gradle.kts @@ -34,7 +34,7 @@ dependencies { compile(project(":kotlin-gradle-plugin-model")) compileOnly(project(":compiler")) compileOnly(project(":compiler:incremental-compilation-impl")) - compileOnly(project(":compiler:daemon-common")) + compileOnly(project(":daemon-common")) compile(kotlinStdlib()) compileOnly(project(":kotlin-reflect-api")) diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt index 09565f9b3eb..e76d0c2ba20 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerRunner.kt @@ -36,6 +36,8 @@ import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.tasks.* import org.jetbrains.kotlin.gradle.utils.newTmpFile import org.jetbrains.kotlin.gradle.utils.relativeToRoot +import org.jetbrains.kotlin.incremental.IncrementalModuleInfo +import org.jetbrains.kotlin.incremental.IncrementalModuleEntry import org.jetbrains.kotlin.incremental.classpathAsList import org.jetbrains.kotlin.incremental.destinationAsFile import org.jetbrains.kotlin.incremental.makeModuleFile @@ -183,7 +185,12 @@ internal open class GradleCompilerRunner(protected val task: Task) { for (project in gradle.rootProject.allprojects) { project.tasks.withType(AbstractKotlinCompile::class.java).toList().forEach { task -> - val module = IncrementalModuleEntry(project.path, task.moduleName, project.buildDir, task.buildHistoryFile) + val module = IncrementalModuleEntry( + project.path, + task.moduleName, + project.buildDir, + task.buildHistoryFile + ) dirToModule[task.destinationDir] = module task.javaOutputDir?.let { dirToModule[it] = module } nameToModules.getOrPut(module.name) { HashSet() }.add(module) @@ -201,7 +208,12 @@ internal open class GradleCompilerRunner(protected val task: Task) { for (target in kotlinExt.targets) { val mainCompilation = target.compilations.findByName(KotlinCompilation.MAIN_COMPILATION_NAME) ?: continue val kotlinTask = mainCompilation.compileKotlinTask as? AbstractKotlinCompile<*> ?: continue - val module = IncrementalModuleEntry(project.path, kotlinTask.moduleName, project.buildDir, kotlinTask.buildHistoryFile) + val module = IncrementalModuleEntry( + project.path, + kotlinTask.moduleName, + project.buildDir, + kotlinTask.buildHistoryFile + ) val jarTask = project.tasks.findByName(target.artifactsTaskName) as? AbstractArchiveTask ?: continue jarToModule[jarTask.archivePath] = module } diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerWork.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerWork.kt index ecbb108347e..d24978438b8 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerWork.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/compilerRunner/GradleKotlinCompilerWork.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.gradle.tasks.clearLocalState import org.jetbrains.kotlin.gradle.tasks.throwGradleExceptionIfError import org.jetbrains.kotlin.gradle.utils.stackTraceAsString import org.jetbrains.kotlin.incremental.ChangedFiles +import org.jetbrains.kotlin.incremental.IncrementalModuleInfo import org.slf4j.LoggerFactory import java.io.* import java.net.URLClassLoader @@ -148,7 +149,7 @@ internal class GradleKotlinCompilerWork @Inject constructor( } private fun compileWithDaemon(messageCollector: MessageCollector): ExitCode? { - val isDebugEnabled = log.isDebugEnabled || System.getProperty("kotlin.daemon.debug.log")?.toBoolean() ?: false + val isDebugEnabled = log.isDebugEnabled || System.getProperty("kotlin.daemon.debug.log")?.toBoolean() ?: true val enableAssertions = System.getProperty("kotlin.daemon.ea")?.toBoolean() ?: false val daemonMessageCollector = if (isDebugEnabled) messageCollector else MessageCollector.NONE diff --git a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/jarSearchingUtil.kt b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/jarSearchingUtil.kt index 44eb6f32856..62af57293d0 100644 --- a/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/jarSearchingUtil.kt +++ b/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/tasks/jarSearchingUtil.kt @@ -39,6 +39,7 @@ private val KOTLIN_SCRIPT_ANNOTATION_EXPECTED_CLASS = "kotlin.script.experimenta private val KOTLIN_JVM_SCRIPT_COMPILER_EXPECTED_CLASS = "kotlin.script.experimental.jvm.JvmScriptCompiler" private val KOTLIN_REFLECT_EXPECTED_CLASS = "kotlin.reflect.full.KClasses" private val TROVE4J_EXPECTED_CLASS = "gnu.trove.THashMap" +private val DAEMON_EXPECTED_CLASS = "org.jetbrains.kotlin.daemon.CompileServiceImpl" internal const val KOTLIN_MODULE_GROUP = "org.jetbrains.kotlin" private val KOTLIN_GRADLE_PLUGIN = "kotlin-gradle-plugin" internal const val KOTLIN_COMPILER_EMBEDDABLE = "kotlin-compiler-embeddable" @@ -76,20 +77,23 @@ internal fun findKotlinCompilerClasspath(project: Project): List { return findKotlinStdlibClasspath(project) + findKotlinScriptRuntimeClasspath(project) + findKotlinReflectClasspath(project) + - listOfNotNull(findTrove4j()) + listOfNotNull(findTrove4j(), findDaemon()) } -internal fun findTrove4j(): File? { +internal fun findJarByClass(classFqName: String): File? { val classLoader = Thread.currentThread().contextClassLoader - val classFromTrove4j = try { - classLoader.loadClass(TROVE4J_EXPECTED_CLASS) + val classFromJar = try { + classLoader.loadClass(classFqName) } catch (e: ClassNotFoundException) { null } ?: return null - return findJarByClass(classFromTrove4j) + return findJarByClass(classFromJar) } +internal fun findTrove4j() = findJarByClass(TROVE4J_EXPECTED_CLASS) +internal fun findDaemon() = findJarByClass(DAEMON_EXPECTED_CLASS) + internal fun findKotlinStdlibClasspath(project: Project): List = findKotlinModuleJar(project, KOTLIN_STDLIB_EXPECTED_CLASS, KOTLIN_STDLIB) diff --git a/libraries/tools/kotlin-script-util/build.gradle.kts b/libraries/tools/kotlin-script-util/build.gradle.kts index 4d9e7aff92a..c48a6033cde 100644 --- a/libraries/tools/kotlin-script-util/build.gradle.kts +++ b/libraries/tools/kotlin-script-util/build.gradle.kts @@ -16,7 +16,7 @@ dependencies { compile(project(":kotlin-scripting-jvm")) compile(commonDep("org.jetbrains.intellij.deps", "trove4j")) compileOnly(project(":compiler:cli")) - compileOnly(project(":compiler:daemon-common")) + compileOnly(project(":daemon-common")) compileOnly(project(":kotlin-scripting-compiler")) compile(projectRuntimeJar(":kotlin-daemon-client")) compileOnly("com.jcabi:jcabi-aether:1.0-SNAPSHOT") diff --git a/license/third_party/testdata/findbugs_license.txt b/license/third_party/testdata/findbugs_license.txt index 6789d151d7c..40a0ab7d3b1 100644 --- a/license/third_party/testdata/findbugs_license.txt +++ b/license/third_party/testdata/findbugs_license.txt @@ -7,7 +7,7 @@ of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, Version 2, hence + as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble @@ -227,7 +227,7 @@ the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, Version 2, +that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in diff --git a/nj2k/nj2k-services/build.gradle.kts b/nj2k/nj2k-services/build.gradle.kts index fcd9ca7f5ba..521c3b4367b 100644 --- a/nj2k/nj2k-services/build.gradle.kts +++ b/nj2k/nj2k-services/build.gradle.kts @@ -20,7 +20,7 @@ dependencies { compile(project(":compiler:light-classes")) compile(project(":compiler:util")) compile(project(":kotlin-build-common")) - compile(project(":compiler:daemon-common")) + compile(project(":daemon-common")) compile(projectRuntimeJar(":kotlin-daemon-client")) compile(project(":kotlin-compiler-runner")) { isTransitive = false } compile(project(":compiler:plugin-api")) diff --git a/plugins/source-sections/source-sections-compiler/build.gradle.kts b/plugins/source-sections/source-sections-compiler/build.gradle.kts index cc64e2f8c89..842e1bba51c 100644 --- a/plugins/source-sections/source-sections-compiler/build.gradle.kts +++ b/plugins/source-sections/source-sections-compiler/build.gradle.kts @@ -18,7 +18,7 @@ dependencies { testCompile(project(":compiler:cli")) testCompile(project(":compiler:cli-common")) testCompile(project(":compiler:frontend.java")) - testCompile(project(":compiler:daemon-common")) + testCompile(project(":daemon-common")) testCompile(projectRuntimeJar(":kotlin-daemon-client")) testCompile(projectTests(":compiler:tests-common")) testCompile(commonDep("junit:junit")) diff --git a/prepare/compiler-client-embeddable/build.gradle.kts b/prepare/compiler-client-embeddable/build.gradle.kts index 4a206c6c8df..a2a57048652 100644 --- a/prepare/compiler-client-embeddable/build.gradle.kts +++ b/prepare/compiler-client-embeddable/build.gradle.kts @@ -15,12 +15,12 @@ val archives by configurations dependencies { jarContents(project(":compiler:cli-common")) { isTransitive = false } - jarContents(project(":compiler:daemon-common")) { isTransitive = false } - jarContents(project(":compiler:daemon-common-new")) { isTransitive = false } + jarContents(project(":daemon-common")) { isTransitive = false } + jarContents(project(":daemon-common-new")) { isTransitive = false } jarContents(projectRuntimeJar(":kotlin-daemon-client")) testCompile(project(":compiler:cli-common")) - testCompile(project(":compiler:daemon-common")) - testCompile(project(":compiler:daemon-common-new")) + testCompile(project(":daemon-common")) + testCompile(project(":daemon-common-new")) testCompile(projectRuntimeJar(":kotlin-daemon-client")) testCompile(commonDep("junit:junit")) testCompile(project(":kotlin-test:kotlin-test-jvm")) diff --git a/prepare/compiler-embeddable/build.gradle.kts b/prepare/compiler-embeddable/build.gradle.kts index 4299a7ad792..b8726ac5aed 100644 --- a/prepare/compiler-embeddable/build.gradle.kts +++ b/prepare/compiler-embeddable/build.gradle.kts @@ -9,6 +9,7 @@ dependencies { runtime(kotlinStdlib()) runtime(project(":kotlin-script-runtime")) runtime(project(":kotlin-reflect")) + runtime(project(":kotlin-daemon-embeddable")) runtime(commonDep("org.jetbrains.intellij.deps", "trove4j")) } diff --git a/prepare/compiler/build.gradle.kts b/prepare/compiler/build.gradle.kts index 802eee32806..6e8a77437e5 100644 --- a/prepare/compiler/build.gradle.kts +++ b/prepare/compiler/build.gradle.kts @@ -26,14 +26,13 @@ val libraries by configurations.creating { extendsFrom(compile) } val trove4jJar by configurations.creating +val ktorNetworkJar by configurations.creating val default by configurations default.extendsFrom(runtimeJar) val compilerBaseName = name -val ktorExcludesForDaemon : List> by rootProject.extra - val outputJar = fileFrom(buildDir, "libs", "$compilerBaseName.jar") val compilerModules: Array by rootProject.extra @@ -58,11 +57,9 @@ dependencies { } trove4jJar(intellijDep()) { includeIntellijCoreJarDependencies(project) { it.startsWith("trove4j") } } + ktorNetworkJar(commonDep("io.ktor", "ktor-network")) fatJarContents(kotlinBuiltins()) - fatJarContents(project(":kotlin-daemon-client-new")) { - isTransitive = false - } fatJarContents(commonDep("javax.inject")) fatJarContents(commonDep("org.jline", "jline")) fatJarContents(commonDep("org.fusesource.jansi", "jansi")) @@ -70,11 +67,6 @@ dependencies { fatJarContents(commonDep("com.google.code.findbugs", "jsr305")) fatJarContents(commonDep("io.javaslang", "javaslang")) fatJarContents(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } - fatJarContents(commonDep("io.ktor", "ktor-network")) { - ktorExcludesForDaemon.forEach { (group, module) -> - exclude(group = group, module = module) - } - } fatJarContents(intellijCoreDep()) { includeJars("intellij-core", "java-compatibility-1.0.1") } fatJarContents(intellijDep()) { @@ -142,6 +134,7 @@ val pack = if (shrink) proguard else packCompiler dist(targetName = "$compilerBaseName.jar", fromTask = pack) { from(trove4jJar) + from(ktorNetworkJar) } runtimeJarArtifactBy(pack, pack.outputs.files.singleFile) { diff --git a/prepare/compiler/build.gradle.kts.182 b/prepare/compiler/build.gradle.kts.182 index 50bc3b848ac..cacf250d429 100644 --- a/prepare/compiler/build.gradle.kts.182 +++ b/prepare/compiler/build.gradle.kts.182 @@ -26,6 +26,7 @@ val libraries by configurations.creating { extendsFrom(compile) } val trove4jJar by configurations.creating +val ktorNetworkJar by configurations.creating val default by configurations default.extendsFrom(runtimeJar) @@ -36,8 +37,6 @@ val outputJar = fileFrom(buildDir, "libs", "$compilerBaseName.jar") val compilerModules: Array by rootProject.extra -val ktorExcludesForDaemon : List> by rootProject.extra - dependencies { compile(kotlinStdlib()) compile(project(":kotlin-script-runtime")) @@ -58,11 +57,9 @@ dependencies { } trove4jJar(intellijDep()) { includeIntellijCoreJarDependencies(project) { it.startsWith("trove4j") } } + ktorNetworkJar(commonDep("io.ktor", "ktor-network")) fatJarContents(kotlinBuiltins()) - fatJarContents(project(":kotlin-daemon-client-new")) { - isTransitive = false - } fatJarContents(commonDep("javax.inject")) fatJarContents(commonDep("org.jline", "jline")) fatJarContents(commonDep("org.fusesource.jansi", "jansi")) @@ -70,11 +67,6 @@ dependencies { fatJarContents(commonDep("com.google.code.findbugs", "jsr305")) fatJarContents(commonDep("io.javaslang", "javaslang")) fatJarContents(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } - fatJarContents(commonDep("io.ktor", "ktor-network")) { - ktorExcludesForDaemon.forEach { (group, module) -> - exclude(group = group, module = module) - } - } fatJarContents(intellijCoreDep()) { includeJars("intellij-core") } fatJarContents(intellijDep()) { @@ -142,6 +134,7 @@ val pack = if (shrink) proguard else packCompiler dist(targetName = "$compilerBaseName.jar", fromTask = pack) { from(trove4jJar) + from(ktorNetworkJar) } runtimeJarArtifactBy(pack, pack.outputs.files.singleFile) { diff --git a/prepare/compiler/build.gradle.kts.as34 b/prepare/compiler/build.gradle.kts.as34 index e8cc420a03f..cacf250d429 100644 --- a/prepare/compiler/build.gradle.kts.as34 +++ b/prepare/compiler/build.gradle.kts.as34 @@ -26,6 +26,7 @@ val libraries by configurations.creating { extendsFrom(compile) } val trove4jJar by configurations.creating +val ktorNetworkJar by configurations.creating val default by configurations default.extendsFrom(runtimeJar) @@ -36,8 +37,6 @@ val outputJar = fileFrom(buildDir, "libs", "$compilerBaseName.jar") val compilerModules: Array by rootProject.extra -val ktorExcludesForDaemon : List> by rootProject.extra - dependencies { compile(kotlinStdlib()) compile(project(":kotlin-script-runtime")) @@ -58,11 +57,9 @@ dependencies { } trove4jJar(intellijDep()) { includeIntellijCoreJarDependencies(project) { it.startsWith("trove4j") } } + ktorNetworkJar(commonDep("io.ktor", "ktor-network")) fatJarContents(kotlinBuiltins()) - fatJarContents(project(":kotlin-daemon-client-new")) { - isTransitive = false - } fatJarContents(commonDep("javax.inject")) fatJarContents(commonDep("org.jline", "jline")) fatJarContents(commonDep("org.fusesource.jansi", "jansi")) @@ -70,11 +67,6 @@ dependencies { fatJarContents(commonDep("com.google.code.findbugs", "jsr305")) fatJarContents(commonDep("io.javaslang", "javaslang")) fatJarContents(commonDep("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } - fatJarContents(commonDep("io.ktor", "ktor-network")) { - ktorExcludesForDaemon.forEach { (group, module) -> - exclude(group = group, module = module) - } - } fatJarContents(intellijCoreDep()) { includeJars("intellij-core") } fatJarContents(intellijDep()) { @@ -142,6 +134,7 @@ val pack = if (shrink) proguard else packCompiler dist(targetName = "$compilerBaseName.jar", fromTask = pack) { from(trove4jJar) + from(ktorNetworkJar) } runtimeJarArtifactBy(pack, pack.outputs.files.singleFile) { diff --git a/prepare/idea-plugin/build.gradle.kts b/prepare/idea-plugin/build.gradle.kts index baae9f151da..a6137df77ce 100644 --- a/prepare/idea-plugin/build.gradle.kts +++ b/prepare/idea-plugin/build.gradle.kts @@ -21,8 +21,8 @@ val projectsToShadow by extra(listOf( ":kotlin-build-common", ":compiler:cli-common", ":compiler:container", - ":compiler:daemon-common", - ":compiler:daemon-common-new", + ":daemon-common", + ":daemon-common-new", ":core:metadata", ":core:metadata.jvm", ":core:descriptors", @@ -120,6 +120,10 @@ dependencies { libraries(project(":kotlin-reflect")) libraries(project(":kotlin-compiler-client-embeddable")) libraries(project(":kotlin-daemon-client")) + libraries(project(":kotlin-daemon-client-new")) + libraries(project(":kotlin-daemon")) { + isTransitive = false + } libraries(project(":kotlin-script-runtime")) libraries(project(":kotlin-script-util")) libraries(project(":kotlin-scripting-common")) diff --git a/prepare/jps-plugin/build.gradle.kts b/prepare/jps-plugin/build.gradle.kts index 649d8151f09..c6df3c44275 100644 --- a/prepare/jps-plugin/build.gradle.kts +++ b/prepare/jps-plugin/build.gradle.kts @@ -10,8 +10,8 @@ val projectsToShadow = listOf( ":kotlin-build-common", ":compiler:cli-common", ":kotlin-compiler-runner", - ":compiler:daemon-common", - ":compiler:daemon-common-new", + ":daemon-common", + ":daemon-common-new", ":core:descriptors", ":core:descriptors.jvm", ":idea:idea-jps-common", diff --git a/prepare/kotlin-daemon-embeddable/build.gradle.kts b/prepare/kotlin-daemon-embeddable/build.gradle.kts new file mode 100644 index 00000000000..8a701499021 --- /dev/null +++ b/prepare/kotlin-daemon-embeddable/build.gradle.kts @@ -0,0 +1,28 @@ + +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.jvm.tasks.Jar + +description = "Kotlin Daemon (for using with embeddable compiler)" + +plugins { + `java` +} + +val packedJars by configurations.creating + +dependencies { + packedJars(project(":kotlin-daemon")) { isTransitive = false } +} + +publish() + +noDefaultJar() + +runtimeJar(rewriteDepsToShadedCompiler( + task("shadowJar") { + from(packedJars) + } +)) + +sourcesJar() +javadocJar() diff --git a/settings.gradle b/settings.gradle index eac040cf236..fc67af84405 100644 --- a/settings.gradle +++ b/settings.gradle @@ -19,9 +19,9 @@ pluginManagement { include ":kotlin-build-common", ":compiler", ":compiler:util", - ":compiler:daemon-common", - ":compiler:daemon-common-new", - ":compiler:daemon", + ":daemon-common", + ":daemon-common-new", + ":kotlin-daemon", ":kotlin-daemon-client", ":kotlin-daemon-client-new", ":kotlin-preloader", @@ -168,6 +168,7 @@ include ":kotlin-build-common", ":kotlin-annotation-processing-runtime", ":kotlin-annotation-processing-gradle", ":kotlin-annotation-processing-embeddable", + ":kotlin-daemon-embeddable", ":examples:kotlin-jsr223-local-example", ":examples:kotlin-jsr223-daemon-local-eval-example", ":kotlin-annotations-jvm", @@ -294,8 +295,9 @@ project(':kotlin-build-common').projectDir = "$rootDir/build-common" as File project(':compiler:cli-common').projectDir = "$rootDir/compiler/cli/cli-common" as File project(':compiler:cli-js').projectDir = "$rootDir/compiler/cli/cli-js" as File project(':kotlin-runner').projectDir = "$rootDir/compiler/cli/cli-runner" as File -project(':compiler:daemon-common').projectDir = "$rootDir/compiler/daemon/daemon-common" as File -project(':compiler:daemon-common-new').projectDir = "$rootDir/compiler/daemon/daemon-common-new" as File +project(':kotlin-daemon').projectDir = "$rootDir/compiler/daemon" as File +project(':daemon-common').projectDir = "$rootDir/compiler/daemon/daemon-common" as File +project(':daemon-common-new').projectDir = "$rootDir/compiler/daemon/daemon-common-new" as File project(':kotlin-daemon-client').projectDir = "$rootDir/compiler/daemon/daemon-client" as File project(':kotlin-daemon-client-new').projectDir = "$rootDir/compiler/daemon/daemon-client-new" as File project(':kotlin-compiler-runner').projectDir = "$rootDir/compiler/compiler-runner" as File @@ -338,6 +340,7 @@ project(':examples:annotation-processor-example').projectDir = "$rootDir/librari project(':kotlin-script-util').projectDir = "$rootDir/libraries/tools/kotlin-script-util" as File project(':kotlin-annotation-processing-gradle').projectDir = "$rootDir/libraries/tools/kotlin-annotation-processing" as File project(':kotlin-annotation-processing-embeddable').projectDir = "$rootDir/prepare/kotlin-annotation-processing-embeddable" as File +project(':kotlin-daemon-embeddable').projectDir = "$rootDir/prepare/kotlin-daemon-embeddable" as File project(':kotlin-annotation-processing').projectDir = "$rootDir/plugins/kapt3/kapt3-compiler" as File project(':kotlin-annotation-processing-cli').projectDir = "$rootDir/plugins/kapt3/kapt3-cli" as File project(':kotlin-annotation-processing-base').projectDir = "$rootDir/plugins/kapt3/kapt3-base" as File