Fixed java path for both headless and windowed mode.

This commit is contained in:
Clinton Alexander 2017-06-01 17:05:16 +01:00
parent 4ae8356f35
commit 964dbcd9a9

View File

@ -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<String>.() -> Unit, args: List<String>) {
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<String> = mutableListOf<String>().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<String>) : 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<String>) : 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.