Skip to content

Commit

Permalink
Dispose of open URLClassLoaders when compilation is complete
Browse files Browse the repository at this point in the history
  • Loading branch information
pablobaxter authored and ting-yuan committed Oct 23, 2024
1 parent 6e060a3 commit 486cdf3
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -79,7 +81,7 @@ class KotlinSymbolProcessingExtension(
logger: KSPLogger,
val testProcessor: SymbolProcessorProvider? = null,
) : AbstractKotlinSymbolProcessingExtension(options, logger, testProcessor != null) {
override fun loadProviders(): List<SymbolProcessorProvider> {
override fun loadProviders(rootDisposable: Disposable): List<SymbolProcessorProvider> {
if (!initialized) {
providers = if (testProcessor != null) {
listOf(testProcessor)
Expand All @@ -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
Expand Down Expand Up @@ -266,7 +272,7 @@ abstract class AbstractKotlinSymbolProcessingExtension(
}
}

val providers = loadProviders()
val providers = loadProviders(project)
if (!initialized) {
codeGenerator = CodeGeneratorImpl(
options.classOutputDir,
Expand Down Expand Up @@ -398,7 +404,7 @@ abstract class AbstractKotlinSymbolProcessingExtension(
)
}

abstract fun loadProviders(): List<SymbolProcessorProvider>
abstract fun loadProviders(rootDisposable: Disposable): List<SymbolProcessorProvider>

private var annotationProcessingComplete = false

Expand Down

0 comments on commit 486cdf3

Please sign in to comment.