[KPM] Remove IdeaKotlinModuleIdentifier in favor of consistent IdeaKotlinFragmentCoordinates
KT-51386
This commit is contained in:
committed by
Space
parent
ef3a3d71b9
commit
1a0d8f777c
+34
@@ -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
|
||||
}
|
||||
}
|
||||
+6
-65
@@ -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?,
|
||||
|
||||
+10
@@ -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
|
||||
+5
-4
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+30
@@ -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"
|
||||
+6
-4
@@ -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 {
|
||||
|
||||
|
||||
+34
@@ -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
|
||||
}
|
||||
}
|
||||
-48
@@ -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
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -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" }
|
||||
|
||||
+31
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
-31
@@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-12
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user