From 964dbcd9a95fb49696e784d8696bee2369ccd639 Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Thu, 1 Jun 2017 17:05:16 +0100 Subject: [PATCH] Fixed java path for both headless and windowed mode. --- .../kotlin/net/corda/plugins/NodeRunner.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/gradle-plugins/cordformation/src/noderunner/kotlin/net/corda/plugins/NodeRunner.kt b/gradle-plugins/cordformation/src/noderunner/kotlin/net/corda/plugins/NodeRunner.kt index bc2d9181a0..4a9711572e 100644 --- a/gradle-plugins/cordformation/src/noderunner/kotlin/net/corda/plugins/NodeRunner.kt +++ b/gradle-plugins/cordformation/src/noderunner/kotlin/net/corda/plugins/NodeRunner.kt @@ -64,15 +64,8 @@ private object WebJarType : JarType("corda-webserver.jar") { } private abstract class JavaCommand(jarName: String, internal val dir: File, debugPort: Int?, internal val nodeName: String, init: MutableList.() -> Unit, args: List) { - private val javaPath: String by lazy { - val path = File(File(System.getProperty("java.home"), "bin"), "java").path - // Replace below is to fix an issue with spaces in paths on Windows. - // Quoting the entire path does not work, only the space or directory within the path. - if(os == OS.WINDOWS) path.replace(" ", "\" \"") else path - } - internal val command: List = mutableListOf().apply { - add(javaPath) + add(getJavaPath()) add("-Dname=$nodeName") null != debugPort && add("-Dcapsule.jvm.args=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$debugPort") add("-jar") @@ -83,10 +76,12 @@ private abstract class JavaCommand(jarName: String, internal val dir: File, debu internal abstract fun processBuilder(): ProcessBuilder internal fun start() = processBuilder().directory(dir).start() + internal abstract fun getJavaPath(): String } private class HeadlessJavaCommand(jarName: String, dir: File, debugPort: Int?, args: List) : JavaCommand(jarName, dir, debugPort, dir.name, { add("--no-local-shell") }, args) { override fun processBuilder() = ProcessBuilder(command).redirectError(File("error.$nodeName.log")).inheritIO() + override fun getJavaPath() = File(File(System.getProperty("java.home"), "bin"), "java").path } private class TerminalWindowJavaCommand(jarName: String, dir: File, debugPort: Int?, args: List) : JavaCommand(jarName, dir, debugPort, "${dir.name}-$jarName", {}, args) { @@ -114,6 +109,12 @@ end tell""") }) private fun unixCommand() = command.map(::quotedFormOf).joinToString(" ") + override fun getJavaPath(): String { + val path = File(File(System.getProperty("java.home"), "bin"), "java").path + // Replace below is to fix an issue with spaces in paths on Windows. + // Quoting the entire path does not work, only the space or directory within the path. + return if(os == OS.WINDOWS) path.replace(" ", "\" \"") else path + } } private fun quotedFormOf(text: String) = "'${text.replace("'", "'\\''")}'" // Suitable for UNIX shells.