Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dispose of open URLClassLoaders when compilation is complete #2164

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading