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
This commit is contained in:
Shams Asari 2018-09-17 17:38:28 +01:00 committed by GitHub
parent c79dd8017d
commit 1c4294f42d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 14 deletions

View File

@ -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"],

View File

@ -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")
}
}

View File

@ -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<String>) {
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 {