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