From c08295921b7a11fdfdd8f1df75fa9acfc30ea738 Mon Sep 17 00:00:00 2001 From: Pablo Baxter Date: Wed, 23 Oct 2024 14:14:30 -0700 Subject: [PATCH] Dispose of open URLClassLoaders when compilation is complete --- .../devtools/ksp/KotlinSymbolProcessingExtension.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt index 27c01f2de7..2c044d6752 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt @@ -45,7 +45,9 @@ import com.google.devtools.ksp.symbol.Origin import com.google.devtools.ksp.symbol.Visibility import com.google.devtools.ksp.symbol.impl.java.KSFileJavaImpl import com.google.devtools.ksp.symbol.impl.kotlin.KSFileImpl +import com.intellij.openapi.Disposable import com.intellij.openapi.project.Project +import com.intellij.openapi.util.Disposer import com.intellij.openapi.vfs.StandardFileSystems import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.psi.PsiJavaFile @@ -79,7 +81,7 @@ class KotlinSymbolProcessingExtension( logger: KSPLogger, val testProcessor: SymbolProcessorProvider? = null, ) : AbstractKotlinSymbolProcessingExtension(options, logger, testProcessor != null) { - override fun loadProviders(): List { + override fun loadProviders(rootDisposable: Disposable): List { if (!initialized) { providers = if (testProcessor != null) { listOf(testProcessor) @@ -88,6 +90,10 @@ class KotlinSymbolProcessingExtension( val classLoader = URLClassLoader(processingClasspath.map { it.toURI().toURL() }.toTypedArray(), javaClass.classLoader) + Disposer.register(rootDisposable) { + classLoader.close() + } + ServiceLoaderLite.loadImplementations(SymbolProcessorProvider::class.java, classLoader).filter { (options.processors.isEmpty() && it.javaClass.name !in options.excludedProcessors) || it.javaClass.name in options.processors @@ -266,7 +272,7 @@ abstract class AbstractKotlinSymbolProcessingExtension( } } - val providers = loadProviders() + val providers = loadProviders(project) if (!initialized) { codeGenerator = CodeGeneratorImpl( options.classOutputDir, @@ -398,7 +404,7 @@ abstract class AbstractKotlinSymbolProcessingExtension( ) } - abstract fun loadProviders(): List + abstract fun loadProviders(rootDisposable: Disposable): List private var annotationProcessingComplete = false