[KPM] Remove now unused IdeFragmentDependencyResolver
KT-51386
This commit is contained in:
committed by
Space
parent
edbf5c5cd8
commit
f65c61472b
-78
@@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@file:OptIn(InternalIdeApi::class)
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.ide
|
|
||||||
|
|
||||||
import org.gradle.api.Project
|
|
||||||
import org.gradle.api.internal.project.ProjectInternal
|
|
||||||
import org.gradle.testfixtures.ProjectBuilder
|
|
||||||
import org.jetbrains.kotlin.gradle.MultiplatformExtensionTest
|
|
||||||
import org.jetbrains.kotlin.gradle.applyMultiplatformPlugin
|
|
||||||
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
|
|
||||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
|
||||||
import org.jetbrains.kotlin.gradle.dsl.pm20Extension
|
|
||||||
import org.jetbrains.kotlin.gradle.kpm.applyKpmPlugin
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.ide.*
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinGradleFragment
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinPm20ProjectExtension
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.currentBuildId
|
|
||||||
|
|
||||||
@OptIn(InternalIdeApi::class)
|
|
||||||
abstract class AbstractIdeFragmentDependenciesTest {
|
|
||||||
val rootProject = ProjectBuilder.builder().build() as ProjectInternal
|
|
||||||
|
|
||||||
private val ideFragmentDependencyResolvers: MutableMap<Project, IdeFragmentDependencyResolver> = mutableMapOf()
|
|
||||||
|
|
||||||
private fun getIdeFragmentDependencyResolver(project: Project) = ideFragmentDependencyResolvers.getOrPut(project) {
|
|
||||||
IdeFragmentDependencyResolver.create(project)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun resolveIdeDependenciesList(fragment: KotlinGradleFragment): List<IdeFragmentDependency> {
|
|
||||||
return getIdeFragmentDependencyResolver(fragment.project).resolveDependencies(fragment)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun resolveIdeDependenciesSet(fragment: KotlinGradleFragment): Set<IdeFragmentDependency> {
|
|
||||||
return resolveIdeDependenciesList(fragment).toSet()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal inline fun AbstractIdeFragmentDependenciesTest.createKpmProject(
|
|
||||||
name: String, configure: KotlinPm20ProjectExtension.() -> Unit
|
|
||||||
): KotlinPm20ProjectExtension {
|
|
||||||
val project = ProjectBuilder.builder().withName(name).withParent(rootProject).build() as ProjectInternal
|
|
||||||
project.applyKpmPlugin()
|
|
||||||
project.pm20Extension.configure()
|
|
||||||
return project.pm20Extension
|
|
||||||
}
|
|
||||||
|
|
||||||
internal inline fun AbstractIdeFragmentDependenciesTest.createMultiplatformProject(
|
|
||||||
name: String, configure: KotlinMultiplatformExtension.() -> Unit
|
|
||||||
): KotlinMultiplatformExtension {
|
|
||||||
val project = ProjectBuilder.builder().withName(name).withParent(rootProject).build() as ProjectInternal
|
|
||||||
project.applyMultiplatformPlugin()
|
|
||||||
project.multiplatformExtension.configure()
|
|
||||||
return project.multiplatformExtension
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun ideLocalSourceDependenciesListOf(vararg fragment: KotlinGradleFragment):
|
|
||||||
List<IdeLocalSourceFragmentDependency> = listOf(*fragment).map { it.toIdeFragmentDependency() }
|
|
||||||
|
|
||||||
internal fun ideLocalSourceDependenciesSetOf(vararg fragment: KotlinGradleFragment):
|
|
||||||
Set<IdeLocalSourceFragmentDependency> = ideLocalSourceDependenciesListOf(*fragment).toSet()
|
|
||||||
|
|
||||||
|
|
||||||
fun KotlinGradleFragment.toIdeFragmentDependency(): IdeLocalSourceFragmentDependency {
|
|
||||||
return IdeLocalSourceFragmentDependency(
|
|
||||||
buildId = project.currentBuildId(),
|
|
||||||
projectPath = project.path,
|
|
||||||
projectName = project.name,
|
|
||||||
kotlinModuleName = containingModule.name,
|
|
||||||
kotlinFragmentName = name
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
-198
@@ -1,198 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@file:Suppress("FunctionName")
|
|
||||||
@file:OptIn(InternalIdeApi::class)
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.ide
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.ide.InternalIdeApi
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.*
|
|
||||||
import kotlin.test.Test
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
|
|
||||||
class KpmProjectToKpmProjectIdeFragmentDependenciesTest : AbstractIdeFragmentDependenciesTest() {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `sample - with jvm and native targets`() {
|
|
||||||
fun KotlinPm20ProjectExtension.setupFragmentsForTest() = mainAndTest {
|
|
||||||
/* Variants */
|
|
||||||
jvm
|
|
||||||
val iosX64 = fragments.create("iosX64", KotlinIosX64Variant::class.java)
|
|
||||||
val iosArm64 = fragments.create("iosArm64", KotlinIosArm64Variant::class.java)
|
|
||||||
val linuxX64 = fragments.create("linuxX64", KotlinLinuxX64Variant::class.java)
|
|
||||||
|
|
||||||
/* Shared fragments */
|
|
||||||
val ios = fragments.create("ios")
|
|
||||||
val native = fragments.create("native")
|
|
||||||
|
|
||||||
/* Refines edges */
|
|
||||||
ios.refines(common)
|
|
||||||
native.refines(common)
|
|
||||||
iosX64.refines(ios)
|
|
||||||
iosArm64.refines(ios)
|
|
||||||
ios.refines(native)
|
|
||||||
linuxX64.refines(native)
|
|
||||||
}
|
|
||||||
|
|
||||||
val p1 = createKpmProject("p1") {
|
|
||||||
setupFragmentsForTest()
|
|
||||||
}
|
|
||||||
|
|
||||||
val p2 = createKpmProject("p2") {
|
|
||||||
setupFragmentsForTest()
|
|
||||||
mainAndTest {
|
|
||||||
dependencies {
|
|
||||||
api(project(":p1"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Assert :p2 to :p1 dependencies for the main module
|
|
||||||
*/
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
ideLocalSourceDependenciesSetOf(p1.main.common),
|
|
||||||
resolveIdeDependenciesSet(p2.main.common)
|
|
||||||
)
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
ideLocalSourceDependenciesSetOf(
|
|
||||||
p1.main.common,
|
|
||||||
p1.main.fragments.getByName("native"),
|
|
||||||
p1.main.fragments.getByName("ios")
|
|
||||||
),
|
|
||||||
resolveIdeDependenciesSet(p2.main.fragments.getByName("ios"))
|
|
||||||
)
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
ideLocalSourceDependenciesSetOf(
|
|
||||||
p1.main.common,
|
|
||||||
p1.main.fragments.getByName("native"),
|
|
||||||
p1.main.fragments.getByName("ios"),
|
|
||||||
p1.main.fragments.getByName("iosX64")
|
|
||||||
),
|
|
||||||
resolveIdeDependenciesSet(p2.main.fragments.getByName("iosX64"))
|
|
||||||
)
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
ideLocalSourceDependenciesSetOf(
|
|
||||||
p1.main.common,
|
|
||||||
p1.main.fragments.getByName("native"),
|
|
||||||
p1.main.fragments.getByName("ios"),
|
|
||||||
p1.main.fragments.getByName("iosArm64")
|
|
||||||
),
|
|
||||||
resolveIdeDependenciesSet(p2.main.fragments.getByName("iosArm64"))
|
|
||||||
)
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
ideLocalSourceDependenciesSetOf(
|
|
||||||
p1.main.common,
|
|
||||||
p1.main.fragments.getByName("native"),
|
|
||||||
p1.main.fragments.getByName("linuxX64")
|
|
||||||
),
|
|
||||||
resolveIdeDependenciesSet(p2.main.fragments.getByName("linuxX64"))
|
|
||||||
)
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
ideLocalSourceDependenciesSetOf(
|
|
||||||
p1.main.common,
|
|
||||||
p1.main.fragments.getByName("jvm")
|
|
||||||
),
|
|
||||||
resolveIdeDependenciesSet(p2.main.fragments.getByName("jvm"))
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
Assert :p2 to :p1 dependencies for the test module
|
|
||||||
*/
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
ideLocalSourceDependenciesSetOf(
|
|
||||||
p1.main.common,
|
|
||||||
p2.main.common
|
|
||||||
),
|
|
||||||
resolveIdeDependenciesSet(p2.test.common)
|
|
||||||
)
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
ideLocalSourceDependenciesSetOf(
|
|
||||||
p1.main.common,
|
|
||||||
p1.main.fragments.getByName("jvm"),
|
|
||||||
|
|
||||||
p2.main.common,
|
|
||||||
p2.main.fragments.getByName("jvm")
|
|
||||||
),
|
|
||||||
resolveIdeDependenciesSet(p2.test.fragments.getByName("jvm"))
|
|
||||||
)
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
ideLocalSourceDependenciesSetOf(
|
|
||||||
p1.main.common,
|
|
||||||
p1.main.fragments.getByName("native"),
|
|
||||||
|
|
||||||
p2.main.common,
|
|
||||||
p2.main.fragments.getByName("native")
|
|
||||||
),
|
|
||||||
resolveIdeDependenciesSet(p2.test.fragments.getByName("native"))
|
|
||||||
)
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
ideLocalSourceDependenciesSetOf(
|
|
||||||
p1.main.common,
|
|
||||||
p1.main.fragments.getByName("native"),
|
|
||||||
p1.main.fragments.getByName("ios"),
|
|
||||||
|
|
||||||
p2.main.common,
|
|
||||||
p2.main.fragments.getByName("native"),
|
|
||||||
p2.main.fragments.getByName("ios")
|
|
||||||
),
|
|
||||||
resolveIdeDependenciesSet(p2.test.fragments.getByName("ios"))
|
|
||||||
)
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
ideLocalSourceDependenciesSetOf(
|
|
||||||
p1.main.common,
|
|
||||||
p1.main.fragments.getByName("native"),
|
|
||||||
p1.main.fragments.getByName("ios"),
|
|
||||||
p1.main.fragments.getByName("iosX64"),
|
|
||||||
|
|
||||||
p2.main.common,
|
|
||||||
p2.main.fragments.getByName("native"),
|
|
||||||
p2.main.fragments.getByName("ios"),
|
|
||||||
p2.main.fragments.getByName("iosX64")
|
|
||||||
),
|
|
||||||
resolveIdeDependenciesSet(p2.test.fragments.getByName("iosX64"))
|
|
||||||
)
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
ideLocalSourceDependenciesSetOf(
|
|
||||||
p1.main.common,
|
|
||||||
p1.main.fragments.getByName("native"),
|
|
||||||
p1.main.fragments.getByName("ios"),
|
|
||||||
p1.main.fragments.getByName("iosArm64"),
|
|
||||||
|
|
||||||
p2.main.common,
|
|
||||||
p2.main.fragments.getByName("native"),
|
|
||||||
p2.main.fragments.getByName("ios"),
|
|
||||||
p2.main.fragments.getByName("iosArm64")
|
|
||||||
),
|
|
||||||
resolveIdeDependenciesSet(p2.test.fragments.getByName("iosArm64"))
|
|
||||||
)
|
|
||||||
|
|
||||||
assertEquals(
|
|
||||||
ideLocalSourceDependenciesSetOf(
|
|
||||||
p1.main.common,
|
|
||||||
p1.main.fragments.getByName("native"),
|
|
||||||
p1.main.fragments.getByName("linuxX64"),
|
|
||||||
|
|
||||||
p2.main.common,
|
|
||||||
p2.main.fragments.getByName("native"),
|
|
||||||
p2.main.fragments.getByName("linuxX64")
|
|
||||||
),
|
|
||||||
resolveIdeDependenciesSet(p2.test.fragments.getByName("linuxX64"))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-79
@@ -1,79 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@file:Suppress("FunctionName", "DuplicatedCode")
|
|
||||||
@file:OptIn(InternalIdeApi::class)
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.ide
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.ide.IdeLocalSourceFragmentDependency
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.ide.InternalIdeApi
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinIosArm64Variant
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinIosX64Variant
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinLinuxX64Variant
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.jvm
|
|
||||||
import kotlin.test.Test
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
|
|
||||||
class KpmProjectToMppProjectIdeFragmentDependenciesTest : AbstractIdeFragmentDependenciesTest() {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `sample - with jvm and native targets`() {
|
|
||||||
val mpp = createMultiplatformProject("mpp") {
|
|
||||||
jvm()
|
|
||||||
iosX64()
|
|
||||||
iosArm64()
|
|
||||||
linuxX64()
|
|
||||||
|
|
||||||
val commonMain = sourceSets.getByName("commonMain")
|
|
||||||
val iosMain = sourceSets.create("iosMain")
|
|
||||||
val nativeMain = sourceSets.create("nativeMain")
|
|
||||||
val iosX64Main = sourceSets.getByName("iosX64Main")
|
|
||||||
val iosArm64Main = sourceSets.getByName("iosArm64Main")
|
|
||||||
val linuxX64Main = sourceSets.getByName("linuxX64Main")
|
|
||||||
|
|
||||||
iosX64Main.dependsOn(iosMain)
|
|
||||||
iosArm64Main.dependsOn(iosMain)
|
|
||||||
iosMain.dependsOn(nativeMain)
|
|
||||||
nativeMain.dependsOn(commonMain)
|
|
||||||
linuxX64Main.dependsOn(nativeMain)
|
|
||||||
nativeMain.dependsOn(commonMain)
|
|
||||||
}
|
|
||||||
|
|
||||||
val kpm = createKpmProject("kpm") {
|
|
||||||
mainAndTest {
|
|
||||||
jvm
|
|
||||||
val iosX64 = fragments.create("iosX64", KotlinIosX64Variant::class.java)
|
|
||||||
val iosArm64 = fragments.create("iosArm64", KotlinIosArm64Variant::class.java)
|
|
||||||
val linuxX64 = fragments.create("linuxX64", KotlinLinuxX64Variant::class.java)
|
|
||||||
|
|
||||||
val ios = fragments.create("ios")
|
|
||||||
val native = fragments.create("native")
|
|
||||||
|
|
||||||
ios.refines(common)
|
|
||||||
native.refines(common)
|
|
||||||
iosX64.refines(ios)
|
|
||||||
iosArm64.refines(ios)
|
|
||||||
ios.refines(native)
|
|
||||||
linuxX64.refines(native)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
resolveIdeDependenciesSet(kpm.main.common)
|
|
||||||
resolveIdeDependenciesSet(kpm.main.fragments.getByName("ios"))
|
|
||||||
resolveIdeDependenciesSet(kpm.main.fragments.getByName("iosX64"))
|
|
||||||
resolveIdeDependenciesSet(kpm.main.fragments.getByName("iosArm64"))
|
|
||||||
resolveIdeDependenciesSet(kpm.main.fragments.getByName("linuxX64"))
|
|
||||||
resolveIdeDependenciesSet(kpm.main.fragments.getByName("jvm"))
|
|
||||||
|
|
||||||
/* TODO */
|
|
||||||
runCatching {
|
|
||||||
assertEquals(
|
|
||||||
setOf(IdeLocalSourceFragmentDependency(mpp.project, "main", "common")),
|
|
||||||
resolveIdeDependenciesSet(kpm.main.common)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-71
@@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@file:OptIn(InternalIdeApi::class)
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.plugin.ide
|
|
||||||
|
|
||||||
import org.gradle.api.Project
|
|
||||||
import org.gradle.api.artifacts.component.BuildIdentifier
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinGradleFragment
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.currentBuildId
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Entity sent to the IDE for importing dependencies of [KotlinGradleFragment]s
|
|
||||||
* @see IdeLocalSourceFragmentDependency
|
|
||||||
* @see IdeMavenBinaryFragmentDependency
|
|
||||||
*/
|
|
||||||
@InternalIdeApi
|
|
||||||
sealed class IdeFragmentDependency
|
|
||||||
|
|
||||||
/**
|
|
||||||
* "Project to Project" / "Source" Dependency on any Gradle project's fragment
|
|
||||||
*/
|
|
||||||
@InternalIdeApi
|
|
||||||
data class IdeLocalSourceFragmentDependency(
|
|
||||||
val buildId: BuildIdentifier,
|
|
||||||
val projectPath: String,
|
|
||||||
val projectName: String,
|
|
||||||
val kotlinModuleName: String,
|
|
||||||
val kotlinFragmentName: String
|
|
||||||
) : IdeFragmentDependency() {
|
|
||||||
constructor(
|
|
||||||
project: Project,
|
|
||||||
kotlinModuleName: String,
|
|
||||||
kotlinFragmentName: String
|
|
||||||
) : this(
|
|
||||||
buildId = project.currentBuildId(),
|
|
||||||
projectPath = project.path,
|
|
||||||
projectName = project.name,
|
|
||||||
kotlinModuleName = kotlinModuleName,
|
|
||||||
kotlinFragmentName = kotlinFragmentName
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Binary dependency provided by a (maven) repository
|
|
||||||
* Can be identified by maven coordinates (group, module, version).
|
|
||||||
* One artifact downloaded by such repository might get transformed into several dependencies
|
|
||||||
* on certain [kotlinFragmentName].
|
|
||||||
*/
|
|
||||||
@InternalIdeApi
|
|
||||||
data class IdeMavenBinaryFragmentDependency(
|
|
||||||
val mavenGroup: String,
|
|
||||||
val mavenModule: String,
|
|
||||||
val version: String,
|
|
||||||
/**
|
|
||||||
* `null` when binary dependency was not resolved using granular metadata transformation,
|
|
||||||
* but just kept 'as is'
|
|
||||||
*/
|
|
||||||
val kotlinModuleName: String?,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* `null` when binary dependency was not resolved using granular metadata transformation,
|
|
||||||
* but just kept 'as is'
|
|
||||||
*/
|
|
||||||
val kotlinFragmentName: String?,
|
|
||||||
val files: List<File>
|
|
||||||
) : IdeFragmentDependency()
|
|
||||||
-127
@@ -1,127 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
@file:OptIn(InternalIdeApi::class)
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.plugin.ide
|
|
||||||
|
|
||||||
import org.gradle.api.Project
|
|
||||||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
|
|
||||||
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
|
|
||||||
import org.jetbrains.kotlin.gradle.dsl.pm20Extension
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.getSourceSetCompiledMetadata
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.FragmentGranularMetadataResolverFactory
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinGradleFragment
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinGradleModule.Companion.moduleName
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.kpmModules
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.toModuleDependency
|
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.SourceSetMetadataStorageForIde
|
|
||||||
import org.jetbrains.kotlin.project.model.KotlinModuleIdentifier
|
|
||||||
import org.jetbrains.kotlin.project.model.LocalModuleIdentifier
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called by the IDE during import to resolve dependencies on a certain fragment
|
|
||||||
*/
|
|
||||||
@InternalIdeApi
|
|
||||||
interface IdeFragmentDependencyResolver {
|
|
||||||
val project: Project
|
|
||||||
fun resolveDependencies(moduleName: String, fragmentName: String): List<IdeFragmentDependency>
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
@JvmStatic
|
|
||||||
fun create(project: Project): IdeFragmentDependencyResolver =
|
|
||||||
IdeFragmentDependencyResolverImpl(project, FragmentGranularMetadataResolverFactory())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun IdeFragmentDependencyResolver.resolveDependencies(kotlinGradleFragment: KotlinGradleFragment): List<IdeFragmentDependency> {
|
|
||||||
require(kotlinGradleFragment.project == project) {
|
|
||||||
"IdeFragmentDependencyResolver for project ${project.path} can't resolve dependencies for foreign fragment " +
|
|
||||||
"${kotlinGradleFragment.project.path}:${kotlinGradleFragment.containingModule.name}/${kotlinGradleFragment.name}"
|
|
||||||
}
|
|
||||||
return resolveDependencies(kotlinGradleFragment.containingModule.name, kotlinGradleFragment.name)
|
|
||||||
}
|
|
||||||
|
|
||||||
private class IdeFragmentDependencyResolverImpl(
|
|
||||||
override val project: Project,
|
|
||||||
private val fragmentGranularMetadataResolverFactory: FragmentGranularMetadataResolverFactory
|
|
||||||
) : IdeFragmentDependencyResolver {
|
|
||||||
override fun resolveDependencies(moduleName: String, fragmentName: String): List<IdeFragmentDependency> {
|
|
||||||
val fragment = project.kpmModules.getByName(moduleName).fragments.getByName(fragmentName)
|
|
||||||
val fragmentGranularMetadataResolver = fragmentGranularMetadataResolverFactory.getOrCreate(fragment)
|
|
||||||
return fragmentGranularMetadataResolver.resolutions.flatMap { resolution ->
|
|
||||||
resolveDependenciesForIde(fragment, resolution)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun resolveDependenciesForIde(
|
|
||||||
fragment: KotlinGradleFragment, resolution: MetadataDependencyResolution
|
|
||||||
): List<IdeFragmentDependency> {
|
|
||||||
val moduleIdentifier = resolution.dependency.toModuleDependency().moduleIdentifier
|
|
||||||
return when (val dependencyId = resolution.dependency.id) {
|
|
||||||
is ProjectComponentIdentifier ->
|
|
||||||
resolveLocalSourceMetadataDependencies(resolution, dependencyId, moduleIdentifier)
|
|
||||||
is ModuleComponentIdentifier ->
|
|
||||||
resolveMavenBinaryMetadataDependencies(fragment, resolution, dependencyId, moduleIdentifier)
|
|
||||||
else -> emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun resolveLocalSourceMetadataDependencies(
|
|
||||||
resolution: MetadataDependencyResolution,
|
|
||||||
dependencyId: ProjectComponentIdentifier,
|
|
||||||
kotlinModuleIdentifier: KotlinModuleIdentifier
|
|
||||||
): List<IdeLocalSourceFragmentDependency> {
|
|
||||||
if (kotlinModuleIdentifier !is LocalModuleIdentifier) return emptyList()
|
|
||||||
if (resolution !is MetadataDependencyResolution.ChooseVisibleSourceSets) return emptyList()
|
|
||||||
return resolution.allVisibleSourceSetNames.map { fragmentName ->
|
|
||||||
IdeLocalSourceFragmentDependency(
|
|
||||||
buildId = dependencyId.build,
|
|
||||||
projectPath = dependencyId.projectPath,
|
|
||||||
projectName = dependencyId.projectName,
|
|
||||||
kotlinModuleName = kotlinModuleIdentifier.moduleName,
|
|
||||||
kotlinFragmentName = fragmentName
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun resolveMavenBinaryMetadataDependencies(
|
|
||||||
fragment: KotlinGradleFragment,
|
|
||||||
resolution: MetadataDependencyResolution,
|
|
||||||
dependencyId: ModuleComponentIdentifier,
|
|
||||||
kotlinModuleIdentifier: KotlinModuleIdentifier,
|
|
||||||
): List<IdeMavenBinaryFragmentDependency> {
|
|
||||||
return when (resolution) {
|
|
||||||
is MetadataDependencyResolution.ChooseVisibleSourceSets ->
|
|
||||||
resolveMavenBinaryMetadataDependencies(fragment, resolution, dependencyId, kotlinModuleIdentifier)
|
|
||||||
is MetadataDependencyResolution.KeepOriginalDependency -> emptyList() // TODO
|
|
||||||
is MetadataDependencyResolution.ExcludeAsUnrequested -> emptyList()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun resolveMavenBinaryMetadataDependencies(
|
|
||||||
fragment: KotlinGradleFragment,
|
|
||||||
resolution: MetadataDependencyResolution.ChooseVisibleSourceSets,
|
|
||||||
dependencyId: ModuleComponentIdentifier,
|
|
||||||
kotlinModuleIdentifier: KotlinModuleIdentifier,
|
|
||||||
): List<IdeMavenBinaryFragmentDependency> {
|
|
||||||
return resolution.allVisibleSourceSetNames.map { fragmentName ->
|
|
||||||
IdeMavenBinaryFragmentDependency(
|
|
||||||
mavenGroup = dependencyId.group,
|
|
||||||
mavenModule = dependencyId.module,
|
|
||||||
kotlinModuleName = kotlinModuleIdentifier.moduleName,
|
|
||||||
kotlinFragmentName = fragmentName,
|
|
||||||
version = dependencyId.version,
|
|
||||||
files = resolution.metadataProvider.getSourceSetCompiledMetadata(
|
|
||||||
project = fragment.project,
|
|
||||||
sourceSetName = fragmentName,
|
|
||||||
outputDirectoryWhenMaterialised = SourceSetMetadataStorageForIde.sourceSetStorage(fragment.project, fragmentName),
|
|
||||||
materializeFilesIfNecessary = true
|
|
||||||
).toList()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-9
@@ -1,9 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.plugin.ide
|
|
||||||
|
|
||||||
@RequiresOptIn(level = RequiresOptIn.Level.ERROR)
|
|
||||||
annotation class InternalIdeApi()
|
|
||||||
Reference in New Issue
Block a user