mirror of
https://github.com/corda/corda.git
synced 2025-01-30 08:04:16 +00:00
Pass in classloader from cordapp loader
This commit is contained in:
parent
af002aba05
commit
b3414267b7
@ -31,7 +31,7 @@ object CordappResolver {
|
||||
* This could happen when trying to run different versions of the same CorDapp on the same node.
|
||||
*/
|
||||
@Synchronized
|
||||
fun register(cordapp: Cordapp) {
|
||||
fun register(cordapp: Cordapp, classLoader: ClassLoader) {
|
||||
val existingClasses = cordappClasses.keys
|
||||
val classesToRegister = cordapp.cordappClasses.toSet()
|
||||
val notAlreadyRegisteredClasses = classesToRegister - existingClasses
|
||||
@ -41,7 +41,7 @@ object CordappResolver {
|
||||
|
||||
for ((className, registeredCordapps) in alreadyRegistered) {
|
||||
if (registeredCordapps.any { it.jarHash == cordapp.jarHash }) continue
|
||||
if (duplicateRegistrationFilter.shouldNotify(className, cordapp::class.java.classLoader)) {
|
||||
if (duplicateRegistrationFilter.shouldNotify(className, classLoader)) {
|
||||
logger.warn("More than one CorDapp registered for $className.")
|
||||
}
|
||||
cordappClasses[className] = registeredCordapps + cordapp
|
||||
@ -97,6 +97,7 @@ internal class DuplicateRegistrationFilter(private val ignoreList: Set<String>)
|
||||
alreadySeen += className
|
||||
|
||||
if (className.canBeIgnored) return false
|
||||
println("Checking status of $className with $classLoader")
|
||||
return className.isContractClass(classLoader)
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,8 @@ class CordappResolverTest {
|
||||
CordappResolver.clear()
|
||||
}
|
||||
|
||||
private val classLoader = ClassLoader.getSystemClassLoader()
|
||||
|
||||
@Test
|
||||
fun `the correct cordapp resolver is used after calling withCordappInfo`() {
|
||||
val defaultTargetVersion = 222
|
||||
@ -22,7 +24,7 @@ class CordappResolverTest {
|
||||
contractClassNames = listOf(javaClass.name),
|
||||
minimumPlatformVersion = 3,
|
||||
targetPlatformVersion = defaultTargetVersion
|
||||
))
|
||||
), classLoader)
|
||||
assertEquals(defaultTargetVersion, CordappResolver.currentTargetVersion)
|
||||
|
||||
val expectedTargetVersion = 555
|
||||
@ -39,12 +41,12 @@ class CordappResolverTest {
|
||||
contractClassNames = listOf(javaClass.name),
|
||||
minimumPlatformVersion = 3,
|
||||
targetPlatformVersion = 222
|
||||
))
|
||||
), classLoader)
|
||||
CordappResolver.register(CordappImpl.TEST_INSTANCE.copy(
|
||||
contractClassNames = listOf(javaClass.name),
|
||||
minimumPlatformVersion = 2,
|
||||
targetPlatformVersion = 456
|
||||
))
|
||||
), classLoader)
|
||||
assertThat(CordappResolver.currentCordapp).isNotNull()
|
||||
}
|
||||
|
||||
@ -55,13 +57,13 @@ class CordappResolverTest {
|
||||
minimumPlatformVersion = 3,
|
||||
targetPlatformVersion = 222,
|
||||
jarHash = SecureHash.randomSHA256()
|
||||
))
|
||||
), classLoader)
|
||||
CordappResolver.register(CordappImpl.TEST_INSTANCE.copy(
|
||||
contractClassNames = listOf(javaClass.name),
|
||||
minimumPlatformVersion = 2,
|
||||
targetPlatformVersion = 456,
|
||||
jarHash = SecureHash.randomSHA256()
|
||||
))
|
||||
), classLoader)
|
||||
assertThat(CordappResolver.currentCordapp).isNull()
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user