[KPM] Integrate refines dependencies into IdeaKotlinSourceDependency
KT-51386
This commit is contained in:
committed by
Space
parent
0f8f61c373
commit
e1ead6b8bf
+10
-1
@@ -101,7 +101,6 @@ public final class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinDependencyKt {
|
|||||||
|
|
||||||
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragment : java/io/Serializable {
|
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragment : java/io/Serializable {
|
||||||
public abstract fun getDependencies ()Ljava/util/List;
|
public abstract fun getDependencies ()Ljava/util/List;
|
||||||
public abstract fun getDirectRefinesDependencies ()Ljava/util/List;
|
|
||||||
public abstract fun getExternal ()Lorg/jetbrains/kotlin/gradle/kpm/KotlinExternalModelContainer;
|
public abstract fun getExternal ()Lorg/jetbrains/kotlin/gradle/kpm/KotlinExternalModelContainer;
|
||||||
public abstract fun getLanguageSettings ()Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinLanguageSettings;
|
public abstract fun getLanguageSettings ()Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinLanguageSettings;
|
||||||
public abstract fun getModuleIdentifier ()Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModuleIdentifier;
|
public abstract fun getModuleIdentifier ()Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModuleIdentifier;
|
||||||
@@ -216,6 +215,16 @@ public final class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceCoordina
|
|||||||
|
|
||||||
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceDependency : org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinDependency {
|
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceDependency : org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinDependency {
|
||||||
public abstract fun getCoordinates ()Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceCoordinates;
|
public abstract fun getCoordinates ()Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceCoordinates;
|
||||||
|
public abstract fun getType ()Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceDependency$Type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceDependency$Type : java/lang/Enum, java/io/Serializable {
|
||||||
|
public static final field Companion Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceDependency$Type$Companion;
|
||||||
|
public static final field Friend Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceDependency$Type;
|
||||||
|
public static final field Refines Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceDependency$Type;
|
||||||
|
public static final field Regular Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceDependency$Type;
|
||||||
|
public static fun valueOf (Ljava/lang/String;)Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceDependency$Type;
|
||||||
|
public static fun values ()[Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceDependency$Type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceDirectory : java/io/Serializable {
|
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceDirectory : java/io/Serializable {
|
||||||
|
|||||||
+15
-2
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKotlinDependency.Companion.DOCUM
|
|||||||
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKotlinDependency.Companion.SOURCES_BINARY_TYPE
|
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKotlinDependency.Companion.SOURCES_BINARY_TYPE
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
sealed interface IdeaKotlinDependency : Serializable {
|
sealed interface IdeaKotlinDependency : Serializable {
|
||||||
val coordinates: IdeaKotlinDependencyCoordinates?
|
val coordinates: IdeaKotlinDependencyCoordinates?
|
||||||
@@ -37,6 +38,16 @@ sealed interface IdeaKotlinSourceCoordinates : IdeaKotlinDependencyCoordinates {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sealed interface IdeaKotlinSourceDependency : IdeaKotlinDependency {
|
sealed interface IdeaKotlinSourceDependency : IdeaKotlinDependency {
|
||||||
|
enum class Type : Serializable {
|
||||||
|
Regular, Friend, Refines;
|
||||||
|
|
||||||
|
@InternalKotlinGradlePluginApi
|
||||||
|
companion object {
|
||||||
|
private const val serialVersionUID = 0L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val type: Type
|
||||||
override val coordinates: IdeaKotlinSourceCoordinates
|
override val coordinates: IdeaKotlinSourceCoordinates
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,12 +78,14 @@ val IdeaKotlinResolvedBinaryDependency.isClasspathType get() = binaryType == CLA
|
|||||||
|
|
||||||
@InternalKotlinGradlePluginApi
|
@InternalKotlinGradlePluginApi
|
||||||
data class IdeaKotlinSourceDependencyImpl(
|
data class IdeaKotlinSourceDependencyImpl(
|
||||||
|
override val type: IdeaKotlinSourceDependency.Type,
|
||||||
override val coordinates: IdeaKotlinSourceCoordinates,
|
override val coordinates: IdeaKotlinSourceCoordinates,
|
||||||
override val external: KotlinExternalModelContainer = KotlinExternalModelContainer.Empty
|
override val external: KotlinExternalModelContainer = KotlinExternalModelContainer.Empty,
|
||||||
) : IdeaKotlinSourceDependency {
|
) : IdeaKotlinSourceDependency {
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "source: $coordinates"
|
@Suppress("DEPRECATION")
|
||||||
|
return "${type.name.toLowerCase(Locale.ROOT)}:$coordinates"
|
||||||
}
|
}
|
||||||
|
|
||||||
@InternalKotlinGradlePluginApi
|
@InternalKotlinGradlePluginApi
|
||||||
|
|||||||
-2
@@ -14,7 +14,6 @@ interface IdeaKotlinFragment : Serializable {
|
|||||||
val platforms: Set<IdeaKotlinPlatform>
|
val platforms: Set<IdeaKotlinPlatform>
|
||||||
val languageSettings: IdeaKotlinLanguageSettings?
|
val languageSettings: IdeaKotlinLanguageSettings?
|
||||||
val dependencies: List<IdeaKotlinDependency>
|
val dependencies: List<IdeaKotlinDependency>
|
||||||
val directRefinesDependencies: List<IdeaKotlinFragment>
|
|
||||||
val sourceDirectories: List<IdeaKotlinSourceDirectory>
|
val sourceDirectories: List<IdeaKotlinSourceDirectory>
|
||||||
val resourceDirectories: List<IdeaKotlinResourceDirectory>
|
val resourceDirectories: List<IdeaKotlinResourceDirectory>
|
||||||
val external: KotlinExternalModelContainer
|
val external: KotlinExternalModelContainer
|
||||||
@@ -27,7 +26,6 @@ data class IdeaKotlinFragmentImpl(
|
|||||||
override val platforms: Set<IdeaKotlinPlatform>,
|
override val platforms: Set<IdeaKotlinPlatform>,
|
||||||
override val languageSettings: IdeaKotlinLanguageSettings?,
|
override val languageSettings: IdeaKotlinLanguageSettings?,
|
||||||
override val dependencies: List<IdeaKotlinDependency>,
|
override val dependencies: List<IdeaKotlinDependency>,
|
||||||
override val directRefinesDependencies: List<IdeaKotlinFragment>,
|
|
||||||
override val sourceDirectories: List<IdeaKotlinSourceDirectory>,
|
override val sourceDirectories: List<IdeaKotlinSourceDirectory>,
|
||||||
override val resourceDirectories: List<IdeaKotlinResourceDirectory>,
|
override val resourceDirectories: List<IdeaKotlinResourceDirectory>,
|
||||||
override val external: KotlinExternalModelContainer
|
override val external: KotlinExternalModelContainer
|
||||||
|
|||||||
+6
-7
@@ -1,7 +1,6 @@
|
|||||||
package org.jetbrains.kotlin.gradle.kpm.idea.testFixtures
|
package org.jetbrains.kotlin.gradle.kpm.idea.testFixtures
|
||||||
|
|
||||||
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKotlinSourceDependency
|
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKotlinSourceDependency
|
||||||
import org.jetbrains.kotlin.gradle.kpm.idea.path
|
|
||||||
|
|
||||||
fun buildIdeaKotlinSourceDependencyMatchers(notation: Any?): List<IdeaKotlinSourceDependencyMatcher> {
|
fun buildIdeaKotlinSourceDependencyMatchers(notation: Any?): List<IdeaKotlinSourceDependencyMatcher> {
|
||||||
return when (notation) {
|
return when (notation) {
|
||||||
@@ -14,19 +13,19 @@ fun buildIdeaKotlinSourceDependencyMatchers(notation: Any?): List<IdeaKotlinSour
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IdeaKotlinSourceDependencyMatcher : IdeaKotlinDependencyMatcher<IdeaKotlinSourceDependency> {
|
interface IdeaKotlinSourceDependencyMatcher : IdeaKotlinDependencyMatcher<IdeaKotlinSourceDependency> {
|
||||||
class FragmentPath(private val path: String) : IdeaKotlinSourceDependencyMatcher {
|
class FragmentPath(private val dependency: String) : IdeaKotlinSourceDependencyMatcher {
|
||||||
override val description: String = path
|
override val description: String = dependency
|
||||||
|
|
||||||
override fun matches(dependency: IdeaKotlinSourceDependency): Boolean {
|
override fun matches(dependency: IdeaKotlinSourceDependency): Boolean {
|
||||||
return path == dependency.coordinates.path
|
return this.dependency == dependency.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FragmentPathRegex(private val pathRegex: Regex) : IdeaKotlinSourceDependencyMatcher {
|
class FragmentPathRegex(private val dependencyRegex: Regex) : IdeaKotlinSourceDependencyMatcher {
|
||||||
override val description: String = pathRegex.pattern
|
override val description: String = dependencyRegex.pattern
|
||||||
|
|
||||||
override fun matches(dependency: IdeaKotlinSourceDependency): Boolean {
|
override fun matches(dependency: IdeaKotlinSourceDependency): Boolean {
|
||||||
return pathRegex.matches(dependency.coordinates.path)
|
return dependencyRegex.matches(dependency.toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-10
@@ -105,33 +105,30 @@ fun IdeaKotlinFragment.assertSourceDependencies(matchers: Set<IdeaKotlinSourceDe
|
|||||||
return sourceDependencies
|
return sourceDependencies
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val fragmentIdentifier = "${moduleIdentifier.moduleClassifier?.plus("/").orEmpty()}${name}"
|
||||||
|
|
||||||
fail(
|
fail(
|
||||||
buildString {
|
buildString {
|
||||||
if (unexpectedDependencies.isNotEmpty()) {
|
if (unexpectedDependencies.isNotEmpty()) {
|
||||||
appendLine("${name}: Unexpected source dependencies found:")
|
|
||||||
unexpectedDependencies.forEach { unexpectedDependency ->
|
|
||||||
appendLine(unexpectedDependency)
|
|
||||||
}
|
|
||||||
|
|
||||||
appendLine()
|
appendLine()
|
||||||
appendLine("${name}: Unexpected source dependency paths:")
|
appendLine("${fragmentIdentifier}: Unexpected source dependency found:")
|
||||||
unexpectedDependencies.forEach { unexpectedDependency ->
|
unexpectedDependencies.forEach { unexpectedDependency ->
|
||||||
appendLine("\"${unexpectedDependency.coordinates.path}\",")
|
appendLine("\"${unexpectedDependency}\",")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (missingDependencies.isNotEmpty()) {
|
if (missingDependencies.isNotEmpty()) {
|
||||||
appendLine()
|
appendLine()
|
||||||
appendLine("${name}: Missing fragment dependencies:")
|
appendLine("${fragmentIdentifier}: Missing fragment dependencies:")
|
||||||
missingDependencies.forEach { missingDependency ->
|
missingDependencies.forEach { missingDependency ->
|
||||||
appendLine(missingDependency.description)
|
appendLine(missingDependency.description)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
appendLine()
|
appendLine()
|
||||||
appendLine("${name}: Resolved source dependency paths:")
|
appendLine("${fragmentIdentifier}: Resolved source dependency paths:")
|
||||||
sourceDependencies.forEach { dependency ->
|
sourceDependencies.forEach { dependency ->
|
||||||
appendLine("\"${dependency.coordinates.path}\",")
|
appendLine("\"${dependency}\",")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
+78
-39
@@ -82,75 +82,114 @@ class SimpleProjectToProjectDependencyResolutionTest : AbstractLightweightIdeaDe
|
|||||||
fun ifTestModule(vararg any: Any?) =
|
fun ifTestModule(vararg any: Any?) =
|
||||||
listOf(*any).takeIf { module.name == KotlinGradleModule.TEST_MODULE_NAME }
|
listOf(*any).takeIf { module.name == KotlinGradleModule.TEST_MODULE_NAME }
|
||||||
|
|
||||||
|
fun ifMainModule(vararg any: Any?) =
|
||||||
|
listOf(*any).takeIf { module.name == KotlinGradleModule.MAIN_MODULE_NAME }
|
||||||
|
|
||||||
module.assertContainsFragment("common").assertSourceDependencies(
|
module.assertContainsFragment("common").assertSourceDependencies(
|
||||||
":producer/main/common",
|
"regular::producer/main/common",
|
||||||
ifTestModule(":consumer/main/common")
|
ifTestModule("friend::consumer/main/common")
|
||||||
)
|
)
|
||||||
|
|
||||||
module.assertContainsFragment("jvm").assertSourceDependencies(
|
module.assertContainsFragment("jvm").assertSourceDependencies(
|
||||||
":producer/main/jvm",
|
"regular::producer/main/jvm",
|
||||||
":producer/main/common",
|
"regular::producer/main/common",
|
||||||
|
ifMainModule(
|
||||||
|
"refines::consumer/main/common",
|
||||||
|
),
|
||||||
ifTestModule(
|
ifTestModule(
|
||||||
":consumer/main/common",
|
"friend::consumer/main/common",
|
||||||
":consumer/main/jvm"
|
"friend::consumer/main/jvm",
|
||||||
|
"refines::consumer/test/common",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
module.assertContainsFragment("nativeCommon").assertSourceDependencies(
|
module.assertContainsFragment("nativeCommon").assertSourceDependencies(
|
||||||
":producer/main/common",
|
"regular::producer/main/common",
|
||||||
":producer/main/nativeCommon",
|
"regular::producer/main/nativeCommon",
|
||||||
|
ifMainModule(
|
||||||
|
"refines::consumer/main/common"
|
||||||
|
),
|
||||||
ifTestModule(
|
ifTestModule(
|
||||||
":consumer/main/common",
|
"friend::consumer/main/common",
|
||||||
":consumer/main/nativeCommon"
|
"friend::consumer/main/nativeCommon",
|
||||||
|
"refines::consumer/test/common",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
module.assertContainsFragment("appleCommon").assertSourceDependencies(
|
module.assertContainsFragment("appleCommon").assertSourceDependencies(
|
||||||
":producer/main/common",
|
"regular::producer/main/common",
|
||||||
":producer/main/appleCommon",
|
"regular::producer/main/appleCommon",
|
||||||
":producer/main/nativeCommon",
|
"regular::producer/main/nativeCommon",
|
||||||
|
ifMainModule(
|
||||||
|
"refines::consumer/main/common",
|
||||||
|
"refines::consumer/main/nativeCommon"
|
||||||
|
),
|
||||||
ifTestModule(
|
ifTestModule(
|
||||||
":consumer/main/common",
|
"friend::consumer/main/common",
|
||||||
":consumer/main/nativeCommon",
|
"friend::consumer/main/nativeCommon",
|
||||||
":consumer/main/appleCommon"
|
"friend::consumer/main/appleCommon",
|
||||||
|
"refines::consumer/test/common",
|
||||||
|
"refines::consumer/test/nativeCommon"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
module.assertContainsFragment("linuxX64").assertSourceDependencies(
|
module.assertContainsFragment("linuxX64").assertSourceDependencies(
|
||||||
":producer/main/common",
|
"regular::producer/main/common",
|
||||||
":producer/main/nativeCommon",
|
"regular::producer/main/nativeCommon",
|
||||||
":producer/main/linuxX64",
|
"regular::producer/main/linuxX64",
|
||||||
|
ifMainModule(
|
||||||
|
"refines::consumer/main/common",
|
||||||
|
"refines::consumer/main/nativeCommon",
|
||||||
|
),
|
||||||
ifTestModule(
|
ifTestModule(
|
||||||
":consumer/main/common",
|
"friend::consumer/main/common",
|
||||||
":consumer/main/nativeCommon",
|
"friend::consumer/main/nativeCommon",
|
||||||
":consumer/main/linuxX64"
|
"friend::consumer/main/linuxX64",
|
||||||
|
"refines::consumer/test/common",
|
||||||
|
"refines::consumer/test/nativeCommon"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
module.assertContainsFragment("macosX64").assertSourceDependencies(
|
module.assertContainsFragment("macosX64").assertSourceDependencies(
|
||||||
":producer/main/macosX64",
|
"regular::producer/main/macosX64",
|
||||||
":producer/main/common",
|
"regular::producer/main/common",
|
||||||
":producer/main/appleCommon",
|
"regular::producer/main/appleCommon",
|
||||||
":producer/main/nativeCommon",
|
"regular::producer/main/nativeCommon",
|
||||||
|
ifMainModule(
|
||||||
|
"refines::consumer/main/common",
|
||||||
|
"refines::consumer/main/nativeCommon",
|
||||||
|
"refines::consumer/main/appleCommon"
|
||||||
|
),
|
||||||
ifTestModule(
|
ifTestModule(
|
||||||
":consumer/main/common",
|
"friend::consumer/main/common",
|
||||||
":consumer/main/nativeCommon",
|
"friend::consumer/main/nativeCommon",
|
||||||
":consumer/main/appleCommon",
|
"friend::consumer/main/appleCommon",
|
||||||
":consumer/main/macosX64"
|
"friend::consumer/main/macosX64",
|
||||||
|
"refines::consumer/test/common",
|
||||||
|
"refines::consumer/test/nativeCommon",
|
||||||
|
"refines::consumer/test/appleCommon"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
module.assertContainsFragment("iosX64").assertSourceDependencies(
|
module.assertContainsFragment("iosX64").assertSourceDependencies(
|
||||||
":producer/main/iosX64",
|
"regular::producer/main/iosX64",
|
||||||
":producer/main/common",
|
"regular::producer/main/common",
|
||||||
":producer/main/iosMain",
|
"regular::producer/main/iosMain",
|
||||||
":producer/main/appleCommon",
|
"regular::producer/main/appleCommon",
|
||||||
":producer/main/nativeCommon",
|
"regular::producer/main/nativeCommon",
|
||||||
|
ifMainModule(
|
||||||
|
"refines::consumer/main/common",
|
||||||
|
"refines::consumer/main/nativeCommon",
|
||||||
|
"refines::consumer/main/appleCommon"
|
||||||
|
),
|
||||||
ifTestModule(
|
ifTestModule(
|
||||||
":consumer/main/common",
|
"friend::consumer/main/common",
|
||||||
":consumer/main/nativeCommon",
|
"friend::consumer/main/nativeCommon",
|
||||||
":consumer/main/appleCommon",
|
"friend::consumer/main/appleCommon",
|
||||||
":consumer/main/iosX64"
|
"friend::consumer/main/iosX64",
|
||||||
|
"refines::consumer/test/common",
|
||||||
|
"refines::consumer/test/nativeCommon",
|
||||||
|
"refines::consumer/test/appleCommon"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-15
@@ -8,35 +8,25 @@ package org.jetbrains.kotlin.gradle.kpm.idea
|
|||||||
import org.jetbrains.kotlin.gradle.kpm.KotlinExternalModelContainer
|
import org.jetbrains.kotlin.gradle.kpm.KotlinExternalModelContainer
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.*
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.*
|
||||||
|
|
||||||
internal class IdeaKotlinFragmentBuildingContext(
|
internal fun IdeaKotlinProjectModelBuildingContext.toIdeaKotlinFragment(fragment: KotlinGradleFragment): IdeaKotlinFragment {
|
||||||
private val parent: IdeaKotlinProjectModelBuildingContext
|
return if (fragment is KotlinGradleVariant) buildIdeaKotlinVariant(fragment)
|
||||||
) : IdeaKotlinProjectModelBuildingContext by parent {
|
else buildIdeaKotlinFragment(fragment)
|
||||||
private val fragmentCache = mutableMapOf<KotlinGradleFragment, IdeaKotlinFragment>()
|
|
||||||
fun getOrPut(source: KotlinGradleFragment, builder: () -> IdeaKotlinFragment) = fragmentCache.getOrPut(source, builder)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun IdeaKotlinFragmentBuildingContext.toIdeaKotlinFragment(fragment: KotlinGradleFragment): IdeaKotlinFragment {
|
private fun IdeaKotlinProjectModelBuildingContext.buildIdeaKotlinFragment(fragment: KotlinGradleFragment): IdeaKotlinFragment {
|
||||||
return getOrPut(fragment) {
|
|
||||||
if (fragment is KotlinGradleVariant) buildIdeaKotlinVariant(fragment)
|
|
||||||
else buildIdeaKotlinFragment(fragment)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun IdeaKotlinFragmentBuildingContext.buildIdeaKotlinFragment(fragment: KotlinGradleFragment): IdeaKotlinFragment {
|
|
||||||
return IdeaKotlinFragmentImpl(
|
return IdeaKotlinFragmentImpl(
|
||||||
name = fragment.name,
|
name = fragment.name,
|
||||||
moduleIdentifier = fragment.containingModule.moduleIdentifier.toIdeaKotlinModuleIdentifier(),
|
moduleIdentifier = fragment.containingModule.moduleIdentifier.toIdeaKotlinModuleIdentifier(),
|
||||||
platforms = fragment.containingVariants.map { variant -> buildIdeaKotlinPlatform(variant) }.toSet(),
|
platforms = fragment.containingVariants.map { variant -> buildIdeaKotlinPlatform(variant) }.toSet(),
|
||||||
languageSettings = fragment.languageSettings.toIdeaKotlinLanguageSettings(),
|
languageSettings = fragment.languageSettings.toIdeaKotlinLanguageSettings(),
|
||||||
dependencies = dependencyResolver.resolve(fragment).toList(),
|
dependencies = dependencyResolver.resolve(fragment).toList(),
|
||||||
directRefinesDependencies = fragment.directRefinesDependencies.map { refinesFragment -> toIdeaKotlinFragment(refinesFragment) },
|
|
||||||
sourceDirectories = fragment.kotlinSourceRoots.sourceDirectories.files.toList().map { file -> IdeaKotlinSourceDirectoryImpl(file) },
|
sourceDirectories = fragment.kotlinSourceRoots.sourceDirectories.files.toList().map { file -> IdeaKotlinSourceDirectoryImpl(file) },
|
||||||
resourceDirectories = emptyList(),
|
resourceDirectories = emptyList(),
|
||||||
external = (fragment as? KotlinGradleFragmentInternal)?.external ?: KotlinExternalModelContainer.Empty
|
external = (fragment as? KotlinGradleFragmentInternal)?.external ?: KotlinExternalModelContainer.Empty
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IdeaKotlinFragmentBuildingContext.buildIdeaKotlinVariant(variant: KotlinGradleVariant): IdeaKotlinVariant {
|
private fun IdeaKotlinProjectModelBuildingContext.buildIdeaKotlinVariant(variant: KotlinGradleVariant): IdeaKotlinVariant {
|
||||||
return IdeaKotlinVariantImpl(
|
return IdeaKotlinVariantImpl(
|
||||||
fragment = buildIdeaKotlinFragment(variant),
|
fragment = buildIdeaKotlinFragment(variant),
|
||||||
platform = buildIdeaKotlinPlatform(variant),
|
platform = buildIdeaKotlinPlatform(variant),
|
||||||
|
|||||||
+1
-2
@@ -8,10 +8,9 @@ package org.jetbrains.kotlin.gradle.kpm.idea
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinGradleModule
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinGradleModule
|
||||||
|
|
||||||
internal fun IdeaKotlinProjectModelBuildingContext.toIdeaKotlinModule(module: KotlinGradleModule): IdeaKotlinModule {
|
internal fun IdeaKotlinProjectModelBuildingContext.toIdeaKotlinModule(module: KotlinGradleModule): IdeaKotlinModule {
|
||||||
val fragmentBuildingContext = IdeaKotlinFragmentBuildingContext(this)
|
|
||||||
return IdeaKotlinModuleImpl(
|
return IdeaKotlinModuleImpl(
|
||||||
name = module.name,
|
name = module.name,
|
||||||
moduleIdentifier = module.moduleIdentifier.toIdeaKotlinModuleIdentifier(),
|
moduleIdentifier = module.moduleIdentifier.toIdeaKotlinModuleIdentifier(),
|
||||||
fragments = module.fragments.toList().map { fragment -> fragmentBuildingContext.toIdeaKotlinFragment(fragment) }
|
fragments = module.fragments.toList().map { fragment -> toIdeaKotlinFragment(fragment) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.konan.target.HostManager
|
|||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
/* Receiver acts as scope, or key to that function */
|
/* Receiver acts as scope, or key to that function */
|
||||||
internal fun IdeaKotlinFragmentBuildingContext.buildIdeaKotlinPlatform(variant: KotlinGradleVariant): IdeaKotlinPlatform {
|
internal fun IdeaKotlinProjectModelBuildingContext.buildIdeaKotlinPlatform(variant: KotlinGradleVariant): IdeaKotlinPlatform {
|
||||||
when (variant) {
|
when (variant) {
|
||||||
is KotlinJvmVariant -> return IdeaKotlinPlatform.jvm(variant.compilationData.kotlinOptions.jvmTarget ?: JvmTarget.DEFAULT.name)
|
is KotlinJvmVariant -> return IdeaKotlinPlatform.jvm(variant.compilationData.kotlinOptions.jvmTarget ?: JvmTarget.DEFAULT.name)
|
||||||
is KotlinNativeVariantInternal -> return IdeaKotlinPlatform.native(variant.konanTarget.name)
|
is KotlinNativeVariantInternal -> return IdeaKotlinPlatform.native(variant.konanTarget.name)
|
||||||
|
|||||||
+7
@@ -18,6 +18,13 @@ internal fun IdeaKotlinProjectModelBuilder.Companion.default(
|
|||||||
) = IdeaKotlinProjectModelBuilderImpl(extension).apply {
|
) = IdeaKotlinProjectModelBuilderImpl(extension).apply {
|
||||||
val fragmentMetadataResolverFactory = FragmentGranularMetadataResolverFactory()
|
val fragmentMetadataResolverFactory = FragmentGranularMetadataResolverFactory()
|
||||||
|
|
||||||
|
registerDependencyResolver(
|
||||||
|
resolver = IdeaKotlinRefinesDependencyResolver,
|
||||||
|
constraint = IdeaKotlinProjectModelBuilder.FragmentConstraint.unconstrained,
|
||||||
|
phase = IdeaKotlinProjectModelBuilder.DependencyResolutionPhase.SourceDependencyResolution,
|
||||||
|
level = IdeaKotlinProjectModelBuilder.DependencyResolutionLevel.Default
|
||||||
|
)
|
||||||
|
|
||||||
registerDependencyResolver(
|
registerDependencyResolver(
|
||||||
resolver = IdeaKotlinSourceDependencyResolver(fragmentMetadataResolverFactory),
|
resolver = IdeaKotlinSourceDependencyResolver(fragmentMetadataResolverFactory),
|
||||||
constraint = IdeaKotlinProjectModelBuilder.FragmentConstraint.unconstrained,
|
constraint = IdeaKotlinProjectModelBuilder.FragmentConstraint.unconstrained,
|
||||||
|
|||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2022 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.kpm.idea
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinGradleFragment
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.currentBuildId
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.refinesClosure
|
||||||
|
|
||||||
|
internal object IdeaKotlinRefinesDependencyResolver : IdeaKotlinDependencyResolver {
|
||||||
|
override fun resolve(fragment: KotlinGradleFragment): Set<IdeaKotlinDependency> = fragment.refinesClosure
|
||||||
|
.map { refinesDependencyFragment -> createRefinesDependency(refinesDependencyFragment) }.toSet()
|
||||||
|
|
||||||
|
private fun createRefinesDependency(fragment: KotlinGradleFragment): IdeaKotlinDependency {
|
||||||
|
return IdeaKotlinSourceDependencyImpl(
|
||||||
|
type = IdeaKotlinSourceDependency.Type.Refines,
|
||||||
|
coordinates = IdeaKotlinSourceCoordinatesImpl(
|
||||||
|
buildId = fragment.project.currentBuildId().name,
|
||||||
|
projectPath = fragment.project.path,
|
||||||
|
projectName = fragment.project.name,
|
||||||
|
kotlinModuleName = fragment.containingModule.name,
|
||||||
|
kotlinModuleClassifier = fragment.containingModule.moduleClassifier,
|
||||||
|
kotlinFragmentName = fragment.name
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
+9
-3
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.MetadataDependencyResolution.Choos
|
|||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.FragmentGranularMetadataResolverFactory
|
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.KotlinGradleFragment
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinGradleModule.Companion.moduleName
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinGradleModule.Companion.moduleName
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.currentBuildId
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.toModuleDependency
|
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.toModuleDependency
|
||||||
|
|
||||||
internal class IdeaKotlinSourceDependencyResolver(
|
internal class IdeaKotlinSourceDependencyResolver(
|
||||||
@@ -18,16 +19,21 @@ internal class IdeaKotlinSourceDependencyResolver(
|
|||||||
override fun resolve(fragment: KotlinGradleFragment): Set<IdeaKotlinDependency> {
|
override fun resolve(fragment: KotlinGradleFragment): Set<IdeaKotlinDependency> {
|
||||||
return fragmentGranularMetadataResolverFactory.getOrCreate(fragment).resolutions
|
return fragmentGranularMetadataResolverFactory.getOrCreate(fragment).resolutions
|
||||||
.filterIsInstance<ChooseVisibleSourceSets>()
|
.filterIsInstance<ChooseVisibleSourceSets>()
|
||||||
.flatMap { resolution -> resolve(resolution) }
|
.flatMap { resolution -> resolve(fragment, resolution) }
|
||||||
.toSet()
|
.toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resolve(resolution: ChooseVisibleSourceSets): Iterable<IdeaKotlinDependency> {
|
private fun resolve(fragment: KotlinGradleFragment, resolution: ChooseVisibleSourceSets): Iterable<IdeaKotlinDependency> {
|
||||||
val gradleProjectIdentifier = resolution.dependency.id as? ProjectComponentIdentifier ?: return emptyList()
|
val gradleProjectIdentifier = resolution.dependency.id as? ProjectComponentIdentifier ?: return emptyList()
|
||||||
val kotlinModuleIdentifier = resolution.dependency.toModuleDependency().moduleIdentifier
|
val kotlinModuleIdentifier = resolution.dependency.toModuleDependency().moduleIdentifier
|
||||||
return resolution.allVisibleSourceSetNames.map { visibleFragmentName ->
|
return resolution.allVisibleSourceSetNames.map { visibleFragmentName ->
|
||||||
IdeaKotlinSourceDependencyImpl(
|
IdeaKotlinSourceDependencyImpl(
|
||||||
IdeaKotlinSourceCoordinatesImpl(
|
type = if (
|
||||||
|
gradleProjectIdentifier.build == fragment.project.currentBuildId() &&
|
||||||
|
gradleProjectIdentifier.projectPath == fragment.project.path
|
||||||
|
) IdeaKotlinSourceDependency.Type.Friend
|
||||||
|
else IdeaKotlinSourceDependency.Type.Regular,
|
||||||
|
coordinates = IdeaKotlinSourceCoordinatesImpl(
|
||||||
buildId = gradleProjectIdentifier.build.name,
|
buildId = gradleProjectIdentifier.build.name,
|
||||||
projectPath = gradleProjectIdentifier.projectPath,
|
projectPath = gradleProjectIdentifier.projectPath,
|
||||||
projectName = gradleProjectIdentifier.projectName,
|
projectName = gradleProjectIdentifier.projectName,
|
||||||
|
|||||||
Reference in New Issue
Block a user