minor: move native platform launcher to separate file to make native-platform dependency optional

This commit is contained in:
Ilya Chernikov
2017-04-05 14:34:31 +02:00
parent 90a8a164b4
commit aebfc2f4a1
2 changed files with 42 additions and 8 deletions
@@ -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()
@@ -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)
}
}