[KPM] Introduce separate IdeaKotlinDependencyCoordinates entity

This splits IdeaKotlinSourceCoordinates from the actual
IdeaKotlinSourceDependency

KT-51386
This commit is contained in:
sebastian.sellmair
2022-03-15 10:46:54 +01:00
committed by Space
parent 588ea65d66
commit 0f8f61c373
5 changed files with 57 additions and 25 deletions
@@ -15,6 +15,7 @@ import java.io.File
import java.io.Serializable
sealed interface IdeaKotlinDependency : Serializable {
val coordinates: IdeaKotlinDependencyCoordinates?
val external: KotlinExternalModelContainer
companion object {
@@ -24,7 +25,9 @@ sealed interface IdeaKotlinDependency : Serializable {
}
}
sealed interface IdeaKotlinSourceDependency : IdeaKotlinDependency {
sealed interface IdeaKotlinDependencyCoordinates : Serializable
sealed interface IdeaKotlinSourceCoordinates : IdeaKotlinDependencyCoordinates {
val buildId: String
val projectPath: String
val projectName: String
@@ -33,10 +36,11 @@ sealed interface IdeaKotlinSourceDependency : IdeaKotlinDependency {
val kotlinFragmentName: String
}
val IdeaKotlinSourceDependency.path: String
get() = "${buildId.takeIf { it != ":" }.orEmpty()}$projectPath/$kotlinModuleName/$kotlinFragmentName"
sealed interface IdeaKotlinSourceDependency : IdeaKotlinDependency {
override val coordinates: IdeaKotlinSourceCoordinates
}
sealed interface IdeaKotlinBinaryCoordinates : Serializable {
sealed interface IdeaKotlinBinaryCoordinates : IdeaKotlinDependencyCoordinates {
val group: String
val module: String
val version: String
@@ -45,7 +49,7 @@ sealed interface IdeaKotlinBinaryCoordinates : Serializable {
}
sealed interface IdeaKotlinBinaryDependency : IdeaKotlinDependency {
val coordinates: IdeaKotlinBinaryCoordinates?
override val coordinates: IdeaKotlinBinaryCoordinates?
}
sealed interface IdeaKotlinUnresolvedBinaryDependency : IdeaKotlinBinaryDependency {
@@ -63,17 +67,12 @@ val IdeaKotlinResolvedBinaryDependency.isClasspathType get() = binaryType == CLA
@InternalKotlinGradlePluginApi
data class IdeaKotlinSourceDependencyImpl(
override val buildId: String,
override val projectPath: String,
override val projectName: String,
override val kotlinModuleName: String,
override val kotlinModuleClassifier: String?,
override val kotlinFragmentName: String,
override val coordinates: IdeaKotlinSourceCoordinates,
override val external: KotlinExternalModelContainer = KotlinExternalModelContainer.Empty
) : IdeaKotlinSourceDependency {
override fun toString(): String {
return "fragment: $path"
return "source: $coordinates"
}
@InternalKotlinGradlePluginApi
@@ -102,6 +101,26 @@ data class IdeaKotlinBinaryCoordinatesImpl(
}
}
@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?,
@@ -18,7 +18,7 @@ interface IdeaKotlinSourceDependencyMatcher : IdeaKotlinDependencyMatcher<IdeaKo
override val description: String = path
override fun matches(dependency: IdeaKotlinSourceDependency): Boolean {
return path == dependency.path
return path == dependency.coordinates.path
}
}
@@ -26,7 +26,7 @@ interface IdeaKotlinSourceDependencyMatcher : IdeaKotlinDependencyMatcher<IdeaKo
override val description: String = pathRegex.pattern
override fun matches(dependency: IdeaKotlinSourceDependency): Boolean {
return pathRegex.matches(dependency.path)
return pathRegex.matches(dependency.coordinates.path)
}
}
}
@@ -116,7 +116,7 @@ fun IdeaKotlinFragment.assertSourceDependencies(matchers: Set<IdeaKotlinSourceDe
appendLine()
appendLine("${name}: Unexpected source dependency paths:")
unexpectedDependencies.forEach { unexpectedDependency ->
appendLine("\"${unexpectedDependency.path}\",")
appendLine("\"${unexpectedDependency.coordinates.path}\",")
}
}
@@ -131,7 +131,7 @@ fun IdeaKotlinFragment.assertSourceDependencies(matchers: Set<IdeaKotlinSourceDe
appendLine()
appendLine("${name}: Resolved source dependency paths:")
sourceDependencies.forEach { dependency ->
appendLine("\"${dependency.path}\",")
appendLine("\"${dependency.coordinates.path}\",")
}
}
)