From b86a3c3d2c5a1c7c0c3af174b192f25038d9fe5b Mon Sep 17 00:00:00 2001 From: Khoi Nguyen Date: Fri, 14 Oct 2022 14:17:36 +0100 Subject: [PATCH 1/5] CORE-7135: Setup Jenkins Project * Added new .ci folder which contains Jenkins file for multibranch pipeline project --- .ci/Jenkinsfile | 8 ++++++++ .ci/nightly/JenkinsfileSnykScan | 6 ++++++ 2 files changed, 14 insertions(+) create mode 100644 .ci/Jenkinsfile create mode 100644 .ci/nightly/JenkinsfileSnykScan diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile new file mode 100644 index 0000000..8e0651c --- /dev/null +++ b/.ci/Jenkinsfile @@ -0,0 +1,8 @@ +@Library('corda-shared-build-pipeline-steps@5.0') _ + +cordaPipeline( + publishRepoPrefix: '', + slimBuild: true, + runUnitTests: false, + dedicatedJobForSnykDelta: false + ) diff --git a/.ci/nightly/JenkinsfileSnykScan b/.ci/nightly/JenkinsfileSnykScan new file mode 100644 index 0000000..c07efb7 --- /dev/null +++ b/.ci/nightly/JenkinsfileSnykScan @@ -0,0 +1,6 @@ +@Library('corda-shared-build-pipeline-steps@5.0') _ + +cordaSnykScanPipeline ( + snykTokenId: 'r3-snyk-corda5', + snykAdditionalCommands: "--all-sub-projects -d" +) From 8267ea597c1a7ebad4fe3908bb9126b7544011fb Mon Sep 17 00:00:00 2001 From: Chris Barratt Date: Mon, 17 Oct 2022 11:04:37 +0100 Subject: [PATCH 2/5] Set service members public for DP2 simulator --- .../java/com/r3/developers/csdetemplate/MyFirstFlow.java | 6 +++--- .../r3/developers/csdetemplate/MyFirstFlowResponder.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlow.java b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlow.java index 50d183a..0fcc95e 100644 --- a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlow.java +++ b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlow.java @@ -26,17 +26,17 @@ public class MyFirstFlow implements RPCStartableFlow { // JsonMarshallingService provides a Service for manipulating json @CordaInject - JsonMarshallingService jsonMarshallingService; + public JsonMarshallingService jsonMarshallingService; // FlowMessaging provides a service for establishing flow sessions between Virtual Nodes and // sending and receiving payloads between them @CordaInject - FlowMessaging flowMessaging; + public FlowMessaging flowMessaging; // MemberLookup provides a service for looking up information about members of the Virtual Network which // this CorDapp is operating in. @CordaInject - MemberLookup memberLookup; + public MemberLookup memberLookup; public MyFirstFlow() {} diff --git a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowResponder.java b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowResponder.java index 4e49f3b..de27380 100644 --- a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowResponder.java +++ b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowResponder.java @@ -23,7 +23,7 @@ public class MyFirstFlowResponder implements ResponderFlow { // MemberLookup provides a service for looking up information about members of the Virtual Network which // this CorDapp is operating in. @CordaInject - MemberLookup memberLookup; + public MemberLookup memberLookup; public MyFirstFlowResponder() {} From 8e6081875b6294b3a288be3a4bb152cab2a3099a Mon Sep 17 00:00:00 2001 From: Chris Barratt Date: Mon, 17 Oct 2022 17:01:27 +0100 Subject: [PATCH 3/5] Final message classes, removal of unneeded deps, initial pass over docs --- build.gradle | 41 ------------------- .../r3/developers/csdetemplate/Message.java | 6 +-- .../developers/csdetemplate/MyFirstFlow.java | 4 +- .../csdetemplate/MyFirstFlowResponder.java | 8 ++-- .../csdetemplate/MyFirstFlowStartArgs.java | 10 +---- .../csdetemplate/MyFirstFlowTest.java | 1 - 6 files changed, 11 insertions(+), 59 deletions(-) diff --git a/build.gradle b/build.gradle index bd29e7b..5b50cbd 100644 --- a/build.gradle +++ b/build.gradle @@ -45,36 +45,6 @@ cordapp { } } -/* -// Declare the set of Kotlin compiler options we need to build a CorDapp. -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { - kotlinOptions { - allWarningsAsErrors = false - - // Specify the version of Kotlin that we are that we will be developing. - languageVersion = '1.7' - // Specify the Kotlin libraries that code is compatible with - apiVersion = '1.7' - // Note that we Need to use a version of Kotlin that will be compatible with the Corda API. - // Currently that is developed in Kotlin 1.7 so picking the same version ensures compatibility with that. - - // Specify the version of Java to target. - jvmTarget = javaVersion - - // Needed for reflection to work correctly. - javaParameters = true - - // -Xjvm-default determines how Kotlin supports default methods. - // JetBrains currently recommends developers use -Xjvm-default=all - // https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-default/ - freeCompilerArgs += [ - "-Xjvm-default=all" - ] - } -} - - */ - // Declare the set of Kotlin compiler options we need to build a CorDapp. tasks.withType(JavaCompile) { @@ -84,8 +54,6 @@ tasks.withType(JavaCompile) { ] } - - repositories { // All dependencies are held in Maven Central mavenCentral() @@ -95,13 +63,6 @@ repositories { // A cordaProvided declaration is required for anything that we use that the Corda API provides. // This is required to allow us to build CorDapp modules as OSGi bundles that CPI and CPB files are built on. dependencies { - // We need a version of kotlin-stdlib-jdk8 built as an OSGi bundle, this is "kotlin-stdlib-jdk8-osgi". - // R3 builds kotlin-stdlib-jdk8-osgi from Kotlin's kotlin-stdlib-jdk8. - // NB: - // Kotlin's kotlin-osgi-bundle does not provide all of the Kotlin API that is required, - // There is no kotlin-stdlib-jdk11, but one is not needed even though we are targetting Java 11. - cordaProvided 'net.corda.kotlin:kotlin-stdlib-jdk8-osgi' - // Declare a "platform" so that we use the correct set of dependency versions for the version of the // Corda API specified. cordaProvided platform("net.corda:corda-api:$cordaApiVersion") @@ -135,9 +96,7 @@ dependencies { // Optional but used by exmaple tests. testImplementation "org.mockito:mockito-core:$mockitoVersion" - testImplementation "org.mockito.kotlin:mockito-kotlin:$mockitoKotlinVersion" testImplementation "org.hamcrest:hamcrest-library:$hamcrestVersion" - } diff --git a/src/main/java/com/r3/developers/csdetemplate/Message.java b/src/main/java/com/r3/developers/csdetemplate/Message.java index a7109ef..4ca6092 100644 --- a/src/main/java/com/r3/developers/csdetemplate/Message.java +++ b/src/main/java/com/r3/developers/csdetemplate/Message.java @@ -3,15 +3,15 @@ package com.r3.developers.csdetemplate; import net.corda.v5.base.annotations.CordaSerializable; import net.corda.v5.base.types.MemberX500Name; -// // A class which will contain a message, It must be marked with @CordaSerializable for Corda -//// to be able to send from one virtual node to another. +// A class which will contain a message, It must be marked with @CordaSerializable for Corda +// to be able to send from one virtual node to another. @CordaSerializable public class Message { - // public Message() {} public Message(MemberX500Name sender, String message) { this.sender = sender; this.message = message; } + public MemberX500Name getSender() { return sender; } diff --git a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlow.java b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlow.java index 0fcc95e..ffcc434 100644 --- a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlow.java +++ b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlow.java @@ -14,7 +14,7 @@ import org.slf4j.LoggerFactory; // MyFirstFlow is an initiating flow, it's corresponding responder flow is called MyFirstFlowResponder (defined below) // to link the two sides of the flow together they need to have the same protocol. -@InitiatingFlow(protocol = "another-flow") +@InitiatingFlow(protocol = "my-first-flow") // MyFirstFlow should inherit from RPCStartableFlow, which tells Corda it can be started via an RPC call public class MyFirstFlow implements RPCStartableFlow { @@ -40,7 +40,7 @@ public class MyFirstFlow implements RPCStartableFlow { public MyFirstFlow() {} - // When a flow is invoked it's call() method is called. + // When a flow is invoked its call() method is called. // call() methods must be marked as @Suspendable, this allows Corda to pause mid-execution to wait // for a response from the other flows and services @NotNull diff --git a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowResponder.java b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowResponder.java index de27380..43f6075 100644 --- a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowResponder.java +++ b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowResponder.java @@ -11,9 +11,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -// MyFirstFlowResponder is a responder flow, it's corresponding initiating flow is called MyFirstFlow (defined above) +// MyFirstFlowResponder is a responder flow, it's corresponding initiating flow is called MyFirstFlow (defined in MyFirstFlow.java) // to link the two sides of the flow together they need to have the same protocol. -@InitiatedBy(protocol = "another-flow") +@InitiatedBy(protocol = "my-first-flow") // Responder flows must inherit from ResponderFlow public class MyFirstFlowResponder implements ResponderFlow { @@ -28,9 +28,9 @@ public class MyFirstFlowResponder implements ResponderFlow { public MyFirstFlowResponder() {} // Responder flows are invoked when an initiating flow makes a call via a session set up with the Virtual - // node hosting the Responder flow. When a responder flow is invoked it's call() method is called. + // node hosting the Responder flow. When a responder flow is invoked its call() method is called. // call() methods must be marked as @Suspendable, this allows Corda to pause mid-execution to wait - // for a response from the other flows and services/ + // for a response from the other flows and services. // The Call method has the flow session passed in as a parameter by Corda so the session is available to // responder flow code, you don't need to inject the FlowMessaging service. @Suspendable diff --git a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowStartArgs.java b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowStartArgs.java index 1867875..2229518 100644 --- a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowStartArgs.java +++ b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowStartArgs.java @@ -2,20 +2,14 @@ package com.r3.developers.csdetemplate; import net.corda.v5.base.types.MemberX500Name; -// // A class to hold the arguments required to start the flow -//class MyFirstFlowStartArgs(val otherMember: MemberX500Name) +// A class to hold the arguments required to start the flow public class MyFirstFlowStartArgs { public MemberX500Name otherMember; - public MemberX500Name getOtherMember() { - return otherMember; - } - public MyFirstFlowStartArgs(MemberX500Name otherMember) { this.otherMember = otherMember; } - // Without the following we get - // "Cannot construct instance of `com.r3.developers.csdetemplate.MyFirstFlowStartArgs` (no Creators, like default constructor, exist): cannot deserialize from Object value (no delegate- or property-based Creator)\n at [Source: (String)\"{\"otherMember\":\"CN=Bob, OU=Test Dept, O=R3, L=London, C=GB\"}\"; line: 1, column: 2]" + // The JSON Marshalling Service, that handles serialisation, needs this constructor. public MyFirstFlowStartArgs() {} } diff --git a/src/test/java/com/r3/developers/csdetemplate/MyFirstFlowTest.java b/src/test/java/com/r3/developers/csdetemplate/MyFirstFlowTest.java index 1aa828f..31305a0 100644 --- a/src/test/java/com/r3/developers/csdetemplate/MyFirstFlowTest.java +++ b/src/test/java/com/r3/developers/csdetemplate/MyFirstFlowTest.java @@ -1,6 +1,5 @@ package com.r3.developers.csdetemplate; - import net.corda.simulator.HoldingIdentity; import net.corda.simulator.RequestData; import net.corda.simulator.SimulatedVirtualNode; From 7062445a2ee95a65d719bd94331395a0a59cd981 Mon Sep 17 00:00:00 2001 From: Chris Barratt Date: Tue, 18 Oct 2022 09:44:25 +0100 Subject: [PATCH 4/5] Finished tweaking comments --- build.gradle | 4 ++-- .../com/r3/developers/csdetemplate/MyFirstFlowResponder.java | 2 +- .../com/r3/developers/csdetemplate/MyFirstFlowStartArgs.java | 2 +- .../java/com/r3/developers/csdetemplate/MyFirstFlowTest.java | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 5b50cbd..ff011d9 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { id 'org.jetbrains.kotlin.jvm' // Include the cordapp-cpb plugin. This automatically includes the cordapp-cpk plugin as well. - // These extend existing build environment so that CPB and CPK files can be built. + // These extend the existing build environment so that CPB and CPK files can be built. // This includes a CorDapp DSL that allows the developer to supply metadata for the CorDapp // required by Corda. id 'net.corda.plugins.cordapp-cpb2' @@ -67,7 +67,7 @@ dependencies { // Corda API specified. cordaProvided platform("net.corda:corda-api:$cordaApiVersion") - // If using transistive dependencies this will provide most of Corda-API: + // If using transistive dependencies this will provide most of the Corda-API: // cordaProvided 'net.corda:corda-application' // Alternatively we can explicitly specify all our Corda-API dependencies: diff --git a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowResponder.java b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowResponder.java index 43f6075..d7fba74 100644 --- a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowResponder.java +++ b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowResponder.java @@ -11,7 +11,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -// MyFirstFlowResponder is a responder flow, it's corresponding initiating flow is called MyFirstFlow (defined in MyFirstFlow.java) +// MyFirstFlowResponder is a responder flow, its corresponding initiating flow is called MyFirstFlow (defined in MyFirstFlow.java) // to link the two sides of the flow together they need to have the same protocol. @InitiatedBy(protocol = "my-first-flow") // Responder flows must inherit from ResponderFlow diff --git a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowStartArgs.java b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowStartArgs.java index 2229518..4c5f2ff 100644 --- a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowStartArgs.java +++ b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlowStartArgs.java @@ -10,6 +10,6 @@ public class MyFirstFlowStartArgs { this.otherMember = otherMember; } - // The JSON Marshalling Service, that handles serialisation, needs this constructor. + // The JSON Marshalling Service, which handles serialisation, needs this constructor. public MyFirstFlowStartArgs() {} } diff --git a/src/test/java/com/r3/developers/csdetemplate/MyFirstFlowTest.java b/src/test/java/com/r3/developers/csdetemplate/MyFirstFlowTest.java index 31305a0..925ae5c 100644 --- a/src/test/java/com/r3/developers/csdetemplate/MyFirstFlowTest.java +++ b/src/test/java/com/r3/developers/csdetemplate/MyFirstFlowTest.java @@ -25,7 +25,7 @@ class MyFirstFlowTest { HoldingIdentity bobHoldingID = HoldingIdentity.Companion.create(bobX500); // Create Alice and Bob's virtual nodes, including the Class's of the flows which will be registered on each node. - // We don't assign Bob's virtual node to a val because we don't need it for this particular test. + // We don't assign Bob's virtual node to a variable because we don't need it for this particular test. SimulatedVirtualNode aliceVN = simulator.createVirtualNode(aliceHoldingID, MyFirstFlow.class); simulator.createVirtualNode(bobHoldingID, MyFirstFlowResponder.class); @@ -35,7 +35,7 @@ class MyFirstFlowTest { // Create a requestData object RequestData requestData = RequestData.Companion.create( "request no 1", // A unique reference for the instance of the flow request - MyFirstFlow.class, // The name of the flow class which is to be started + MyFirstFlow.class, // The name of the flow class which is to be started myFirstFlowStartArgs // The object which contains the start arguments of the flow ); From 2bcc9d6fb5cd7430e041014604a4eda287ec4acf Mon Sep 17 00:00:00 2001 From: Chris Barratt Date: Wed, 19 Oct 2022 01:14:28 +0100 Subject: [PATCH 5/5] Suppress varargs unchecked warning, remove unnecessary NotNull annotation --- src/main/java/com/r3/developers/csdetemplate/MyFirstFlow.java | 2 +- .../java/com/r3/developers/csdetemplate/MyFirstFlowTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlow.java b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlow.java index ffcc434..21321c6 100644 --- a/src/main/java/com/r3/developers/csdetemplate/MyFirstFlow.java +++ b/src/main/java/com/r3/developers/csdetemplate/MyFirstFlow.java @@ -46,7 +46,7 @@ public class MyFirstFlow implements RPCStartableFlow { @NotNull @Suspendable @Override - public String call(@NotNull RPCRequestData requestBody) { + public String call(RPCRequestData requestBody) { // Useful logging to follow what's happening in the console or logs log.info("MFF: MyFirstFlow.call() called"); diff --git a/src/test/java/com/r3/developers/csdetemplate/MyFirstFlowTest.java b/src/test/java/com/r3/developers/csdetemplate/MyFirstFlowTest.java index 925ae5c..e343318 100644 --- a/src/test/java/com/r3/developers/csdetemplate/MyFirstFlowTest.java +++ b/src/test/java/com/r3/developers/csdetemplate/MyFirstFlowTest.java @@ -15,8 +15,8 @@ class MyFirstFlowTest { private MemberX500Name bobX500 = MemberX500Name.parse("CN=Bob, OU=Test Dept, O=R3, L=London, C=GB"); @Test + @SuppressWarnings("unchecked") public void test_that_MyFirstFLow_returns_correct_message() { - // Instantiate an instance of the Simulator Simulator simulator = new Simulator();