[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.dsl.KotlinCommonOptions
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
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
|
import org.jetbrains.kotlin.gradle.utils.ObservableSet
|
||||||
|
|
||||||
abstract class AbstractCompilationDetails<T : KotlinCommonOptions> : CompilationDetails<T> {
|
abstract class AbstractCompilationDetails<T : KotlinCommonOptions> : CompilationDetails<T> {
|
||||||
private val directlyIncludedKotlinSourceSetsImpl: MutableObservableSet<KotlinSourceSet> by lazy {
|
private val directlyIncludedKotlinSourceSetsImpl: MutableObservableSetImpl<KotlinSourceSet> by lazy {
|
||||||
MutableObservableSet(defaultSourceSet)
|
MutableObservableSetImpl(defaultSourceSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
final override val directlyIncludedKotlinSourceSets: ObservableSet<KotlinSourceSet>
|
final override val directlyIncludedKotlinSourceSets: ObservableSet<KotlinSourceSet>
|
||||||
get() = directlyIncludedKotlinSourceSetsImpl
|
get() = directlyIncludedKotlinSourceSetsImpl
|
||||||
|
|
||||||
private val allKotlinSourceSetsImpl: MutableObservableSet<KotlinSourceSet> by lazy {
|
private val allKotlinSourceSetsImpl: MutableObservableSetImpl<KotlinSourceSet> by lazy {
|
||||||
MutableObservableSet<KotlinSourceSet>().also { set ->
|
MutableObservableSetImpl<KotlinSourceSet>().also { set ->
|
||||||
defaultSourceSet.internal.withDependsOnClosure.forAll(set::add)
|
defaultSourceSet.internal.withDependsOnClosure.forAll(set::add)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ abstract class AbstractCompilationDetails<T : KotlinCommonOptions> : Compilation
|
|||||||
directlyIncludedKotlinSourceSetsImpl.add(sourceSet)
|
directlyIncludedKotlinSourceSetsImpl.add(sourceSet)
|
||||||
sourceSet.internal.withDependsOnClosure.forAll { inDependsOnClosure ->
|
sourceSet.internal.withDependsOnClosure.forAll { inDependsOnClosure ->
|
||||||
allKotlinSourceSetsImpl.add(inDependsOnClosure)
|
allKotlinSourceSetsImpl.add(inDependsOnClosure)
|
||||||
inDependsOnClosure.internal.addCompilation(compilation)
|
inDependsOnClosure.internal.compilations.add(compilation)
|
||||||
}
|
}
|
||||||
|
|
||||||
whenSourceSetAdded(sourceSet)
|
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.KotlinCompilation
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.utils.MutableObservableSet
|
import org.jetbrains.kotlin.gradle.utils.MutableObservableSet
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl
|
||||||
import org.jetbrains.kotlin.gradle.utils.ObservableSet
|
import org.jetbrains.kotlin.gradle.utils.ObservableSet
|
||||||
|
|
||||||
abstract class AbstractKotlinSourceSet : InternalKotlinSourceSet {
|
abstract class AbstractKotlinSourceSet : InternalKotlinSourceSet {
|
||||||
private val dependsOnImpl = MutableObservableSet<KotlinSourceSet>()
|
private val dependsOnImpl = MutableObservableSetImpl<KotlinSourceSet>()
|
||||||
private val dependsOnClosureImpl = MutableObservableSet<KotlinSourceSet>()
|
private val dependsOnClosureImpl = MutableObservableSetImpl<KotlinSourceSet>()
|
||||||
private val withDependsOnClosureImpl = MutableObservableSet<KotlinSourceSet>(this)
|
private val withDependsOnClosureImpl = MutableObservableSetImpl<KotlinSourceSet>(this)
|
||||||
private val compilationsImpl = MutableObservableSet<KotlinCompilation<*>>()
|
|
||||||
|
|
||||||
final override val dependsOn: ObservableSet<KotlinSourceSet>
|
final override val dependsOn: ObservableSet<KotlinSourceSet>
|
||||||
get() = dependsOnImpl
|
get() = dependsOnImpl
|
||||||
@@ -27,8 +27,7 @@ abstract class AbstractKotlinSourceSet : InternalKotlinSourceSet {
|
|||||||
final override val withDependsOnClosure: ObservableSet<KotlinSourceSet>
|
final override val withDependsOnClosure: ObservableSet<KotlinSourceSet>
|
||||||
get() = withDependsOnClosureImpl
|
get() = withDependsOnClosureImpl
|
||||||
|
|
||||||
override val compilations: ObservableSet<KotlinCompilation<*>>
|
override val compilations: MutableObservableSet<KotlinCompilation<*>> = MutableObservableSetImpl()
|
||||||
get() = compilationsImpl
|
|
||||||
|
|
||||||
final override fun dependsOn(other: KotlinSourceSet) {
|
final override fun dependsOn(other: KotlinSourceSet) {
|
||||||
if (other == this) return
|
if (other == this) return
|
||||||
@@ -51,9 +50,5 @@ abstract class AbstractKotlinSourceSet : InternalKotlinSourceSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected open fun afterDependsOnAdded(other: KotlinSourceSet) = Unit
|
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.KotlinCompilation
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
|
import org.jetbrains.kotlin.gradle.utils.MutableObservableSet
|
||||||
import org.jetbrains.kotlin.gradle.utils.ObservableSet
|
import org.jetbrains.kotlin.gradle.utils.ObservableSet
|
||||||
|
|
||||||
internal val KotlinSourceSet.internal: InternalKotlinSourceSet
|
internal val KotlinSourceSet.internal: InternalKotlinSourceSet
|
||||||
@@ -18,6 +19,5 @@ internal interface InternalKotlinSourceSet : KotlinSourceSet {
|
|||||||
override val dependsOn: ObservableSet<KotlinSourceSet>
|
override val dependsOn: ObservableSet<KotlinSourceSet>
|
||||||
val dependsOnClosure: ObservableSet<KotlinSourceSet>
|
val dependsOnClosure: ObservableSet<KotlinSourceSet>
|
||||||
val withDependsOnClosure: ObservableSet<KotlinSourceSet>
|
val withDependsOnClosure: ObservableSet<KotlinSourceSet>
|
||||||
val compilations: ObservableSet<KotlinCompilation<*>>
|
val compilations: MutableObservableSet<KotlinCompilation<*>>
|
||||||
fun addCompilation(compilation: KotlinCompilation<*>)
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -10,7 +10,9 @@ interface ObservableSet<T> : Set<T> {
|
|||||||
fun forAll(action: (T) -> Unit)
|
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 underlying = mutableSetOf(*elements)
|
||||||
private val whenObjectAddedActions = mutableListOf<(T) -> Unit>()
|
private val whenObjectAddedActions = mutableListOf<(T) -> Unit>()
|
||||||
private val forAllActions = mutableListOf<(T) -> Unit>()
|
private val forAllActions = mutableListOf<(T) -> Unit>()
|
||||||
|
|||||||
+3
-3
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle
|
package org.jetbrains.kotlin.gradle
|
||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.utils.MutableObservableSet
|
import org.jetbrains.kotlin.gradle.utils.MutableObservableSetImpl
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ class ObservableSetTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test - forAll`() {
|
fun `test - forAll`() {
|
||||||
val set = MutableObservableSet(1)
|
val set = MutableObservableSetImpl(1)
|
||||||
val testListener1 = TestListener()
|
val testListener1 = TestListener()
|
||||||
val testListener2 = TestListener()
|
val testListener2 = TestListener()
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ class ObservableSetTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `test - whenObjectAdded`() {
|
fun `test - whenObjectAdded`() {
|
||||||
val set = MutableObservableSet(1)
|
val set = MutableObservableSetImpl(1)
|
||||||
val testListener1 = TestListener()
|
val testListener1 = TestListener()
|
||||||
val testListener2 = TestListener()
|
val testListener2 = TestListener()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user