Skip to content

Commit 5c34d5b

Browse files
sellmairSpace
authored and
Space
committed
[MPP] SourceSetMetadataStorageForIde: Remove faulty 'cleanupStaleEntries'
^KT-52955 Verification Pending This method over-aggressively removed libraries in the situation of isolated KGP ClassLoaders or when a project enabled Gradles configuration caching. This faulty cleanup is removed in anticipation of a re-structured SourceSetMetadataStorageForIde in the near future.
1 parent a449dda commit 5c34d5b

File tree

2 files changed

+2
-67
lines changed

2 files changed

+2
-67
lines changed

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/mpp/KotlinMultiplatformPlugin.kt

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.registerDefaultVariantFactori
3030
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.setupFragmentsMetadataForKpmModules
3131
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.setupKpmModulesPublication
3232
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.util.copyAttributes
33-
import org.jetbrains.kotlin.gradle.plugin.sources.CleanupStaleSourceSetMetadataEntriesService
3433
import org.jetbrains.kotlin.gradle.plugin.sources.DefaultLanguageSettingsBuilder
3534
import org.jetbrains.kotlin.gradle.plugin.sources.SourceSetMetadataStorageForIde
3635
import org.jetbrains.kotlin.gradle.plugin.sources.checkSourceSetVisibilityRequirements
@@ -126,24 +125,6 @@ class KotlinMultiplatformPlugin : Plugin<Project> {
126125
project.pluginManager.apply(ScriptingGradleSubplugin::class.java)
127126

128127
exportProjectStructureMetadataForOtherBuilds(project)
129-
130-
SingleActionPerBuild.run(project.rootProject, "cleanup-processed-metadata") {
131-
if (isConfigurationCacheAvailable(project.gradle)) {
132-
BuildEventsListenerRegistryHolder.getInstance(project).listenerRegistry.onTaskCompletion(
133-
project.gradle.sharedServices
134-
.registerIfAbsent(
135-
"cleanup-stale-sourceset-metadata",
136-
CleanupStaleSourceSetMetadataEntriesService::class.java
137-
) {
138-
CleanupStaleSourceSetMetadataEntriesService.configure(it, project)
139-
}
140-
)
141-
} else {
142-
project.gradle.buildFinished {
143-
SourceSetMetadataStorageForIde.cleanupStaleEntries(project)
144-
}
145-
}
146-
}
147128
}
148129

149130
private fun exportProjectStructureMetadataForOtherBuilds(

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/SourceSetMetadataStorageForIde.kt

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,9 @@ import org.jetbrains.kotlin.gradle.dsl.multiplatformExtensionOrNull
1717
import java.io.File
1818

1919
object SourceSetMetadataStorageForIde {
20-
fun cleanupStaleEntries(project: Project) {
21-
val projectStorageDirectories = project.rootProject.allprojects
22-
.associate { projectStorage(it) to it.multiplatformExtensionOrNull?.sourceSets.orEmpty().map { it.name } }
23-
cleanupStaleEntries(getStorageRoot(project), projectStorageDirectories)
24-
}
25-
26-
fun cleanupStaleEntries(projectStorageRoot: File, projectStorageDirectories: Map<File, List<String>>) {
27-
projectStorageRoot.listFiles().orEmpty().filter { it.isDirectory }.forEach { directory ->
28-
// If no project corresponds to the directory, remove the directory
29-
if (directory !in projectStorageDirectories) {
30-
directory.deleteRecursively()
31-
} else {
32-
// Under the project's directory, delete subdirectories that don't correspond to any source set:
33-
val sourceSetNames = projectStorageDirectories.getValue(directory)
34-
directory.listFiles().orEmpty().filter { it.isDirectory }.forEach { subdirectory ->
35-
if (subdirectory.name !in sourceSetNames)
36-
subdirectory.deleteRecursively()
37-
}
38-
}
39-
}
40-
}
20+
private fun getStorageRoot(project: Project): File = project.rootDir.resolve(".gradle/kotlin/sourceSetMetadata")
4121

42-
internal fun getStorageRoot(project: Project): File = project.rootDir.resolve(".gradle/kotlin/sourceSetMetadata")
43-
44-
internal fun projectStorage(project: Project): File {
22+
private fun projectStorage(project: Project): File {
4523
val projectPathSegments = generateSequence(project) { it.parent }.map { it.name }
4624
return getStorageRoot(project).resolve(
4725
// Escape dots in project names to avoid ambiguous paths.
@@ -54,27 +32,3 @@ object SourceSetMetadataStorageForIde {
5432
internal fun sourceSetStorageWithScope(project: Project, sourceSetName: String, scope: KotlinDependencyScope) =
5533
sourceSetStorage(project, sourceSetName).resolve(scope.scopeName)
5634
}
57-
58-
abstract class CleanupStaleSourceSetMetadataEntriesService : BuildService<CleanupStaleSourceSetMetadataEntriesService.Parameters>, AutoCloseable, OperationCompletionListener {
59-
interface Parameters : BuildServiceParameters {
60-
val projectStorageRoot: Property<File>
61-
val projectStorageDirectories: MapProperty<File, List<String>>
62-
}
63-
64-
override fun onFinish(event: FinishEvent?) {
65-
// noop
66-
}
67-
68-
override fun close() {
69-
SourceSetMetadataStorageForIde.cleanupStaleEntries(parameters.projectStorageRoot.get(), parameters.projectStorageDirectories.get())
70-
}
71-
72-
companion object {
73-
fun configure(spec: BuildServiceSpec<Parameters>, project: Project) {
74-
spec.parameters.projectStorageRoot.set(SourceSetMetadataStorageForIde.getStorageRoot(project))
75-
spec.parameters.projectStorageDirectories.set(project.rootProject.allprojects.associate {
76-
SourceSetMetadataStorageForIde.projectStorage(it) to it.multiplatformExtensionOrNull?.sourceSets.orEmpty().map { it.name }
77-
})
78-
}
79-
}
80-
}

0 commit comments

Comments
 (0)