Optimize contracts scanning (#4580)

This commit is contained in:
Tudor Malene 2019-01-15 13:29:38 +00:00 committed by GitHub
parent 44733da8b6
commit 76182f29d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,20 +28,15 @@ class ContractsJarFile(private val file: Path) : ContractsJar {
override val hash: SecureHash by lazy(LazyThreadSafetyMode.NONE, file::hash)
override fun scan(): List<ContractClassName> {
val scanResult = ClassGraph().overrideClasspath(singleton(file)).enableAllInfo().scan()
val scanResult = ClassGraph().overrideClasspath(singleton(file)).enableClassInfo().scan()
val contractClassNames = scanResult.use {
return scanResult.use { result ->
coreContractClasses
.flatMap { scanResult.getClassesImplementing(it.qualifiedName).names }
.toSet()
}
return URLClassLoader(arrayOf(file.toUri().toURL()), Contract::class.java.classLoader).use { cl ->
contractClassNames.mapNotNull {
val contractClass = cl.loadClass(it)
// Only keep instantiable contracts
if (contractClass.isConcreteClass) contractClass.name else null
}
.flatMap { result.getClassesImplementing(it.qualifiedName)}
.filterNot { it.isAbstract }
.filterNot { it.isInterface }
.map { it.name }
.toList()
}
}
}