diff --git a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt index f9bf988088e..00c5eb1775f 100644 --- a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt +++ b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinCompilerClient.kt @@ -16,9 +16,6 @@ package org.jetbrains.kotlin.daemon.client -import net.rubygrapefruit.platform.Native -import net.rubygrapefruit.platform.NativeException -import net.rubygrapefruit.platform.ProcessLauncher import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector @@ -26,6 +23,7 @@ import org.jetbrains.kotlin.daemon.common.* import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents import org.jetbrains.kotlin.progress.CompilationCanceledStatus import java.io.File +import java.io.IOException import java.io.OutputStream import java.io.PrintStream import java.net.SocketException @@ -399,13 +397,17 @@ object KotlinCompilerClient { // assuming daemon process is deaf and (mostly) silent, so do not handle streams val daemon = try { - val nativeLauncher = Native.get(ProcessLauncher::class.java) - nativeLauncher.start(processBuilder) + launchWithNativePlatformLauncher(processBuilder) } - catch (e: NativeException) { - reportingTargets.report(DaemonReportCategory.DEBUG, "Could not start daemon with native process launcher, falling back to ProcessBuilder#start") - processBuilder.start() + catch (e: IOException) { + reportingTargets.report(DaemonReportCategory.DEBUG, "Could not start daemon with native process launcher, falling back to ProcessBuilder#start (${e.cause})") + null } + catch (e: NoClassDefFoundError) { + reportingTargets.report(DaemonReportCategory.DEBUG, "net.rubygrapefruit.platform library is not in the classpath, falling back to ProcessBuilder#start") + null + } + ?: processBuilder.start() val isEchoRead = Semaphore(1) isEchoRead.acquire() diff --git a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/NativePlatformUtil.kt b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/NativePlatformUtil.kt new file mode 100644 index 00000000000..21e3004b587 --- /dev/null +++ b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/NativePlatformUtil.kt @@ -0,0 +1,32 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.daemon.client + +import net.rubygrapefruit.platform.Native +import net.rubygrapefruit.platform.NativeException +import net.rubygrapefruit.platform.ProcessLauncher +import java.io.IOException + +internal fun launchWithNativePlatformLauncher(processBuilder: ProcessBuilder): Process { + return try { + val nativeLauncher = Native.get(ProcessLauncher::class.java) + nativeLauncher.start(processBuilder) + } + catch (e: NativeException) { + throw IOException(e) + } +} \ No newline at end of file