diff --git a/node/src/main/kotlin/net/corda/node/internal/cordapp/JarScanningCordappLoader.kt b/node/src/main/kotlin/net/corda/node/internal/cordapp/JarScanningCordappLoader.kt index a433aea27c..345876741e 100644 --- a/node/src/main/kotlin/net/corda/node/internal/cordapp/JarScanningCordappLoader.kt +++ b/node/src/main/kotlin/net/corda/node/internal/cordapp/JarScanningCordappLoader.kt @@ -144,7 +144,7 @@ class JarScanningCordappLoader private constructor(private val cordappJarPaths: findServiceFlows(this), findSchedulableFlows(this), findServices(this), - findPlugins(url), + findWhitelists(url), findSerializers(this), findCustomSchemas(this), findAllFlows(this), @@ -267,7 +267,7 @@ class JarScanningCordappLoader private constructor(private val cordappJarPaths: return contractClasses } - private fun findPlugins(cordappJarPath: RestrictedURL): List { + private fun findWhitelists(cordappJarPath: RestrictedURL): List { val whitelists = URLClassLoader(arrayOf(cordappJarPath.url)).use { ServiceLoader.load(SerializationWhitelist::class.java, it).toList() } @@ -306,6 +306,7 @@ class JarScanningCordappLoader private constructor(private val cordappJarPaths: } } + // TODO Remove this class as rootPackageName is never non-null. /** @property rootPackageName only this package and subpackages may be extracted from [url], or null to allow all packages. */ private data class RestrictedURL(val url: URL, val rootPackageName: String?) { val qualifiedNamePrefix: String get() = rootPackageName?.let { "$it." } ?: "" @@ -359,14 +360,14 @@ class JarScanningCordappLoader private constructor(private val cordappJarPaths: fun getAllStandardClasses(): List { return scanResult - .getAllStandardClasses() + .allStandardClasses .names .filter { it.startsWith(qualifiedNamePrefix) } } fun getAllInterfaces(): List { return scanResult - .getAllInterfaces() + .allInterfaces .names .filter { it.startsWith(qualifiedNamePrefix) } } @@ -400,13 +401,14 @@ abstract class CordappLoaderTemplate : CordappLoader { logger.error("There are multiple CorDapp JARs on the classpath for flow " + "${entry.value.first().first.name}: [ ${entry.value.joinToString { it.second.jarPath.toString() }} ].") entry.value.forEach { (_, cordapp) -> - val zip = ZipInputStream(cordapp.jarPath.openStream()) - val ident = BigInteger(64, Random()).toString(36) - logger.error("Contents of: ${cordapp.jarPath} will be prefaced with: ${ident}") - var e = zip.nextEntry - while (e != null) { - logger.error("$ident\t ${e.name}") - e = zip.nextEntry + ZipInputStream(cordapp.jarPath.openStream()).use { zip -> + val ident = BigInteger(64, Random()).toString(36) + logger.error("Contents of: ${cordapp.jarPath} will be prefaced with: $ident") + var e = zip.nextEntry + while (e != null) { + logger.error("$ident\t ${e.name}") + e = zip.nextEntry + } } } throw MultipleCordappsForFlowException("There are multiple CorDapp JARs on the classpath for flow " + diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/TestCordappInternal.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/TestCordappInternal.kt index 1a14b28000..3380c37b5d 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/TestCordappInternal.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/TestCordappInternal.kt @@ -6,8 +6,8 @@ import net.corda.core.internal.createDirectories import net.corda.core.internal.div import net.corda.core.internal.writeText import net.corda.testing.node.TestCordapp +import java.nio.file.FileAlreadyExistsException import java.nio.file.Path -import java.nio.file.StandardCopyOption.REPLACE_EXISTING /** * Extends the public [TestCordapp] API with internal extensions for use within the testing framework and for internal testing of the platform. @@ -36,7 +36,11 @@ abstract class TestCordappInternal : TestCordapp() { val configDir = (cordappsDir / "config").createDirectories() jarToCordapp.forEach { jar, cordapp -> - jar.copyToDirectory(cordappsDir, REPLACE_EXISTING) + try { + jar.copyToDirectory(cordappsDir) + } catch (e: FileAlreadyExistsException) { + // Ignore if the node already has the same CorDapp jar. This can happen if the node is being restarted. + } val configString = ConfigValueFactory.fromMap(cordapp.config).toConfig().root().render() (configDir / "${jar.fileName.toString().removeSuffix(".jar")}.conf").writeText(configString) }