[KPM] Remove IdeaKotlinModuleIdentifier in favor of consistent IdeaKotlinFragmentCoordinates

KT-51386
This commit is contained in:
sebastian.sellmair
2022-03-16 10:46:05 +01:00
committed by Space
parent ef3a3d71b9
commit 1a0d8f777c
23 changed files with 277 additions and 269 deletions
@@ -93,23 +93,48 @@ public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinD
}
public final class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinDependencyKt {
public static final fun getPath (Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceCoordinates;)Ljava/lang/String;
public static final fun isClasspathType (Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinResolvedBinaryDependency;)Z
public static final fun isDocumentationType (Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinResolvedBinaryDependency;)Z
public static final fun isSourcesType (Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinResolvedBinaryDependency;)Z
}
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragment : java/io/Serializable {
public abstract fun getCoordinates ()Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentCoordinates;
public abstract fun getDependencies ()Ljava/util/List;
public abstract fun getExternal ()Lorg/jetbrains/kotlin/gradle/kpm/KotlinExternalModelContainer;
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 getName ()Ljava/lang/String;
public abstract fun getPlatforms ()Ljava/util/Set;
public abstract fun getResourceDirectories ()Ljava/util/List;
public abstract fun getSourceDirectories ()Ljava/util/List;
}
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentCoordinates : java/io/Serializable, org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinDependencyCoordinates {
public abstract fun getFragmentName ()Ljava/lang/String;
public abstract fun getModule ()Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModuleCoordinates;
}
public final class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentCoordinatesKt {
public static final fun getPath (Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentCoordinates;)Ljava/lang/String;
}
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentDependency : org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinDependency {
public abstract fun getCoordinates ()Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentCoordinates;
public abstract fun getType ()Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentDependency$Type;
}
public final class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentDependency$Type : java/lang/Enum, java/io/Serializable {
public static final field Companion Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentDependency$Type$Companion;
public static final field Friend Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentDependency$Type;
public static final field Refines Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentDependency$Type;
public static final field Regular Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentDependency$Type;
public static fun valueOf (Ljava/lang/String;)Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentDependency$Type;
public static fun values ()[Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentDependency$Type;
}
public final class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragmentKt {
public static final fun getName (Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinFragment;)Ljava/lang/String;
}
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinJsPlatformDetails : org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinPlatformDetails {
public abstract fun isIr ()Z
}
@@ -129,24 +154,26 @@ public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinL
public abstract fun isProgressiveMode ()Z
}
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinLocalModuleIdentifier : org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModuleIdentifier {
public abstract fun getBuildId ()Ljava/lang/String;
public abstract fun getProjectId ()Ljava/lang/String;
}
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinMavenModuleIdentifier : org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModuleIdentifier {
public abstract fun getGroup ()Ljava/lang/String;
public abstract fun getName ()Ljava/lang/String;
}
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModule : java/io/Serializable {
public abstract fun getCoordinates ()Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModuleCoordinates;
public abstract fun getFragments ()Ljava/util/List;
public abstract fun getModuleIdentifier ()Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModuleIdentifier;
public abstract fun getName ()Ljava/lang/String;
}
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModuleIdentifier : java/io/Serializable {
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModuleCoordinates : java/io/Serializable {
public abstract fun getBuildId ()Ljava/lang/String;
public abstract fun getModuleClassifier ()Ljava/lang/String;
public abstract fun getModuleName ()Ljava/lang/String;
public abstract fun getProjectName ()Ljava/lang/String;
public abstract fun getProjectPath ()Ljava/lang/String;
}
public final class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModuleCoordinatesKt {
public static final fun getPath (Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModuleCoordinates;)Ljava/lang/String;
}
public final class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModuleKt {
public static final fun getModuleClassifier (Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModule;)Ljava/lang/String;
public static final fun getName (Lorg/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinModule;)Ljava/lang/String;
}
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinNativePlatformDetails : org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinPlatformDetails {
@@ -201,32 +228,6 @@ public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinR
public abstract fun getFile ()Ljava/io/File;
}
public abstract interface class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceCoordinates : org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinDependencyCoordinates {
public abstract fun getBuildId ()Ljava/lang/String;
public abstract fun getKotlinFragmentName ()Ljava/lang/String;
public abstract fun getKotlinModuleClassifier ()Ljava/lang/String;
public abstract fun getKotlinModuleName ()Ljava/lang/String;
public abstract fun getProjectName ()Ljava/lang/String;
public abstract fun getProjectPath ()Ljava/lang/String;
}
public final class org/jetbrains/kotlin/gradle/kpm/idea/IdeaKotlinSourceCoordinatesImpl$Companion {
}
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 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 fun getFile ()Ljava/io/File;
}
@@ -0,0 +1,34 @@
/*
* 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
sealed interface IdeaKotlinBinaryCoordinates : IdeaKotlinDependencyCoordinates {
val group: String
val module: String
val version: String
val kotlinModuleName: String?
val kotlinFragmentName: String?
}
@InternalKotlinGradlePluginApi
data class IdeaKotlinBinaryCoordinatesImpl(
override val group: String,
override val module: String,
override val version: String,
override val kotlinModuleName: String? = null,
override val kotlinFragmentName: String? = null
) : IdeaKotlinBinaryCoordinates {
override fun toString(): String {
return "$group:$module:$version" +
(if (kotlinModuleName != null) ":$kotlinModuleName" else "") +
(if (kotlinFragmentName != null) ":$kotlinFragmentName" else "")
}
companion object {
private const val serialVersionUID = 0L
}
}
@@ -26,18 +26,7 @@ sealed interface IdeaKotlinDependency : Serializable {
}
}
sealed interface IdeaKotlinDependencyCoordinates : Serializable
sealed interface IdeaKotlinSourceCoordinates : IdeaKotlinDependencyCoordinates {
val buildId: String
val projectPath: String
val projectName: String
val kotlinModuleName: String
val kotlinModuleClassifier: String?
val kotlinFragmentName: String
}
sealed interface IdeaKotlinSourceDependency : IdeaKotlinDependency {
sealed interface IdeaKotlinFragmentDependency : IdeaKotlinDependency {
enum class Type : Serializable {
Regular, Friend, Refines;
@@ -48,15 +37,7 @@ sealed interface IdeaKotlinSourceDependency : IdeaKotlinDependency {
}
val type: Type
override val coordinates: IdeaKotlinSourceCoordinates
}
sealed interface IdeaKotlinBinaryCoordinates : IdeaKotlinDependencyCoordinates {
val group: String
val module: String
val version: String
val kotlinModuleName: String?
val kotlinFragmentName: String?
override val coordinates: IdeaKotlinFragmentCoordinates
}
sealed interface IdeaKotlinBinaryDependency : IdeaKotlinDependency {
@@ -77,11 +58,11 @@ val IdeaKotlinResolvedBinaryDependency.isDocumentationType get() = binaryType ==
val IdeaKotlinResolvedBinaryDependency.isClasspathType get() = binaryType == CLASSPATH_BINARY_TYPE
@InternalKotlinGradlePluginApi
data class IdeaKotlinSourceDependencyImpl(
override val type: IdeaKotlinSourceDependency.Type,
override val coordinates: IdeaKotlinSourceCoordinates,
data class IdeaKotlinFragmentDependencyImpl(
override val type: IdeaKotlinFragmentDependency.Type,
override val coordinates: IdeaKotlinFragmentCoordinates,
override val external: KotlinExternalModelContainer = KotlinExternalModelContainer.Empty,
) : IdeaKotlinSourceDependency {
) : IdeaKotlinFragmentDependency {
override fun toString(): String {
@Suppress("DEPRECATION")
@@ -94,46 +75,6 @@ data class IdeaKotlinSourceDependencyImpl(
}
}
@InternalKotlinGradlePluginApi
data class IdeaKotlinBinaryCoordinatesImpl(
override val group: String,
override val module: String,
override val version: String,
override val kotlinModuleName: String? = null,
override val kotlinFragmentName: String? = null
) : IdeaKotlinBinaryCoordinates {
override fun toString(): String {
return "$group:$module:$version" +
(if (kotlinModuleName != null) ":$kotlinModuleName" else "") +
(if (kotlinFragmentName != null) ":$kotlinFragmentName" else "")
}
companion object {
private const val serialVersionUID = 0L
}
}
@InternalKotlinGradlePluginApi
data class IdeaKotlinSourceCoordinatesImpl(
override val buildId: String,
override val projectPath: String,
override val projectName: String,
override val kotlinModuleName: String,
override val kotlinModuleClassifier: String?,
override val kotlinFragmentName: String
) : IdeaKotlinSourceCoordinates {
override fun toString(): String = path
companion object {
private const val serialVersionUID = 0L
}
}
val IdeaKotlinSourceCoordinates.path: String
get() = "${buildId.takeIf { it != ":" }.orEmpty()}$projectPath/$kotlinModuleName/$kotlinFragmentName"
@InternalKotlinGradlePluginApi
data class IdeaKotlinResolvedBinaryDependencyImpl(
override val coordinates: IdeaKotlinBinaryCoordinates?,
@@ -0,0 +1,10 @@
/*
* 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 java.io.Serializable
sealed interface IdeaKotlinDependencyCoordinates : Serializable
@@ -9,8 +9,7 @@ import org.jetbrains.kotlin.gradle.kpm.KotlinExternalModelContainer
import java.io.Serializable
interface IdeaKotlinFragment : Serializable {
val name: String
val moduleIdentifier: IdeaKotlinModuleIdentifier
val coordinates: IdeaKotlinFragmentCoordinates
val platforms: Set<IdeaKotlinPlatform>
val languageSettings: IdeaKotlinLanguageSettings?
val dependencies: List<IdeaKotlinDependency>
@@ -19,10 +18,11 @@ interface IdeaKotlinFragment : Serializable {
val external: KotlinExternalModelContainer
}
val IdeaKotlinFragment.name get() = coordinates.fragmentName
@InternalKotlinGradlePluginApi
data class IdeaKotlinFragmentImpl(
override val name: String,
override val moduleIdentifier: IdeaKotlinModuleIdentifier,
override val coordinates: IdeaKotlinFragmentCoordinates,
override val platforms: Set<IdeaKotlinPlatform>,
override val languageSettings: IdeaKotlinLanguageSettings?,
override val dependencies: List<IdeaKotlinDependency>,
@@ -36,3 +36,4 @@ data class IdeaKotlinFragmentImpl(
private const val serialVersionUID = 0L
}
}
@@ -0,0 +1,30 @@
/*
* 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 java.io.Serializable
sealed interface IdeaKotlinFragmentCoordinates : Serializable, IdeaKotlinDependencyCoordinates {
val module: IdeaKotlinModuleCoordinates
val fragmentName: String
}
@InternalKotlinGradlePluginApi
data class IdeaKotlinFragmentCoordinatesImpl(
override val module: IdeaKotlinModuleCoordinates,
override val fragmentName: String
) : IdeaKotlinFragmentCoordinates {
override fun toString(): String = path
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
val IdeaKotlinFragmentCoordinates.path: String
get() = "${module.path}/$fragmentName"
@@ -8,15 +8,17 @@ package org.jetbrains.kotlin.gradle.kpm.idea
import java.io.Serializable
interface IdeaKotlinModule : Serializable {
val name: String
val moduleIdentifier: IdeaKotlinModuleIdentifier
val coordinates: IdeaKotlinModuleCoordinates
val fragments: List<IdeaKotlinFragment>
}
val IdeaKotlinModule.name get() = coordinates.moduleName
val IdeaKotlinModule.moduleClassifier get() = coordinates.moduleClassifier
@InternalKotlinGradlePluginApi
data class IdeaKotlinModuleImpl(
override val name: String,
override val moduleIdentifier: IdeaKotlinModuleIdentifier,
override val coordinates: IdeaKotlinModuleCoordinates,
override val fragments: List<IdeaKotlinFragment>
) : IdeaKotlinModule {
@@ -0,0 +1,34 @@
/*
* 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 java.io.Serializable
interface IdeaKotlinModuleCoordinates : Serializable {
val buildId: String
val projectPath: String
val projectName: String
val moduleName: String
val moduleClassifier: String?
}
val IdeaKotlinModuleCoordinates.path: String
get() = "${buildId.takeIf { it != ":" }.orEmpty()}$projectPath/$moduleName"
@InternalKotlinGradlePluginApi
data class IdeaKotlinModuleCoordinatesImpl(
override val buildId: String,
override val projectPath: String,
override val projectName: String,
override val moduleName: String,
override val moduleClassifier: String?
) : IdeaKotlinModuleCoordinates {
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
@@ -1,48 +0,0 @@
/*
* 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 java.io.Serializable
interface IdeaKotlinModuleIdentifier : Serializable {
val moduleClassifier: String?
}
interface IdeaKotlinLocalModuleIdentifier : IdeaKotlinModuleIdentifier {
val buildId: String
val projectId: String
}
interface IdeaKotlinMavenModuleIdentifier : IdeaKotlinModuleIdentifier {
val group: String
val name: String
}
@InternalKotlinGradlePluginApi
data class IdeaKotlinLocalModuleIdentifierImpl(
override val moduleClassifier: String?,
override val buildId: String,
override val projectId: String
) : IdeaKotlinLocalModuleIdentifier {
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
@InternalKotlinGradlePluginApi
data class IdeaKotlinMavenModuleIdentifierImpl(
override val moduleClassifier: String?,
override val group: String,
override val name: String
) : IdeaKotlinMavenModuleIdentifier {
@InternalKotlinGradlePluginApi
companion object {
private const val serialVersionUID = 0L
}
}
@@ -63,10 +63,10 @@ class BackwardsCompatibilityDeserializationTest {
run {
val deserializedModelProxy = createProxyInstance<IdeaKotlinProjectModel>(deserializedModel)
val deserializedMainModuleProxy = deserializedModelProxy.modules.firstOrNull { it.moduleIdentifier.moduleClassifier == null }
val deserializedMainModuleProxy = deserializedModelProxy.modules.firstOrNull { it.coordinates.moduleClassifier == null }
?: fail("Missing main module")
val deserializedTestModuleProxy = deserializedModelProxy.modules.firstOrNull { it.moduleIdentifier.moduleClassifier == "test" }
val deserializedTestModuleProxy = deserializedModelProxy.modules.firstOrNull { it.coordinates.moduleClassifier == "test" }
?: fail("Missing test module")
listOf(deserializedMainModuleProxy, deserializedTestModuleProxy).forEach { module ->
@@ -100,7 +100,7 @@ class BackwardsCompatibilityDeserializationTest {
val deserializedModel = deserializeModelWithBackwardsCompatibleClasses(model)
val deserializedModelProxy = createProxyInstance<IdeaKotlinProjectModel>(deserializedModel)
val deserializedMainModuleProxy = deserializedModelProxy.modules.find { it.moduleIdentifier.moduleClassifier == null }
val deserializedMainModuleProxy = deserializedModelProxy.modules.find { it.coordinates.moduleClassifier == null }
?: fail("Missing main module")
val deserializedCommonFragmentProxy = deserializedMainModuleProxy.fragments.find { it.name == "common" }
@@ -0,0 +1,31 @@
package org.jetbrains.kotlin.gradle.kpm.idea.testFixtures
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKotlinFragmentDependency
fun buildIdeaKotlinFragmentDependencyMatchers(notation: Any?): List<IdeaKotlinFragmentDependencyMatcher> {
return when (notation) {
null -> emptyList()
is Iterable<*> -> notation.flatMap { buildIdeaKotlinFragmentDependencyMatchers(it) }
is String -> listOf(IdeaKotlinFragmentDependencyMatcher.DependencyLiteral(notation))
is Regex -> listOf(IdeaKotlinFragmentDependencyMatcher.DependencyRegex(notation))
else -> error("Can't build ${IdeaKotlinFragmentDependencyMatcher::class.simpleName} from $notation")
}
}
interface IdeaKotlinFragmentDependencyMatcher : IdeaKotlinDependencyMatcher<IdeaKotlinFragmentDependency> {
class DependencyLiteral(private val dependencyLiteral: String) : IdeaKotlinFragmentDependencyMatcher {
override val description: String = dependencyLiteral
override fun matches(dependency: IdeaKotlinFragmentDependency): Boolean {
return this.dependencyLiteral == dependency.toString()
}
}
class DependencyRegex(private val dependencyRegex: Regex) : IdeaKotlinFragmentDependencyMatcher {
override val description: String = dependencyRegex.pattern
override fun matches(dependency: IdeaKotlinFragmentDependency): Boolean {
return dependencyRegex.matches(dependency.coordinates.toString())
}
}
}
@@ -1,31 +0,0 @@
package org.jetbrains.kotlin.gradle.kpm.idea.testFixtures
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKotlinSourceDependency
fun buildIdeaKotlinSourceDependencyMatchers(notation: Any?): List<IdeaKotlinSourceDependencyMatcher> {
return when (notation) {
null -> emptyList()
is Iterable<*> -> notation.flatMap { buildIdeaKotlinSourceDependencyMatchers(it) }
is String -> listOf(IdeaKotlinSourceDependencyMatcher.FragmentPath(notation))
is Regex -> listOf(IdeaKotlinSourceDependencyMatcher.FragmentPathRegex(notation))
else -> error("Can't build ${IdeaKotlinSourceDependencyMatcher::class.simpleName} from $notation")
}
}
interface IdeaKotlinSourceDependencyMatcher : IdeaKotlinDependencyMatcher<IdeaKotlinSourceDependency> {
class FragmentPath(private val dependency: String) : IdeaKotlinSourceDependencyMatcher {
override val description: String = dependency
override fun matches(dependency: IdeaKotlinSourceDependency): Boolean {
return this.dependency == dependency.toString()
}
}
class FragmentPathRegex(private val dependencyRegex: Regex) : IdeaKotlinSourceDependencyMatcher {
override val description: String = dependencyRegex.pattern
override fun matches(dependency: IdeaKotlinSourceDependency): Boolean {
return dependencyRegex.matches(dependency.toString())
}
}
}
@@ -33,7 +33,7 @@ fun IdeaKotlinFragment.assertResolvedBinaryDependencies(
when (dependency) {
is IdeaKotlinResolvedBinaryDependencyImpl -> dependency
is IdeaKotlinUnresolvedBinaryDependencyImpl -> fail("Unexpected unresolved dependency: $dependency")
is IdeaKotlinSourceDependencyImpl -> null
is IdeaKotlinFragmentDependencyImpl -> null
}
}
.filter { it.binaryType == binaryType }
@@ -91,8 +91,8 @@ fun IdeaKotlinFragment.assertResolvedBinaryDependencies(
binaryType: String, vararg matchers: Any?
) = assertResolvedBinaryDependencies(binaryType, matchers.toSet())
fun IdeaKotlinFragment.assertSourceDependencies(matchers: Set<IdeaKotlinSourceDependencyMatcher>): Set<IdeaKotlinSourceDependency> {
val sourceDependencies = dependencies.filterIsInstance<IdeaKotlinSourceDependency>().toSet()
fun IdeaKotlinFragment.assertFragmentDependencies(matchers: Set<IdeaKotlinFragmentDependencyMatcher>): Set<IdeaKotlinFragmentDependency> {
val sourceDependencies = dependencies.filterIsInstance<IdeaKotlinFragmentDependency>().toSet()
val unexpectedDependencies = sourceDependencies
.filter { dependency -> matchers.none { matcher -> matcher.matches(dependency) } }
@@ -105,13 +105,11 @@ fun IdeaKotlinFragment.assertSourceDependencies(matchers: Set<IdeaKotlinSourceDe
return sourceDependencies
}
val fragmentIdentifier = "${moduleIdentifier.moduleClassifier?.plus("/").orEmpty()}${name}"
fail(
buildString {
if (unexpectedDependencies.isNotEmpty()) {
appendLine()
appendLine("${fragmentIdentifier}: Unexpected source dependency found:")
appendLine("${coordinates.path}: Unexpected source dependency found:")
unexpectedDependencies.forEach { unexpectedDependency ->
appendLine("\"${unexpectedDependency}\",")
}
@@ -119,14 +117,14 @@ fun IdeaKotlinFragment.assertSourceDependencies(matchers: Set<IdeaKotlinSourceDe
if (missingDependencies.isNotEmpty()) {
appendLine()
appendLine("${fragmentIdentifier}: Missing fragment dependencies:")
appendLine("${coordinates.path}: Missing fragment dependencies:")
missingDependencies.forEach { missingDependency ->
appendLine(missingDependency.description)
}
}
appendLine()
appendLine("${fragmentIdentifier}: Resolved source dependency paths:")
appendLine("${coordinates.path}: Resolved source dependency paths:")
sourceDependencies.forEach { dependency ->
appendLine("\"${dependency}\",")
}
@@ -135,8 +133,8 @@ fun IdeaKotlinFragment.assertSourceDependencies(matchers: Set<IdeaKotlinSourceDe
}
@JvmName("assertSourceDependenciesByAnyMatcher")
fun IdeaKotlinFragment.assertSourceDependencies(matchers: Set<Any?>): Set<IdeaKotlinSourceDependency> =
assertSourceDependencies(matchers.flatMap { buildIdeaKotlinSourceDependencyMatchers(it) }.toSet())
fun IdeaKotlinFragment.assertFragmentDependencies(matchers: Set<Any?>): Set<IdeaKotlinFragmentDependency> =
assertFragmentDependencies(matchers.flatMap { buildIdeaKotlinFragmentDependencyMatchers(it) }.toSet())
fun IdeaKotlinFragment.assertSourceDependencies(vararg matchers: Any?) =
assertSourceDependencies(matchers.toSet())
fun IdeaKotlinFragment.assertFragmentDependencies(vararg matchers: Any?) =
assertFragmentDependencies(matchers.toSet())
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.gradle.kpm.applyKpmPlugin
import org.jetbrains.kotlin.gradle.kpm.buildIdeaKotlinProjectModel
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.assertContainsFragment
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.assertIsNotEmpty
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.assertSourceDependencies
import org.jetbrains.kotlin.gradle.kpm.idea.testFixtures.assertFragmentDependencies
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.*
import org.junit.Test
@@ -85,12 +85,12 @@ class SimpleProjectToProjectDependencyResolutionTest : AbstractLightweightIdeaDe
fun ifMainModule(vararg any: Any?) =
listOf(*any).takeIf { module.name == KotlinGradleModule.MAIN_MODULE_NAME }
module.assertContainsFragment("common").assertSourceDependencies(
module.assertContainsFragment("common").assertFragmentDependencies(
"regular::producer/main/common",
ifTestModule("friend::consumer/main/common")
)
module.assertContainsFragment("jvm").assertSourceDependencies(
module.assertContainsFragment("jvm").assertFragmentDependencies(
"regular::producer/main/jvm",
"regular::producer/main/common",
ifMainModule(
@@ -103,7 +103,7 @@ class SimpleProjectToProjectDependencyResolutionTest : AbstractLightweightIdeaDe
)
)
module.assertContainsFragment("nativeCommon").assertSourceDependencies(
module.assertContainsFragment("nativeCommon").assertFragmentDependencies(
"regular::producer/main/common",
"regular::producer/main/nativeCommon",
ifMainModule(
@@ -116,7 +116,7 @@ class SimpleProjectToProjectDependencyResolutionTest : AbstractLightweightIdeaDe
)
)
module.assertContainsFragment("appleCommon").assertSourceDependencies(
module.assertContainsFragment("appleCommon").assertFragmentDependencies(
"regular::producer/main/common",
"regular::producer/main/appleCommon",
"regular::producer/main/nativeCommon",
@@ -133,7 +133,7 @@ class SimpleProjectToProjectDependencyResolutionTest : AbstractLightweightIdeaDe
)
)
module.assertContainsFragment("linuxX64").assertSourceDependencies(
module.assertContainsFragment("linuxX64").assertFragmentDependencies(
"regular::producer/main/common",
"regular::producer/main/nativeCommon",
"regular::producer/main/linuxX64",
@@ -150,7 +150,7 @@ class SimpleProjectToProjectDependencyResolutionTest : AbstractLightweightIdeaDe
)
)
module.assertContainsFragment("macosX64").assertSourceDependencies(
module.assertContainsFragment("macosX64").assertFragmentDependencies(
"regular::producer/main/macosX64",
"regular::producer/main/common",
"regular::producer/main/appleCommon",
@@ -171,7 +171,7 @@ class SimpleProjectToProjectDependencyResolutionTest : AbstractLightweightIdeaDe
)
)
module.assertContainsFragment("iosX64").assertSourceDependencies(
module.assertContainsFragment("iosX64").assertFragmentDependencies(
"regular::producer/main/iosX64",
"regular::producer/main/common",
"regular::producer/main/iosMain",
@@ -8,15 +8,14 @@ package org.jetbrains.kotlin.gradle.kpm.idea
import org.jetbrains.kotlin.gradle.kpm.KotlinExternalModelContainer
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.*
internal fun IdeaKotlinProjectModelBuildingContext.toIdeaKotlinFragment(fragment: KotlinGradleFragment): IdeaKotlinFragment {
internal fun IdeaKotlinProjectModelBuildingContext.IdeaKotlinFragment(fragment: KotlinGradleFragment): IdeaKotlinFragment {
return if (fragment is KotlinGradleVariant) buildIdeaKotlinVariant(fragment)
else buildIdeaKotlinFragment(fragment)
}
private fun IdeaKotlinProjectModelBuildingContext.buildIdeaKotlinFragment(fragment: KotlinGradleFragment): IdeaKotlinFragment {
return IdeaKotlinFragmentImpl(
name = fragment.name,
moduleIdentifier = fragment.containingModule.moduleIdentifier.toIdeaKotlinModuleIdentifier(),
coordinates = IdeaKotlinFragmentCoordinates(fragment),
platforms = fragment.containingVariants.map { variant -> buildIdeaKotlinPlatform(variant) }.toSet(),
languageSettings = fragment.languageSettings.toIdeaKotlinLanguageSettings(),
dependencies = dependencyResolver.resolve(fragment).toList(),
@@ -0,0 +1,15 @@
/*
* 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
internal fun IdeaKotlinFragmentCoordinates(fragment: KotlinGradleFragment): IdeaKotlinFragmentCoordinates {
return IdeaKotlinFragmentCoordinatesImpl(
module = IdeaKotlinModuleCoordinates(fragment.containingModule),
fragmentName = fragment.name
)
}
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinGradleModule.Companion.
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.currentBuildId
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.toModuleDependency
internal class IdeaKotlinSourceDependencyResolver(
internal class IdeaKotlinGranularFragmentDependencyResolver(
private val fragmentGranularMetadataResolverFactory: FragmentGranularMetadataResolverFactory
) : IdeaKotlinDependencyResolver {
override fun resolve(fragment: KotlinGradleFragment): Set<IdeaKotlinDependency> {
@@ -27,19 +27,21 @@ internal class IdeaKotlinSourceDependencyResolver(
val gradleProjectIdentifier = resolution.dependency.id as? ProjectComponentIdentifier ?: return emptyList()
val kotlinModuleIdentifier = resolution.dependency.toModuleDependency().moduleIdentifier
return resolution.allVisibleSourceSetNames.map { visibleFragmentName ->
IdeaKotlinSourceDependencyImpl(
IdeaKotlinFragmentDependencyImpl(
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,
projectPath = gradleProjectIdentifier.projectPath,
projectName = gradleProjectIdentifier.projectName,
kotlinModuleName = kotlinModuleIdentifier.moduleName,
kotlinModuleClassifier = kotlinModuleIdentifier.moduleClassifier,
kotlinFragmentName = visibleFragmentName
) IdeaKotlinFragmentDependency.Type.Friend
else IdeaKotlinFragmentDependency.Type.Regular,
coordinates = IdeaKotlinFragmentCoordinatesImpl(
module = IdeaKotlinModuleCoordinatesImpl(
buildId = gradleProjectIdentifier.build.name,
projectPath = gradleProjectIdentifier.projectPath,
projectName = gradleProjectIdentifier.projectName,
moduleName = kotlinModuleIdentifier.moduleName,
moduleClassifier = kotlinModuleIdentifier.moduleClassifier,
),
fragmentName = visibleFragmentName
)
)
}
@@ -7,10 +7,9 @@ package org.jetbrains.kotlin.gradle.kpm.idea
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.KotlinGradleModule
internal fun IdeaKotlinProjectModelBuildingContext.toIdeaKotlinModule(module: KotlinGradleModule): IdeaKotlinModule {
internal fun IdeaKotlinProjectModelBuildingContext.IdeaKotlinModule(module: KotlinGradleModule): IdeaKotlinModule {
return IdeaKotlinModuleImpl(
name = module.name,
moduleIdentifier = module.moduleIdentifier.toIdeaKotlinModuleIdentifier(),
fragments = module.fragments.toList().map { fragment -> toIdeaKotlinFragment(fragment) }
coordinates = IdeaKotlinModuleCoordinates(module),
fragments = module.fragments.toList().map { fragment -> IdeaKotlinFragment(fragment) }
)
}
@@ -0,0 +1,19 @@
/*
* 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.KotlinGradleModule
import org.jetbrains.kotlin.gradle.plugin.mpp.pm20.currentBuildId
internal fun IdeaKotlinModuleCoordinates(module: KotlinGradleModule): IdeaKotlinModuleCoordinates {
return IdeaKotlinModuleCoordinatesImpl(
buildId = module.project.currentBuildId().name,
projectPath = module.project.path,
projectName = module.project.name,
moduleName = module.name,
moduleClassifier = module.moduleClassifier
)
}
@@ -1,21 +0,0 @@
/*
* 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.project.model.KotlinModuleIdentifier
import org.jetbrains.kotlin.project.model.LocalModuleIdentifier
import org.jetbrains.kotlin.project.model.MavenModuleIdentifier
internal fun KotlinModuleIdentifier.toIdeaKotlinModuleIdentifier(): IdeaKotlinModuleIdentifier {
return when (this) {
is LocalModuleIdentifier -> IdeaKotlinLocalModuleIdentifierImpl(
moduleClassifier, buildId = buildId, projectId = projectId
)
is MavenModuleIdentifier -> IdeaKotlinMavenModuleIdentifierImpl(
moduleClassifier, group = group, name = name
)
}
}
@@ -135,7 +135,7 @@ internal fun IdeaKotlinProjectModelBuildingContext.toIdeaKotlinProjectModel(exte
coreLibrariesVersion = extension.coreLibrariesVersion,
explicitApiModeCliOption = extension.explicitApi?.cliOption,
kotlinNativeHome = File(extension.project.konanHome).absoluteFile,
modules = extension.modules.map { module -> toIdeaKotlinModule(module) }
modules = extension.modules.map { module -> IdeaKotlinModule(module) }
)
}
@@ -26,7 +26,7 @@ internal fun IdeaKotlinProjectModelBuilder.Companion.default(
)
registerDependencyResolver(
resolver = IdeaKotlinSourceDependencyResolver(fragmentMetadataResolverFactory),
resolver = IdeaKotlinGranularFragmentDependencyResolver(fragmentMetadataResolverFactory),
constraint = IdeaKotlinProjectModelBuilder.FragmentConstraint.unconstrained,
phase = IdeaKotlinProjectModelBuilder.DependencyResolutionPhase.SourceDependencyResolution,
level = IdeaKotlinProjectModelBuilder.DependencyResolutionLevel.Default
@@ -6,7 +6,6 @@
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 {
@@ -14,16 +13,9 @@ internal object IdeaKotlinRefinesDependencyResolver : IdeaKotlinDependencyResolv
.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
)
return IdeaKotlinFragmentDependencyImpl(
type = IdeaKotlinFragmentDependency.Type.Refines,
coordinates = IdeaKotlinFragmentCoordinates(fragment)
)
}
}