diff --git a/constants.properties b/constants.properties index cc931afe3c..1c67578704 100644 --- a/constants.properties +++ b/constants.properties @@ -1,4 +1,4 @@ -gradlePluginsVersion=4.0.11 +gradlePluginsVersion=4.0.12 kotlinVersion=1.2.20 platformVersion=4 guavaVersion=21.0 diff --git a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappConfigFileProvider.kt b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappConfigFileProvider.kt index 921b67f98a..81daea5504 100644 --- a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappConfigFileProvider.kt +++ b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappConfigFileProvider.kt @@ -2,7 +2,6 @@ package net.corda.node.internal.cordapp import com.typesafe.config.Config import com.typesafe.config.ConfigFactory -import net.corda.core.internal.cordapp.CordappConfigProvider import net.corda.core.utilities.loggerFor import java.io.File diff --git a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappConfigProvider.kt b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappConfigProvider.kt index f632481d1c..94553da3ad 100644 --- a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappConfigProvider.kt +++ b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappConfigProvider.kt @@ -1,4 +1,4 @@ -package net.corda.core.internal.cordapp +package net.corda.node.internal.cordapp import com.typesafe.config.Config diff --git a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappProviderImpl.kt b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappProviderImpl.kt index 06efde8cd7..0ea56b1900 100644 --- a/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappProviderImpl.kt +++ b/node/src/main/kotlin/net/corda/node/internal/cordapp/CordappProviderImpl.kt @@ -7,7 +7,6 @@ import net.corda.core.cordapp.Cordapp import net.corda.core.cordapp.CordappContext import net.corda.core.crypto.SecureHash import net.corda.core.internal.DEPLOYED_CORDAPP_UPLOADER -import net.corda.core.internal.cordapp.CordappConfigProvider import net.corda.core.internal.createCordappContext import net.corda.core.node.services.AttachmentId import net.corda.core.node.services.AttachmentStorage diff --git a/node/src/test/kotlin/net/corda/node/internal/cordapp/CordappProviderImplTests.kt b/node/src/test/kotlin/net/corda/node/internal/cordapp/CordappProviderImplTests.kt index ebfb3795b2..1a9e2a4951 100644 --- a/node/src/test/kotlin/net/corda/node/internal/cordapp/CordappProviderImplTests.kt +++ b/node/src/test/kotlin/net/corda/node/internal/cordapp/CordappProviderImplTests.kt @@ -2,15 +2,12 @@ package net.corda.node.internal.cordapp import com.typesafe.config.Config import com.typesafe.config.ConfigFactory -import junit.framework.Assert.assertNull -import net.corda.core.internal.cordapp.CordappConfigProvider import net.corda.core.node.services.AttachmentStorage import net.corda.testing.common.internal.testNetworkParameters import net.corda.testing.internal.MockCordappConfigProvider import net.corda.testing.services.MockAttachmentStorage import org.assertj.core.api.Assertions.assertThat -import org.junit.Assert.assertEquals -import org.junit.Assert.assertNotNull +import org.junit.Assert.* import org.junit.Before import org.junit.Test import java.net.URL @@ -19,9 +16,9 @@ class CordappProviderImplTests { private companion object { val isolatedJAR = this::class.java.getResource("isolated.jar")!! // TODO: Cordapp name should differ from the JAR name - val isolatedCordappName = "isolated" + const val isolatedCordappName = "isolated" val emptyJAR = this::class.java.getResource("empty.jar")!! - val validConfig = ConfigFactory.parseString("key=value") + val validConfig: Config = ConfigFactory.parseString("key=value") val stubConfigProvider = object : CordappConfigProvider { override fun getConfigByName(name: String): Config = ConfigFactory.empty() @@ -77,7 +74,7 @@ class CordappProviderImplTests { @Test fun `test cordapp configuration`() { val configProvider = MockCordappConfigProvider() - configProvider.cordappConfigs.put(isolatedCordappName, validConfig) + configProvider.cordappConfigs[isolatedCordappName] = validConfig val loader = CordappLoader.createDevMode(listOf(isolatedJAR)) val provider = CordappProviderImpl(loader, configProvider, attachmentStore, whitelistedContractImplementations) diff --git a/samples/cordapp-configuration/README.md b/samples/cordapp-configuration/README.md index 651e8debc9..e8e35b8291 100644 --- a/samples/cordapp-configuration/README.md +++ b/samples/cordapp-configuration/README.md @@ -6,18 +6,18 @@ This sample shows a simple example of how to use per-cordapp configuration. It i * Gradle build file to show how to install your Cordapp configuration * A flow that consumes the Cordapp configuration -## Usage +To run from the command line in Unix: -To run the sample you must first build it from the project root with; +1. Run ``./gradlew samples:cordapp-configuration:deployNodes`` to create a set of configs and installs under + ``samples/cordapp-configuration/build/nodes`` +2. Run ``./samples/cordapp-configuration/build/nodes/runnodes`` to open up three new terminals with the three nodes +3. At the shell prompt for Bank A or Bank B run ``start net.corda.configsample.GetStringConfigFlow configKey: someStringValue``. + This will start the flow and read the `someStringValue` CorDapp config. - ./gradlew deployNodes - -This will deploy the node with the configuration installed. -The relevant section is the ``deployNodes`` task. +To run from the command line in Windows: -## Running - -* Windows: `build\nodes\runnodes` -* Mac/Linux: `./build/nodes/runnodes` - -Once the nodes have started up and show a prompt you can now run your flow. \ No newline at end of file +1. Run ``gradlew samples:cordapp-configuration:deployNodes`` to create a set of configs and installs under + ``samples\cordapp-configuration\build\nodes`` +2. Run ``samples\cordapp-configuration\build\nodes\runnodes`` to open up three new terminals with the three nodes +3. At the shell prompt for Bank A or Bank B run ``start net.corda.configsample.GetStringConfigFlow configKey: someStringValue``. + This will start the flow and read the `someStringValue` CorDapp config. diff --git a/samples/cordapp-configuration/src/main/kotlin/net/corda/configsample/ConfigSampleFlow.kt b/samples/cordapp-configuration/src/main/kotlin/net/corda/configsample/ConfigSampleFlow.kt deleted file mode 100644 index 251830f538..0000000000 --- a/samples/cordapp-configuration/src/main/kotlin/net/corda/configsample/ConfigSampleFlow.kt +++ /dev/null @@ -1,10 +0,0 @@ -package net.corda.configsample - -import net.corda.core.flows.FlowLogic - -class ConfigSampleFlow : FlowLogic() { - override fun call(): String { - val config = serviceHub.getAppContext().config - return config.getString("someStringValue") - } -} \ No newline at end of file diff --git a/samples/cordapp-configuration/src/main/kotlin/net/corda/configsample/GetStringConfigFlow.kt b/samples/cordapp-configuration/src/main/kotlin/net/corda/configsample/GetStringConfigFlow.kt new file mode 100644 index 0000000000..7fbbaeff77 --- /dev/null +++ b/samples/cordapp-configuration/src/main/kotlin/net/corda/configsample/GetStringConfigFlow.kt @@ -0,0 +1,19 @@ +package net.corda.configsample + +import co.paralleluniverse.fibers.Suspendable +import net.corda.core.flows.FlowLogic +import net.corda.core.flows.StartableByRPC +import net.corda.core.utilities.ProgressTracker + +@StartableByRPC +class GetStringConfigFlow(private val configKey: String) : FlowLogic() { + object READING : ProgressTracker.Step("Reading config") + override val progressTracker = ProgressTracker(READING) + + @Suspendable + override fun call(): String { + progressTracker.currentStep = READING + val config = serviceHub.getAppContext().config + return config.getString(configKey) + } +} diff --git a/testing/test-utils/src/main/kotlin/net/corda/testing/internal/MockCordappConfigProvider.kt b/testing/test-utils/src/main/kotlin/net/corda/testing/internal/MockCordappConfigProvider.kt index 6f2f99cfa8..50f2ae24aa 100644 --- a/testing/test-utils/src/main/kotlin/net/corda/testing/internal/MockCordappConfigProvider.kt +++ b/testing/test-utils/src/main/kotlin/net/corda/testing/internal/MockCordappConfigProvider.kt @@ -2,7 +2,7 @@ package net.corda.testing.internal import com.typesafe.config.Config import com.typesafe.config.ConfigFactory -import net.corda.core.internal.cordapp.CordappConfigProvider +import net.corda.node.internal.cordapp.CordappConfigProvider class MockCordappConfigProvider : CordappConfigProvider { val cordappConfigs = mutableMapOf ()