[KPM] Integrate refines dependencies into IdeaKotlinSourceDependency

KT-51386
This commit is contained in:
sebastian.sellmair
2022-03-15 14:28:47 +01:00
committed by Space
parent 0f8f61c373
commit e1ead6b8bf
12 changed files with 168 additions and 82 deletions
@@ -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 java.io.File
import java.io.Serializable
import java.util.*
sealed interface IdeaKotlinDependency : Serializable {
val coordinates: IdeaKotlinDependencyCoordinates?
@@ -37,6 +38,16 @@ sealed interface IdeaKotlinSourceCoordinates : IdeaKotlinDependencyCoordinates {
}
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
}
@@ -67,12 +78,14 @@ val IdeaKotlinResolvedBinaryDependency.isClasspathType get() = binaryType == CLA
@InternalKotlinGradlePluginApi
data class IdeaKotlinSourceDependencyImpl(
override val type: IdeaKotlinSourceDependency.Type,
override val coordinates: IdeaKotlinSourceCoordinates,
override val external: KotlinExternalModelContainer = KotlinExternalModelContainer.Empty
override val external: KotlinExternalModelContainer = KotlinExternalModelContainer.Empty,
) : IdeaKotlinSourceDependency {
override fun toString(): String {
return "source: $coordinates"
@Suppress("DEPRECATION")
return "${type.name.toLowerCase(Locale.ROOT)}:$coordinates"
}
@InternalKotlinGradlePluginApi
@@ -14,7 +14,6 @@ interface IdeaKotlinFragment : Serializable {
val platforms: Set<IdeaKotlinPlatform>
val languageSettings: IdeaKotlinLanguageSettings?
val dependencies: List<IdeaKotlinDependency>
val directRefinesDependencies: List<IdeaKotlinFragment>
val sourceDirectories: List<IdeaKotlinSourceDirectory>
val resourceDirectories: List<IdeaKotlinResourceDirectory>
val external: KotlinExternalModelContainer
@@ -27,7 +26,6 @@ data class IdeaKotlinFragmentImpl(
override val platforms: Set<IdeaKotlinPlatform>,
override val languageSettings: IdeaKotlinLanguageSettings?,
override val dependencies: List<IdeaKotlinDependency>,
override val directRefinesDependencies: List<IdeaKotlinFragment>,
override val sourceDirectories: List<IdeaKotlinSourceDirectory>,
override val resourceDirectories: List<IdeaKotlinResourceDirectory>,
override val external: KotlinExternalModelContainer
@@ -1,7 +1,6 @@
package org.jetbrains.kotlin.gradle.kpm.idea.testFixtures
import org.jetbrains.kotlin.gradle.kpm.idea.IdeaKotlinSourceDependency
import org.jetbrains.kotlin.gradle.kpm.idea.path
fun buildIdeaKotlinSourceDependencyMatchers(notation: Any?): List<IdeaKotlinSourceDependencyMatcher> {
return when (notation) {
@@ -14,19 +13,19 @@ fun buildIdeaKotlinSourceDependencyMatchers(notation: Any?): List<IdeaKotlinSour
}
interface IdeaKotlinSourceDependencyMatcher : IdeaKotlinDependencyMatcher<IdeaKotlinSourceDependency> {
class FragmentPath(private val path: String) : IdeaKotlinSourceDependencyMatcher {
override val description: String = path
class FragmentPath(private val dependency: String) : IdeaKotlinSourceDependencyMatcher {
override val description: String = dependency
override fun matches(dependency: IdeaKotlinSourceDependency): Boolean {
return path == dependency.coordinates.path
return this.dependency == dependency.toString()
}
}
class FragmentPathRegex(private val pathRegex: Regex) : IdeaKotlinSourceDependencyMatcher {
override val description: String = pathRegex.pattern
class FragmentPathRegex(private val dependencyRegex: Regex) : IdeaKotlinSourceDependencyMatcher {
override val description: String = dependencyRegex.pattern
override fun matches(dependency: IdeaKotlinSourceDependency): Boolean {
return pathRegex.matches(dependency.coordinates.path)
return dependencyRegex.matches(dependency.toString())
}
}
}
@@ -105,33 +105,30 @@ fun IdeaKotlinFragment.assertSourceDependencies(matchers: Set<IdeaKotlinSourceDe
return sourceDependencies
}
val fragmentIdentifier = "${moduleIdentifier.moduleClassifier?.plus("/").orEmpty()}${name}"
fail(
buildString {
if (unexpectedDependencies.isNotEmpty()) {
appendLine("${name}: Unexpected source dependencies found:")
unexpectedDependencies.forEach { unexpectedDependency ->
appendLine(unexpectedDependency)
}
appendLine()
appendLine("${name}: Unexpected source dependency paths:")
appendLine("${fragmentIdentifier}: Unexpected source dependency found:")
unexpectedDependencies.forEach { unexpectedDependency ->
appendLine("\"${unexpectedDependency.coordinates.path}\",")
appendLine("\"${unexpectedDependency}\",")
}
}
if (missingDependencies.isNotEmpty()) {
appendLine()
appendLine("${name}: Missing fragment dependencies:")
appendLine("${fragmentIdentifier}: Missing fragment dependencies:")
missingDependencies.forEach { missingDependency ->
appendLine(missingDependency.description)
}
}
appendLine()
appendLine("${name}: Resolved source dependency paths:")
appendLine("${fragmentIdentifier}: Resolved source dependency paths:")
sourceDependencies.forEach { dependency ->
appendLine("\"${dependency.coordinates.path}\",")
appendLine("\"${dependency}\",")
}
}
)