From e5a8888232ae087ec69a1ba9d26441114860024c Mon Sep 17 00:00:00 2001 From: Rick Parker Date: Thu, 5 Mar 2020 17:39:55 +0000 Subject: [PATCH] CORDA-3644: Add Corda-Testing tag to test artifacts' MANIFEST.MF. (#6032) --- client/mock/build.gradle | 8 ++++++- .../dbfailure/dbfcontracts/build.gradle | 7 ++++++- .../dbfailure/dbfworkflows/build.gradle | 7 ++++++- testing/node-driver/build.gradle | 5 +++++ .../testing/node/internal/DriverDSLImpl.kt | 21 +++++++++++++++---- testing/smoke-test-utils/build.gradle | 8 +++++++ testing/test-cli/build.gradle | 10 +++++---- testing/test-common/build.gradle | 5 +++++ testing/test-db/build.gradle | 5 +++++ testing/test-utils/build.gradle | 5 +++++ 10 files changed, 70 insertions(+), 11 deletions(-) diff --git a/client/mock/build.gradle b/client/mock/build.gradle index 3cebd33402..712ada2bf1 100644 --- a/client/mock/build.gradle +++ b/client/mock/build.gradle @@ -29,7 +29,13 @@ dependencies { jar { baseName 'corda-mock' manifest { - attributes 'Automatic-Module-Name': 'net.corda.client.mock' + attributes( + 'Automatic-Module-Name': 'net.corda.client.mock', + + // This JAR is part of Corda's testing framework. + // Driver will not include it as part of an out-of-process node. + 'Corda-Testing': true + ) } } diff --git a/testing/cordapps/dbfailure/dbfcontracts/build.gradle b/testing/cordapps/dbfailure/dbfcontracts/build.gradle index 76dd8b8082..8767f08a31 100644 --- a/testing/cordapps/dbfailure/dbfcontracts/build.gradle +++ b/testing/cordapps/dbfailure/dbfcontracts/build.gradle @@ -13,6 +13,11 @@ dependencies { compile project(":core") } -jar{ +jar { baseName "testing-dbfailure-contracts" + manifest { + // This JAR is part of Corda's testing framework. + // Driver will not include it as part of an out-of-process node. + attributes('Corda-Testing': true) + } } \ No newline at end of file diff --git a/testing/cordapps/dbfailure/dbfworkflows/build.gradle b/testing/cordapps/dbfailure/dbfworkflows/build.gradle index 571a3cb3a5..26e0058cc5 100644 --- a/testing/cordapps/dbfailure/dbfworkflows/build.gradle +++ b/testing/cordapps/dbfailure/dbfworkflows/build.gradle @@ -7,6 +7,11 @@ dependencies { compile project(":testing:cordapps:dbfailure:dbfcontracts") } -jar{ +jar { baseName "testing-dbfailure-workflows" + manifest { + // This JAR is part of Corda's testing framework. + // Driver will not include it as part of an out-of-process node. + attributes('Corda-Testing': true) + } } \ No newline at end of file diff --git a/testing/node-driver/build.gradle b/testing/node-driver/build.gradle index 152abc037d..02664e0a38 100644 --- a/testing/node-driver/build.gradle +++ b/testing/node-driver/build.gradle @@ -66,6 +66,11 @@ task integrationTest(type: Test) { jar { baseName 'corda-node-driver' + manifest { + // This JAR is part of Corda's testing framework. + // Driver will not include it as part of an out-of-process node. + attributes('Corda-Testing': true) + } } publish { diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt index c3c5037470..744f455c6b 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/DriverDSLImpl.kt @@ -1,3 +1,4 @@ +@file:Suppress("TooManyFunctions") package net.corda.testing.node.internal import co.paralleluniverse.fibers.instrument.JavaAgent @@ -112,6 +113,7 @@ import java.util.concurrent.TimeUnit import java.util.concurrent.TimeoutException import java.util.concurrent.atomic.AtomicInteger import java.util.jar.JarInputStream +import java.util.jar.Manifest import kotlin.collections.ArrayList import kotlin.collections.HashMap import kotlin.collections.HashSet @@ -806,6 +808,8 @@ class DriverDSLImpl( Permissions.invokeRpc(CordaRPCOps::killFlow) ) + private const val CORDA_TESTING_ATTRIBUTE = "Corda-Testing" + private val CORDAPP_MANIFEST_ATTRIBUTES: List = unmodifiableList(listOf( CORDAPP_CONTRACT_NAME, CORDAPP_CONTRACT_LICENCE, @@ -952,7 +956,7 @@ class DriverDSLImpl( val cpPathEntry = Paths.get(cpEntry) cpPathEntry.isRegularFile() && !isTestArtifact(cpPathEntry.fileName.toString()) - && !cpPathEntry.isCorDapp + && !cpPathEntry.isExcludedJar } return ProcessUtilities.startJavaProcess( @@ -980,12 +984,21 @@ class DriverDSLImpl( || name.startsWith("mockito") } + // Identify Corda's own testing framework by attribute in MANIFEST.MF. + private fun isTestArtifact(manifest: Manifest): Boolean { + return manifest[CORDA_TESTING_ATTRIBUTE] != null + } + // Identify CorDapp JARs by their attributes in MANIFEST.MF. - private val Path.isCorDapp: Boolean get() { + private fun isCordapp(manifest: Manifest): Boolean { + return CORDAPP_MANIFEST_ATTRIBUTES.any { manifest[it] != null } + || (manifest[TARGET_PLATFORM_VERSION] != null && manifest[MIN_PLATFORM_VERSION] != null) + } + + private val Path.isExcludedJar: Boolean get() { return JarInputStream(Files.newInputStream(this).buffered()).use { jar -> val manifest = jar.manifest ?: return false - CORDAPP_MANIFEST_ATTRIBUTES.any { manifest[it] != null } - || (manifest[TARGET_PLATFORM_VERSION] != null && manifest[MIN_PLATFORM_VERSION] != null) + isCordapp(manifest) || isTestArtifact(manifest) } } diff --git a/testing/smoke-test-utils/build.gradle b/testing/smoke-test-utils/build.gradle index 0868951903..0a1023a061 100644 --- a/testing/smoke-test-utils/build.gradle +++ b/testing/smoke-test-utils/build.gradle @@ -7,3 +7,11 @@ dependencies { compile project(':test-common') compile project(':client:rpc') } + +tasks.named('jar', Jar) { + manifest { + // This JAR is part of Corda's testing framework. + // Driver will not include it as part of an out-of-process node. + attributes('Corda-Testing': true) + } +} \ No newline at end of file diff --git a/testing/test-cli/build.gradle b/testing/test-cli/build.gradle index ac45c22be9..a668c605f4 100644 --- a/testing/test-cli/build.gradle +++ b/testing/test-cli/build.gradle @@ -14,10 +14,12 @@ dependencies { testRuntimeOnly "org.junit.vintage:junit-vintage-engine:${junit_vintage_version}" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_jupiter_version}" testRuntimeOnly "org.junit.platform:junit-platform-launcher:${junit_platform_version}" - } -compileKotlin { - kotlinOptions { - languageVersion = "1.2" + +tasks.named('jar', Jar) { + manifest { + // This JAR is part of Corda's testing framework. + // Driver will not include it as part of an out-of-process node. + attributes('Corda-Testing': true) } } \ No newline at end of file diff --git a/testing/test-common/build.gradle b/testing/test-common/build.gradle index f522d75d40..f3d667e49a 100644 --- a/testing/test-common/build.gradle +++ b/testing/test-common/build.gradle @@ -25,6 +25,11 @@ dependencies { jar { baseName 'corda-test-common' + manifest { + // This JAR is part of Corda's testing framework. + // Driver will not include it as part of an out-of-process node. + attributes('Corda-Testing': true) + } } publish { diff --git a/testing/test-db/build.gradle b/testing/test-db/build.gradle index f4e906addb..3be30d52fe 100644 --- a/testing/test-db/build.gradle +++ b/testing/test-db/build.gradle @@ -16,6 +16,11 @@ dependencies { jar { baseName 'corda-test-db' + manifest { + // This JAR is part of Corda's testing framework. + // Driver will not include it as part of an out-of-process node. + attributes('Corda-Testing': true) + } } publish { diff --git a/testing/test-utils/build.gradle b/testing/test-utils/build.gradle index 797c607c70..f8a85f6607 100644 --- a/testing/test-utils/build.gradle +++ b/testing/test-utils/build.gradle @@ -36,6 +36,11 @@ dependencies { jar { baseName 'corda-test-utils' + manifest { + // This JAR is part of Corda's testing framework. + // Driver will not include it as part of an out-of-process node. + attributes('Corda-Testing': true) + } } publish {