Avoid changing java.rmi.server.hostname property
This commit is contained in:
+4
-2
@@ -105,7 +105,7 @@ object KotlinCompilerClient {
|
||||
leaseSession: Boolean,
|
||||
sessionAliveFlagFile: File? = null
|
||||
): CompileServiceSession? = connectLoop(reportingTargets) {
|
||||
setupServerHostName()
|
||||
ensureServerHostnameIsSetUp()
|
||||
val (service, newJVMOptions) = tryFindSuitableDaemonOrNewOpts(File(daemonOptions.runFilesPath), compilerId, daemonJVMOptions, { cat, msg -> reportingTargets.report(cat, msg) })
|
||||
if (service != null) {
|
||||
// the newJVMOptions could be checked here for additional parameters, if needed
|
||||
@@ -380,9 +380,11 @@ object KotlinCompilerClient {
|
||||
|
||||
private fun startDaemon(compilerId: CompilerId, daemonJVMOptions: DaemonJVMOptions, daemonOptions: DaemonOptions, reportingTargets: DaemonReportingTargets) {
|
||||
val javaExecutable = File(File(System.getProperty("java.home"), "bin"), "java")
|
||||
val serverHostname = System.getProperty(JAVA_RMI_SERVER_HOSTNAME) ?: error("$JAVA_RMI_SERVER_HOSTNAME is not set!")
|
||||
val platformSpecificOptions = listOf(
|
||||
// hide daemon window
|
||||
"-Djava.awt.headless=true")
|
||||
"-Djava.awt.headless=true",
|
||||
"-D$JAVA_RMI_SERVER_HOSTNAME=$serverHostname")
|
||||
val args = listOf(
|
||||
javaExecutable.absolutePath, "-cp", compilerId.compilerClasspath.joinToString(File.pathSeparator)) +
|
||||
platformSpecificOptions +
|
||||
|
||||
+5
-2
@@ -31,6 +31,7 @@ import java.util.*
|
||||
|
||||
|
||||
val SOCKET_ANY_FREE_PORT = 0
|
||||
val JAVA_RMI_SERVER_HOSTNAME = "java.rmi.server.hostname"
|
||||
|
||||
object LoopbackNetworkInterface {
|
||||
|
||||
@@ -100,6 +101,8 @@ fun findPortAndCreateRegistry(attempts: Int, portRangeStart: Int, portRangeEnd:
|
||||
* Needs to be set up on both client and server to prevent localhost resolution,
|
||||
* which may be slow and can cause a timeout when there is a network problem/misconfiguration.
|
||||
*/
|
||||
fun setupServerHostName() {
|
||||
System.setProperty("java.rmi.server.hostname", LoopbackNetworkInterface.loopbackInetAddressName)
|
||||
fun ensureServerHostnameIsSetUp() {
|
||||
if (System.getProperty(JAVA_RMI_SERVER_HOSTNAME) == null) {
|
||||
System.setProperty(JAVA_RMI_SERVER_HOSTNAME, LoopbackNetworkInterface.loopbackInetAddressName)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ object KotlinCompileDaemon {
|
||||
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
setupServerHostName()
|
||||
ensureServerHostnameIsSetUp()
|
||||
|
||||
log.info("Kotlin compiler daemon version " + (loadVersionFromResource() ?: "<unknown>"))
|
||||
log.info("daemon JVM args: " + ManagementFactory.getRuntimeMXBean().inputArguments.joinToString(" "))
|
||||
|
||||
Reference in New Issue
Block a user