[Gradle][MPP] Replace InternalKotlinSourceSet.addCompilation by exposing mutable .compilations
This requires to make MutableObservableSet public as well, since public implementations will inherit. The MutableObservableSet therefore move its implementation to an internal MutableObservableSetImpl ^KT-52726 Verification Pending
This commit is contained in:
committed by
Space
parent
84a22256f9
commit
ea483c01fe
+6
-6
@@ -8,19 +8,19 @@ package org.jetbrains.kotlin.gradle.plugin.mpp
|
||||
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||
import org.jetbrains.kotlin.gradle.utils.MutableObservableSet
|
||||
import org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl
|
||||
import org.jetbrains.kotlin.gradle.utils.ObservableSet
|
||||
|
||||
abstract class AbstractCompilationDetails<T : KotlinCommonOptions> : CompilationDetails<T> {
|
||||
private val directlyIncludedKotlinSourceSetsImpl: MutableObservableSet<KotlinSourceSet> by lazy {
|
||||
MutableObservableSet(defaultSourceSet)
|
||||
private val directlyIncludedKotlinSourceSetsImpl: MutableObservableSetImpl<KotlinSourceSet> by lazy {
|
||||
MutableObservableSetImpl(defaultSourceSet)
|
||||
}
|
||||
|
||||
final override val directlyIncludedKotlinSourceSets: ObservableSet<KotlinSourceSet>
|
||||
get() = directlyIncludedKotlinSourceSetsImpl
|
||||
|
||||
private val allKotlinSourceSetsImpl: MutableObservableSet<KotlinSourceSet> by lazy {
|
||||
MutableObservableSet<KotlinSourceSet>().also { set ->
|
||||
private val allKotlinSourceSetsImpl: MutableObservableSetImpl<KotlinSourceSet> by lazy {
|
||||
MutableObservableSetImpl<KotlinSourceSet>().also { set ->
|
||||
defaultSourceSet.internal.withDependsOnClosure.forAll(set::add)
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ abstract class AbstractCompilationDetails<T : KotlinCommonOptions> : Compilation
|
||||
directlyIncludedKotlinSourceSetsImpl.add(sourceSet)
|
||||
sourceSet.internal.withDependsOnClosure.forAll { inDependsOnClosure ->
|
||||
allKotlinSourceSetsImpl.add(inDependsOnClosure)
|
||||
inDependsOnClosure.internal.addCompilation(compilation)
|
||||
inDependsOnClosure.internal.compilations.add(compilation)
|
||||
}
|
||||
|
||||
whenSourceSetAdded(sourceSet)
|
||||
|
||||
+5
-10
@@ -10,13 +10,13 @@ package org.jetbrains.kotlin.gradle.plugin.sources
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.utils.MutableObservableSet
|
||||
import org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl
|
||||
import org.jetbrains.kotlin.gradle.utils.ObservableSet
|
||||
|
||||
abstract class AbstractKotlinSourceSet : InternalKotlinSourceSet {
|
||||
private val dependsOnImpl = MutableObservableSet<KotlinSourceSet>()
|
||||
private val dependsOnClosureImpl = MutableObservableSet<KotlinSourceSet>()
|
||||
private val withDependsOnClosureImpl = MutableObservableSet<KotlinSourceSet>(this)
|
||||
private val compilationsImpl = MutableObservableSet<KotlinCompilation<*>>()
|
||||
private val dependsOnImpl = MutableObservableSetImpl<KotlinSourceSet>()
|
||||
private val dependsOnClosureImpl = MutableObservableSetImpl<KotlinSourceSet>()
|
||||
private val withDependsOnClosureImpl = MutableObservableSetImpl<KotlinSourceSet>(this)
|
||||
|
||||
final override val dependsOn: ObservableSet<KotlinSourceSet>
|
||||
get() = dependsOnImpl
|
||||
@@ -27,8 +27,7 @@ abstract class AbstractKotlinSourceSet : InternalKotlinSourceSet {
|
||||
final override val withDependsOnClosure: ObservableSet<KotlinSourceSet>
|
||||
get() = withDependsOnClosureImpl
|
||||
|
||||
override val compilations: ObservableSet<KotlinCompilation<*>>
|
||||
get() = compilationsImpl
|
||||
override val compilations: MutableObservableSet<KotlinCompilation<*>> = MutableObservableSetImpl()
|
||||
|
||||
final override fun dependsOn(other: KotlinSourceSet) {
|
||||
if (other == this) return
|
||||
@@ -51,9 +50,5 @@ abstract class AbstractKotlinSourceSet : InternalKotlinSourceSet {
|
||||
}
|
||||
|
||||
protected open fun afterDependsOnAdded(other: KotlinSourceSet) = Unit
|
||||
|
||||
final override fun addCompilation(compilation: KotlinCompilation<*>) {
|
||||
compilationsImpl.add(compilation)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.gradle.plugin.sources
|
||||
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||
import org.jetbrains.kotlin.gradle.utils.MutableObservableSet
|
||||
import org.jetbrains.kotlin.gradle.utils.ObservableSet
|
||||
|
||||
internal val KotlinSourceSet.internal: InternalKotlinSourceSet
|
||||
@@ -18,6 +19,5 @@ internal interface InternalKotlinSourceSet : KotlinSourceSet {
|
||||
override val dependsOn: ObservableSet<KotlinSourceSet>
|
||||
val dependsOnClosure: ObservableSet<KotlinSourceSet>
|
||||
val withDependsOnClosure: ObservableSet<KotlinSourceSet>
|
||||
val compilations: ObservableSet<KotlinCompilation<*>>
|
||||
fun addCompilation(compilation: KotlinCompilation<*>)
|
||||
val compilations: MutableObservableSet<KotlinCompilation<*>>
|
||||
}
|
||||
|
||||
+3
-1
@@ -10,7 +10,9 @@ interface ObservableSet<T> : Set<T> {
|
||||
fun forAll(action: (T) -> Unit)
|
||||
}
|
||||
|
||||
internal class MutableObservableSet<T>(vararg elements: T) : ObservableSet<T>, MutableSet<T> {
|
||||
interface MutableObservableSet<T> : ObservableSet<T>, MutableSet<T>
|
||||
|
||||
internal class MutableObservableSetImpl<T>(vararg elements: T) : MutableObservableSet<T> {
|
||||
private val underlying = mutableSetOf(*elements)
|
||||
private val whenObjectAddedActions = mutableListOf<(T) -> Unit>()
|
||||
private val forAllActions = mutableListOf<(T) -> Unit>()
|
||||
|
||||
+3
-3
@@ -7,7 +7,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle
|
||||
|
||||
import org.jetbrains.kotlin.gradle.utils.MutableObservableSet
|
||||
import org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -22,7 +22,7 @@ class ObservableSetTest {
|
||||
|
||||
@Test
|
||||
fun `test - forAll`() {
|
||||
val set = MutableObservableSet(1)
|
||||
val set = MutableObservableSetImpl(1)
|
||||
val testListener1 = TestListener()
|
||||
val testListener2 = TestListener()
|
||||
|
||||
@@ -41,7 +41,7 @@ class ObservableSetTest {
|
||||
|
||||
@Test
|
||||
fun `test - whenObjectAdded`() {
|
||||
val set = MutableObservableSet(1)
|
||||
val set = MutableObservableSetImpl(1)
|
||||
val testListener1 = TestListener()
|
||||
val testListener2 = TestListener()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user