From 7cfe7f2a7842bf327be8b7881e26bb0963378530 Mon Sep 17 00:00:00 2001 From: Maksymilian Pawlak <120831+m4ksio@users.noreply.github.com> Date: Wed, 13 Dec 2017 18:21:00 +0000 Subject: [PATCH] Windows space in path escape (#2246) --- .../kotlin/net/corda/plugins/NodeRunner.kt | 13 ++++++------- 1 file changed, 6 insertions(+), 7 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 94953584ab..c49bd847f7 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 @@ -122,7 +122,7 @@ private class TerminalWindowJavaCommand(jarName: String, dir: File, debugPort: I end tell""") } OS.WINDOWS -> { - listOf("cmd", "/C", "start ${command.joinToString(" ")}") + listOf("cmd", "/C", "start ${command.joinToString(" ") { windowsSpaceEscape(it) }}") } OS.LINUX -> { // Start shell to keep window open unless java terminated normally or due to SIGTERM: @@ -136,12 +136,11 @@ 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 - } + override fun getJavaPath(): String = 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. + private fun windowsSpaceEscape(s:String) = s.replace(" ", "\" \"") } private fun quotedFormOf(text: String) = "'${text.replace("'", "'\\''")}'" // Suitable for UNIX shells.