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> { 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> { private fun findCustomSchemas(scanResult: ScanResult): Set<MappedSchema> {

View File

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