diff --git a/node/src/main/kotlin/com/r3corda/node/driver/Driver.kt b/node/src/main/kotlin/com/r3corda/node/driver/Driver.kt index 51e1ddd2e0..32ff224270 100644 --- a/node/src/main/kotlin/com/r3corda/node/driver/Driver.kt +++ b/node/src/main/kotlin/com/r3corda/node/driver/Driver.kt @@ -21,6 +21,7 @@ import java.io.File import java.net.ServerSocket import java.net.Socket import java.net.SocketException +import java.net.URLClassLoader import java.nio.file.Paths import java.text.SimpleDateFormat import java.util.* @@ -85,7 +86,6 @@ sealed class PortAllocation { * @param baseDirectory The base directory node directories go into, defaults to "build//". The node * directories themselves are "//", where legalName defaults to "-" * and may be specified in [DriverDSL.startNode]. - * @param quasarJarPath The path to quasar.jar, relative to cwd. Defaults to "lib/quasar.jar". TODO remove this once we can bundle quasar properly. * @param portAllocation The port allocation strategy to use for the messaging and the web server addresses. Defaults to incremental. * @param debugPortAllocation The port allocation strategy to use for jvm debugging. Defaults to incremental. * @param dsl The dsl itself @@ -93,7 +93,6 @@ sealed class PortAllocation { */ fun driver( baseDirectory: String = "build/${getTimestampAsDirectoryName()}", - quasarJarPath: String = "lib/quasar.jar", portAllocation: PortAllocation = PortAllocation.Incremental(10000), debugPortAllocation: PortAllocation = PortAllocation.Incremental(5005), dsl: DriverDSLExposedInterface.() -> A @@ -101,14 +100,12 @@ fun driver( driverDsl = DriverDSL( portAllocation = portAllocation, debugPortAllocation = debugPortAllocation, - baseDirectory = baseDirectory, - quasarJarPath = quasarJarPath + baseDirectory = baseDirectory ), coerce = { it }, dsl = dsl ) - /** * This is a helper method to allow extending of the DSL, along the lines of * interface SomeOtherExposedDSLInterface : DriverDSLExposedInterface @@ -185,8 +182,7 @@ fun poll(f: () -> A?): A { class DriverDSL( val portAllocation: PortAllocation, val debugPortAllocation: PortAllocation, - val baseDirectory: String, - val quasarJarPath: String + val baseDirectory: String ) : DriverDSLInternalInterface { override val networkMapCache = InMemoryNetworkMapCache() @@ -195,6 +191,15 @@ class DriverDSL( private var networkMapNodeInfo: NodeInfo? = null private val registeredProcesses = LinkedList() + //TODO: remove this once we can bundle quasar properly. + private val quasarJarPath: String by lazy { + val cl = ClassLoader.getSystemClassLoader() + val urls = (cl as URLClassLoader).urLs + val quasarPattern = ".*quasar.*\\.jar$".toRegex() + val quasarPath = urls.map { it.path }.first { quasarPattern.matches(it) } + quasarPath + } + val driverNodeConfiguration = NodeConfigurationFromConfig( NodeConfiguration.loadConfig( baseDirectoryPath = Paths.get(baseDirectory, "driver-artemis"), diff --git a/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt b/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt index 0e1ebc6b19..58d448e643 100644 --- a/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt +++ b/node/src/test/kotlin/com/r3corda/node/driver/DriverTests.kt @@ -1,6 +1,5 @@ package com.r3corda.node.driver -import com.google.common.net.HostAndPort import com.r3corda.core.node.NodeInfo import com.r3corda.core.node.services.NetworkMapCache import com.r3corda.node.services.api.RegulatorService @@ -10,7 +9,6 @@ import org.junit.Test class DriverTests { - companion object { fun nodeMustBeUp(networkMapCache: NetworkMapCache, nodeInfo: NodeInfo, nodeName: String) { val address = nodeInfo.address as ArtemisMessagingComponent.Address @@ -33,7 +31,7 @@ class DriverTests { @Test fun simpleNodeStartupShutdownWorks() { - val (notary, regulator) = driver(quasarJarPath = "../lib/quasar.jar") { + val (notary, regulator) = driver { val notary = startNode("TestNotary", setOf(NotaryService.Type)) val regulator = startNode("Regulator", setOf(RegulatorService.Type)) @@ -47,7 +45,7 @@ class DriverTests { @Test fun startingNodeWithNoServicesWorks() { - val noService = driver(quasarJarPath = "../lib/quasar.jar") { + val noService = driver { val noService = startNode("NoService") nodeMustBeUp(networkMapCache, noService, "NoService") noService @@ -57,7 +55,7 @@ class DriverTests { @Test fun randomFreePortAllocationWorks() { - val nodeInfo = driver(quasarJarPath = "../lib/quasar.jar", portAllocation = PortAllocation.RandomFree()) { + val nodeInfo = driver(portAllocation = PortAllocation.RandomFree()) { val nodeInfo = startNode("NoService") nodeMustBeUp(networkMapCache, nodeInfo, "NoService") nodeInfo