From c50fd5e07ec5d33389fa6c074a1ff94501250216 Mon Sep 17 00:00:00 2001 From: Chris Rankin <chris.rankin@r3.com> Date: Fri, 29 Jun 2018 12:22:18 +0100 Subject: [PATCH] ENT-1903: Remove fast-classpath-scanner from serialization-deterministic. (#3471) --- serialization-deterministic/build.gradle | 1 - .../internal/amqp/AMQPSerializationScheme.kt | 18 +++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/serialization-deterministic/build.gradle b/serialization-deterministic/build.gradle index 97ef9f7076..54530bad3e 100644 --- a/serialization-deterministic/build.gradle +++ b/serialization-deterministic/build.gradle @@ -22,7 +22,6 @@ dependencies { // Configure these by hand. It should be a minimal subset of dependencies, // and without any obviously non-deterministic ones such as Hibernate. runtimeLibraries project(path: ':core-deterministic', configuration: 'runtimeArtifacts') - runtimeLibraries "io.github.lukehutch:fast-classpath-scanner:$fast_classpath_scanner_version" runtimeLibraries "org.apache.qpid:proton-j:$protonj_version" runtimeLibraries "org.iq80.snappy:snappy:$snappy_version" } diff --git a/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/AMQPSerializationScheme.kt b/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/AMQPSerializationScheme.kt index 6a38e9c0f1..f47a106a33 100644 --- a/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/AMQPSerializationScheme.kt +++ b/serialization/src/main/kotlin/net/corda/serialization/internal/amqp/AMQPSerializationScheme.kt @@ -44,9 +44,8 @@ abstract class AbstractAMQPSerializationScheme( constructor(cordapps: List<Cordapp>) : this(cordapps.customSerializers, ConcurrentHashMap()) // TODO: This method of initialisation for the Whitelist and plugin serializers will have to change - // when we have per-cordapp contexts and dynamic app reloading but for now it's the easiest way + // when we have per-cordapp contexts and dynamic app reloading but for now it's the easiest way companion object { - const val SCAN_SPEC_PROP_NAME = "amqp.custom.serialization.scanSpec" private val serializationWhitelists: List<SerializationWhitelist> by lazy { @@ -54,25 +53,30 @@ abstract class AbstractAMQPSerializationScheme( } private val customSerializers: List<SerializationCustomSerializer<*, *>> by lazy { - val scanSpec: String? = System.getProperty(SCAN_SPEC_PROP_NAME) if (scanSpec == null) { emptyList() } else { - FastClasspathScanner(scanSpec).addClassLoader(this::class.java.classLoader).scan() + scanClasspathForSerializers(scanSpec) + } + } + + @StubOutForDJVM + private fun scanClasspathForSerializers(scanSpec: String): List<SerializationCustomSerializer<*, *>> = + this::class.java.classLoader.let { cl -> + FastClasspathScanner(scanSpec).addClassLoader(cl).scan() .getNamesOfClassesImplementing(SerializationCustomSerializer::class.java) - .mapNotNull { this::class.java.classLoader.loadClass(it).asSubclass(SerializationCustomSerializer::class.java) } + .map { cl.loadClass(it).asSubclass(SerializationCustomSerializer::class.java) } .filterNot { Modifier.isAbstract(it.modifiers) } .map { it.kotlin.objectOrNewInstance() } } - } @DeleteForDJVM val List<Cordapp>.customSerializers get() = flatMap { it.serializationCustomSerializers }.toSet() } - // Parameter "context" is unused directy but passed in by reflection. Removing it will cause failures. + // Parameter "context" is unused directly but passed in by reflection. Removing it will cause failures. private fun registerCustomSerializers(context: SerializationContext, factory: SerializerFactory) { with(factory) { register(publicKeySerializer)