Switch plugin and annotation processor loading to the own implementation of ServiceLoader

'ServiceLoader' in JDK8 leaks file handles (https://bugs.openjdk.java.net/browse/JDK-8156014).
New implementation uses the ZipFile API, it also doesn't operate on the whole classpath which is not often needed.
This commit is contained in:
Yan Zhulanow
2018-10-29 16:12:15 +09:00
parent 11e23ecc70
commit 0ffa901859
8 changed files with 459 additions and 6 deletions
@@ -14,7 +14,7 @@ import java.net.URLClassLoader
import java.util.*
import javax.annotation.processing.Processor
class ProcessorLoader(
open class ProcessorLoader(
private val paths: KaptPaths,
private val annotationProcessorFqNames: List<String>,
private val logger: KaptLogger
@@ -33,7 +33,7 @@ class ProcessorLoader(
annotationProcessorFqNames.mapNotNull { tryLoadProcessor(it, classLoader) }
} else {
logger.info("Need to discovery annotation processors in the AP classpath")
ServiceLoader.load(Processor::class.java, classLoader).toList()
doLoadProcessors(classLoader)
}
if (processors.isEmpty()) {
@@ -45,6 +45,10 @@ class ProcessorLoader(
return processors
}
open fun doLoadProcessors(classLoader: URLClassLoader): List<Processor> {
return ServiceLoader.load(Processor::class.java, classLoader).toList()
}
private fun tryLoadProcessor(fqName: String, classLoader: ClassLoader): Processor? {
val annotationProcessorClass = try {
Class.forName(fqName, true, classLoader)