From 1c4294f42d56a426347c6414f9c0cd935fd8e0ef Mon Sep 17 00:00:00 2001 From: Shams Asari Date: Mon, 17 Sep 2018 17:38:28 +0100 Subject: [PATCH] CORDA-1982: Convert the --base-directory to an absolute path to avoid issues on start up (#3952) Also the --network-root-truststore default value has been corrected to be relative to the base dir. The cliutils has been updated to always convert Path cmd line params to be absolute --- .../net/corda/node/NodeCmdLineOptions.kt | 4 ++-- .../net/corda/node/NodeCmdLineOptionsTest.kt | 7 +++---- .../net/corda/cliutils/CordaCliWrapper.kt | 19 +++++++++++-------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/node/src/main/kotlin/net/corda/node/NodeCmdLineOptions.kt b/node/src/main/kotlin/net/corda/node/NodeCmdLineOptions.kt index ab53a9c71a..426d36db91 100644 --- a/node/src/main/kotlin/net/corda/node/NodeCmdLineOptions.kt +++ b/node/src/main/kotlin/net/corda/node/NodeCmdLineOptions.kt @@ -18,7 +18,7 @@ class NodeCmdLineOptions { names = ["-b", "--base-directory"], description = ["The node working directory where all the files are kept."] ) - var baseDirectory: Path = Paths.get(".") + var baseDirectory: Path = Paths.get(".").toAbsolutePath().normalize() @Option( names = ["-f", "--config-file"], @@ -57,7 +57,7 @@ class NodeCmdLineOptions { names = ["-t", "--network-root-truststore"], description = ["Network root trust store obtained from network operator."] ) - var networkRootTrustStorePath = Paths.get("certificates") / "network-root-truststore.jks" + var networkRootTrustStorePath: Path = baseDirectory / "certificates" / "network-root-truststore.jks" @Option( names = ["-p", "--network-root-truststore-password"], diff --git a/node/src/test/kotlin/net/corda/node/NodeCmdLineOptionsTest.kt b/node/src/test/kotlin/net/corda/node/NodeCmdLineOptionsTest.kt index 1ee0e163ea..70ee537829 100644 --- a/node/src/test/kotlin/net/corda/node/NodeCmdLineOptionsTest.kt +++ b/node/src/test/kotlin/net/corda/node/NodeCmdLineOptionsTest.kt @@ -15,20 +15,18 @@ class NodeCmdLineOptionsTest { companion object { private lateinit var workingDirectory: Path - private lateinit var buildDirectory: Path @BeforeClass @JvmStatic fun initDirectories() { workingDirectory = Paths.get(".").normalize().toAbsolutePath() - buildDirectory = workingDirectory.resolve("build") } } @Test fun `no command line arguments`() { - assertThat(parser.cmdLineOptions.baseDirectory.normalize().toAbsolutePath()).isEqualTo(workingDirectory) - assertThat(parser.cmdLineOptions.configFile.normalize().toAbsolutePath()).isEqualTo(workingDirectory / "node.conf") + assertThat(parser.cmdLineOptions.baseDirectory).isEqualTo(workingDirectory) + assertThat(parser.cmdLineOptions.configFile).isEqualTo(workingDirectory / "node.conf") assertThat(parser.verbose).isEqualTo(false) assertThat(parser.loggingLevel).isEqualTo(Level.INFO) assertThat(parser.cmdLineOptions.nodeRegistrationOption).isEqualTo(null) @@ -40,5 +38,6 @@ class NodeCmdLineOptionsTest { assertThat(parser.cmdLineOptions.unknownConfigKeysPolicy).isEqualTo(UnknownConfigKeysPolicy.FAIL) assertThat(parser.cmdLineOptions.devMode).isEqualTo(null) assertThat(parser.cmdLineOptions.clearNetworkMapCache).isEqualTo(false) + assertThat(parser.cmdLineOptions.networkRootTrustStorePath).isEqualTo(workingDirectory / "certificates" / "network-root-truststore.jks") } } diff --git a/tools/cliutils/src/main/kotlin/net/corda/cliutils/CordaCliWrapper.kt b/tools/cliutils/src/main/kotlin/net/corda/cliutils/CordaCliWrapper.kt index 8d37b5f694..f30c3ed05d 100644 --- a/tools/cliutils/src/main/kotlin/net/corda/cliutils/CordaCliWrapper.kt +++ b/tools/cliutils/src/main/kotlin/net/corda/cliutils/CordaCliWrapper.kt @@ -8,6 +8,7 @@ import org.fusesource.jansi.AnsiConsole import org.slf4j.event.Level import picocli.CommandLine import picocli.CommandLine.* +import java.nio.file.Path import java.nio.file.Paths import kotlin.system.exitProcess import java.util.* @@ -45,22 +46,24 @@ interface Validated { /** This is generally covered by commons-lang. */ object CordaSystemUtils { - const val OS_NAME = "os.name" + private const val OS_NAME = "os.name" + private const val MAC_PREFIX = "Mac" + private const val WIN_PREFIX = "Windows" - const val MAC_PREFIX = "Mac" - const val WIN_PREFIX = "Windows" - - fun isOsMac() = getOsName().startsWith(MAC_PREFIX) - fun isOsWindows() = getOsName().startsWith(WIN_PREFIX) - fun getOsName() = System.getProperty(OS_NAME) + fun isOsMac(): Boolean = getOsName().startsWith(MAC_PREFIX) + fun isOsWindows(): Boolean = getOsName().startsWith(WIN_PREFIX) + fun getOsName(): String = System.getProperty(OS_NAME) } fun CordaCliWrapper.start(args: Array) { + this.args = args + // This line makes sure ANSI escapes work on Windows, where they aren't supported out of the box. AnsiConsole.systemInstall() val cmd = CommandLine(this) - this.args = args + // Make sure any provided paths are absolute. Relative paths have caused issues and are less clear in logs. + cmd.registerConverter(Path::class.java) { Paths.get(it).toAbsolutePath().normalize() } cmd.commandSpec.name(alias) cmd.commandSpec.usageMessage().description(description) try {