Fixed a bug in the CorDapp loader that crashed when plugins were loaded (#1527)

* Fixed a bug in the CorDapp loader that crashed when plugins were loaded
due to an incorrect classloader definition.

* Removed debug statement.
This commit is contained in:
Clinton 2017-09-15 16:22:22 +01:00 committed by josecoll
parent f6bfca8c8e
commit 64f2bf7b09
6 changed files with 26 additions and 13 deletions

View File

@ -0,0 +1,8 @@
package net.corda.finance.contracts.isolated
import net.corda.core.node.CordaPluginRegistry
/**
* Dummy plugin for testing plugin loading
*/
class DummyPlugin : CordaPluginRegistry()

View File

@ -0,0 +1 @@
net.corda.finance.contracts.isolated.DummyPlugin

View File

@ -134,7 +134,9 @@ class CordappLoader private constructor(private val cordappJarPaths: List<URL>)
}
private fun findPlugins(cordappJarPath: URL): List<CordaPluginRegistry> {
return ServiceLoader.load(CordaPluginRegistry::class.java, URLClassLoader(arrayOf(cordappJarPath), null)).toList()
return ServiceLoader.load(CordaPluginRegistry::class.java, URLClassLoader(arrayOf(cordappJarPath), appClassLoader)).toList().filter {
cordappJarPath == it.javaClass.protectionDomain.codeSource.location
}
}
private fun findCustomSchemas(scanResult: ScanResult): Set<MappedSchema> {

View File

@ -35,18 +35,20 @@ class CordappLoaderTest {
}
@Test
fun `isolated JAR contains a CorDapp with a contract`() {
fun `isolated JAR contains a CorDapp with a contract and plugin`() {
val isolatedJAR = CordappLoaderTest::class.java.getResource("isolated.jar")!!
val loader = CordappLoader.createDevMode(listOf(isolatedJAR))
val expectedCordapp = Cordapp(
listOf("net.corda.finance.contracts.isolated.AnotherDummyContract"),
emptyList(),
listOf(loader.appClassLoader.loadClass("net.corda.core.flows.ContractUpgradeFlow\$Initiator").asSubclass(FlowLogic::class.java)),
emptyList(),
emptyList(),
emptySet(),
isolatedJAR)
val expected = arrayOf(expectedCordapp)
Assert.assertArrayEquals(expected, loader.cordapps.toTypedArray())
val actual = loader.cordapps.toTypedArray()
assertThat(actual).hasSize(1)
val actualCordapp = actual.first()
assertThat(actualCordapp.contractClassNames).isEqualTo(listOf("net.corda.finance.contracts.isolated.AnotherDummyContract"))
assertThat(actualCordapp.initiatedFlows).isEmpty()
assertThat(actualCordapp.rpcFlows).isEqualTo(listOf(loader.appClassLoader.loadClass("net.corda.core.flows.ContractUpgradeFlow\$Initiator").asSubclass(FlowLogic::class.java)))
assertThat(actualCordapp.services).isEmpty()
assertThat(actualCordapp.plugins).hasSize(1)
assertThat(actualCordapp.plugins.first().javaClass.name).isEqualTo("net.corda.finance.contracts.isolated.DummyPlugin")
assertThat(actualCordapp.jarPath).isEqualTo(isolatedJAR)
}
}