CORDA-1274: Migrated usage of FastClasspathScanner to ClassGraph (#4060)

FastClasspathScanner was renamed to ClassGraph for the version 4 release
This commit is contained in:
Shams Asari
2018-10-11 19:50:26 +01:00
committed by GitHub
parent 8c41ae208d
commit aced03df54
12 changed files with 89 additions and 72 deletions

View File

@ -27,8 +27,8 @@ dependencies {
compile "org.apache.qpid:proton-j:$protonj_version"
// FastClasspathScanner: classpath scanning - needed for the NetworkBootstrapper.
compile "io.github.lukehutch:fast-classpath-scanner:$fast_classpath_scanner_version"
// ClassGraph: classpath scanning
compile "io.github.classgraph:classgraph:$class_graph_version"
// For caches rather than guava
compile "com.github.ben-manes.caffeine:caffeine:$caffeine_version"

View File

@ -1,6 +1,6 @@
package net.corda.nodeapi.internal
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner
import io.github.classgraph.ClassGraph
import net.corda.core.contracts.Contract
import net.corda.core.contracts.ContractClassName
import net.corda.core.contracts.UpgradedContract
@ -28,15 +28,13 @@ class ContractsJarFile(private val file: Path) : ContractsJar {
override val hash: SecureHash by lazy(LazyThreadSafetyMode.NONE, file::hash)
override fun scan(): List<ContractClassName> {
val scanResult = FastClasspathScanner()
// A set of a single element may look odd, but if this is removed "Path" which itself is an `Iterable`
// is getting broken into pieces to scan individually, which doesn't yield desired effect.
.overrideClasspath(singleton(file))
.scan()
val scanResult = ClassGraph().overrideClasspath(singleton(file)).enableAllInfo().scan()
val contractClassNames = coreContractClasses
.flatMap { scanResult.getNamesOfClassesImplementing(it.qualifiedName) }
.toSet()
val contractClassNames = scanResult.use {
coreContractClasses
.flatMap { scanResult.getClassesImplementing(it.qualifiedName).names }
.toSet()
}
return URLClassLoader(arrayOf(file.toUri().toURL()), Contract::class.java.classLoader).use { cl ->
contractClassNames.mapNotNull {