Introduced a few more extension methods to Path, which are clearer than the static methods in Files. (#2985)

Also migrated code away from the old File API.
This commit is contained in:
Shams Asari
2018-04-23 14:31:49 +01:00
committed by GitHub
parent 3aaa176dd4
commit d3446e213c
62 changed files with 661 additions and 526 deletions

View File

@ -108,7 +108,7 @@ object InteractiveShell {
config["crash.auth"] = "corda"
configuration.sshHostKeyDirectory?.apply {
val sshKeysDir = configuration.sshHostKeyDirectory
sshKeysDir.toFile().mkdirs()
sshKeysDir.createDirectories()
config["crash.ssh.keypath"] = (sshKeysDir / "hostkey.pem").toString()
config["crash.ssh.keygen"] = "true"
}

View File

@ -9,11 +9,11 @@ import com.fasterxml.jackson.databind.SerializerProvider
import com.google.common.io.Closeables
import net.corda.core.contracts.UniqueIdentifier
import net.corda.core.internal.copyTo
import net.corda.core.internal.inputStream
import org.crsh.command.InvocationContext
import rx.Observable
import java.io.BufferedInputStream
import java.io.InputStream
import java.nio.file.Files
import java.nio.file.Paths
import java.util.*
@ -85,7 +85,7 @@ object InputStreamDeserializer : JsonDeserializer<InputStream>() {
private val streams = Collections.synchronizedSet(HashSet<InputStream>())
override fun deserialize(p: JsonParser, ctxt: DeserializationContext): InputStream {
val stream = object : BufferedInputStream(Files.newInputStream(Paths.get(p.text))) {
val stream = object : BufferedInputStream(Paths.get(p.text).inputStream()) {
override fun close() {
super.close()
streams.remove(this)

View File

@ -1,19 +1,18 @@
package net.corda.tools.shell
import net.corda.core.internal.toPath
import net.corda.core.utilities.NetworkHostAndPort
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.slf4j.event.Level
import java.nio.file.Paths
import kotlin.test.assertEquals
import java.io.File
class StandaloneShellArgsParserTest {
private val CONFIG_FILE = File(StandaloneShellArgsParserTest::class.java.getResource("/config.conf").toURI())
private val CONFIG_FILE = StandaloneShellArgsParserTest::class.java.getResource("/config.conf").toPath()
@Test
fun args_to_cmd_options() {
val args = arrayOf("--config-file", "/x/y/z/config.conf",
"--commands-directory", "/x/y/commands",
"--cordpass-directory", "/x/y/cordapps",
@ -32,7 +31,8 @@ class StandaloneShellArgsParserTest {
"--truststore-type", "dummy",
"--keystore-type", "JKS")
val expectedOptions = CommandLineOptions(configFile = "/x/y/z/config.conf",
val expectedOptions = CommandLineOptions(
configFile = "/x/y/z/config.conf",
commandsDirectory = Paths.get("/x/y/commands").normalize().toAbsolutePath(),
cordappsDirectory = Paths.get("/x/y/cordapps").normalize().toAbsolutePath(),
host = "alocalhost",
@ -52,7 +52,7 @@ class StandaloneShellArgsParserTest {
val options = CommandLineOptionParser().parse(*args)
assertEquals(expectedOptions, options)
assertThat(options).isEqualTo(expectedOptions)
}
@Test
@ -127,7 +127,7 @@ class StandaloneShellArgsParserTest {
@Test
fun cmd_options_to_config_from_file() {
val options = CommandLineOptions(configFile = CONFIG_FILE.absolutePath,
val options = CommandLineOptions(configFile = CONFIG_FILE.toString(),
commandsDirectory = null,
cordappsDirectory = null,
host = null,
@ -166,7 +166,7 @@ class StandaloneShellArgsParserTest {
@Test
fun cmd_options_override_config_from_file() {
val options = CommandLineOptions(configFile = CONFIG_FILE.absolutePath,
val options = CommandLineOptions(configFile = CONFIG_FILE.toString(),
commandsDirectory = null,
cordappsDirectory = null,
host = null,