[Gradle] Implement IdeaKotlinProjectArtifactDependency
KT-55112
This commit is contained in:
committed by
Space Team
parent
e6daabdb2d
commit
cda82b47e0
+5
-4
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.gradle.idea.tcs
|
||||
|
||||
import org.jetbrains.kotlin.tooling.core.MutableExtras
|
||||
import org.jetbrains.kotlin.tooling.core.mutableExtrasOf
|
||||
import java.io.File
|
||||
|
||||
sealed class IdeaKotlinBinaryDependency : IdeaKotlinDependency {
|
||||
@@ -15,8 +16,8 @@ sealed class IdeaKotlinBinaryDependency : IdeaKotlinDependency {
|
||||
data class IdeaKotlinResolvedBinaryDependency(
|
||||
val binaryType: String,
|
||||
val binaryFile: File,
|
||||
override val extras: MutableExtras,
|
||||
override val coordinates: IdeaKotlinBinaryCoordinates?
|
||||
override val coordinates: IdeaKotlinBinaryCoordinates?,
|
||||
override val extras: MutableExtras = mutableExtrasOf()
|
||||
) : IdeaKotlinBinaryDependency() {
|
||||
internal companion object {
|
||||
const val serialVersionUID = 0L
|
||||
@@ -26,9 +27,9 @@ data class IdeaKotlinResolvedBinaryDependency(
|
||||
data class IdeaKotlinUnresolvedBinaryDependency(
|
||||
val cause: String?,
|
||||
override val coordinates: IdeaKotlinBinaryCoordinates?,
|
||||
override val extras: MutableExtras
|
||||
override val extras: MutableExtras = mutableExtrasOf()
|
||||
) : IdeaKotlinBinaryDependency() {
|
||||
internal companion object {
|
||||
const val serialVersionUID = 0L
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+18
-5
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.gradle.idea.tcs
|
||||
|
||||
import java.io.File
|
||||
import java.io.Serializable
|
||||
|
||||
sealed interface IdeaKotlinDependencyCoordinates : Serializable
|
||||
@@ -22,20 +23,32 @@ data class IdeaKotlinBinaryCoordinates(
|
||||
internal companion object {
|
||||
const val serialVersionUID = 0L
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
data class IdeaKotlinSourceCoordinates(
|
||||
val buildId: String,
|
||||
val projectPath: String,
|
||||
val projectName: String,
|
||||
val project: IdeaKotlinProjectCoordinates,
|
||||
val sourceSetName: String
|
||||
) : IdeaKotlinDependencyCoordinates {
|
||||
|
||||
val buildId: String get() = project.buildId
|
||||
val projectPath: String get() = project.projectPath
|
||||
val projectName: String get() = project.projectName
|
||||
|
||||
override fun toString(): String {
|
||||
return "${buildId.takeIf { it != ":" }.orEmpty()}$projectPath/$sourceSetName"
|
||||
return "$project/$sourceSetName"
|
||||
}
|
||||
|
||||
internal companion object {
|
||||
const val serialVersionUID = 0L
|
||||
}
|
||||
}
|
||||
|
||||
data class IdeaKotlinProjectArtifactCoordinates(
|
||||
val project: IdeaKotlinProjectCoordinates,
|
||||
val artifactFile: File
|
||||
) : IdeaKotlinDependencyCoordinates {
|
||||
|
||||
internal companion object {
|
||||
const val serialVersionUID = 0L
|
||||
}
|
||||
}
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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.idea.tcs
|
||||
|
||||
import org.jetbrains.kotlin.tooling.core.MutableExtras
|
||||
import org.jetbrains.kotlin.tooling.core.mutableExtrasOf
|
||||
|
||||
data class IdeaKotlinProjectArtifactDependency(
|
||||
val type: IdeaKotlinSourceDependency.Type,
|
||||
override val coordinates: IdeaKotlinProjectArtifactCoordinates,
|
||||
override val extras: MutableExtras = mutableExtrasOf()
|
||||
) : IdeaKotlinDependency {
|
||||
|
||||
internal companion object {
|
||||
const val serialVersionUID = 0L
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 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.idea.tcs
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
data class IdeaKotlinProjectCoordinates(
|
||||
val buildId: String,
|
||||
val projectPath: String,
|
||||
val projectName: String
|
||||
) : Serializable {
|
||||
override fun toString(): String {
|
||||
return "${buildId.takeIf { it != ":" }?.plus(":").orEmpty()}$projectPath"
|
||||
}
|
||||
|
||||
internal companion object {
|
||||
const val serialVersionUID = 0L
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.idea.testFixtures.tcs
|
||||
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinProjectArtifactDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinSourceDependency
|
||||
|
||||
internal class IdeaKotlinProjectArtifactDependencyMatcher(
|
||||
val type: IdeaKotlinSourceDependency.Type,
|
||||
val projectPath: String,
|
||||
val artifactFilePath: Regex
|
||||
) : IdeaKotlinDependencyMatcher {
|
||||
override val description: String
|
||||
get() = "project($type)::$projectPath/${artifactFilePath.pattern}"
|
||||
|
||||
override fun matches(dependency: IdeaKotlinDependency): Boolean {
|
||||
if (dependency !is IdeaKotlinProjectArtifactDependency) return false
|
||||
return dependency.type == type &&
|
||||
dependency.coordinates.project.projectPath == projectPath &&
|
||||
dependency.coordinates.artifactFile.path.matches(artifactFilePath)
|
||||
|
||||
}
|
||||
}
|
||||
+1
@@ -23,3 +23,4 @@ internal class IdeaKotlinSourceDependencyMatcher(
|
||||
dependency.coordinates.sourceSetName == sourceSetName
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
-3
@@ -19,6 +19,12 @@ object TestIdeaKotlinInstances {
|
||||
extrasKeyOf<String>() withValue "Cash"
|
||||
)
|
||||
|
||||
val simpleProjectCoordinates = IdeaKotlinProjectCoordinates(
|
||||
buildId = "myBuildId",
|
||||
projectPath = "my:project:path",
|
||||
projectName = "myProjectName"
|
||||
)
|
||||
|
||||
val simpleBinaryCoordinates = IdeaKotlinBinaryCoordinates(
|
||||
group = "myGroup",
|
||||
module = "myModule",
|
||||
@@ -27,12 +33,16 @@ object TestIdeaKotlinInstances {
|
||||
)
|
||||
|
||||
val simpleSourceCoordinates = IdeaKotlinSourceCoordinates(
|
||||
buildId = "myBuildId",
|
||||
projectPath = "my:project:path",
|
||||
projectName = "myProjectName",
|
||||
project = simpleProjectCoordinates,
|
||||
sourceSetName = "mySourceSetName"
|
||||
)
|
||||
|
||||
|
||||
val simpleProjectArtifactCoordinates = IdeaKotlinProjectArtifactCoordinates(
|
||||
project = simpleProjectCoordinates,
|
||||
artifactFile = File("myArtifactFile.klib")
|
||||
)
|
||||
|
||||
val simpleUnresolvedBinaryDependency = IdeaKotlinUnresolvedBinaryDependency(
|
||||
cause = "myCause",
|
||||
coordinates = simpleBinaryCoordinates,
|
||||
@@ -51,4 +61,10 @@ object TestIdeaKotlinInstances {
|
||||
type = IdeaKotlinSourceDependency.Type.Regular,
|
||||
extras = extrasWithIntAndStrings.toMutableExtras()
|
||||
)
|
||||
|
||||
val simpleProjectArtifactDependency = IdeaKotlinProjectArtifactDependency(
|
||||
coordinates = simpleProjectArtifactCoordinates,
|
||||
type = IdeaKotlinSourceDependency.Type.Regular,
|
||||
extras = extrasWithIntAndStrings.toMutableExtras()
|
||||
)
|
||||
}
|
||||
+9
-2
@@ -23,8 +23,8 @@ fun ideSourceDependency(type: IdeaKotlinSourceDependency.Type, project: Project,
|
||||
}
|
||||
|
||||
fun ideSourceDependency(type: IdeaKotlinSourceDependency.Type, path: String): IdeaKotlinDependencyMatcher {
|
||||
val segments = path.split(":")
|
||||
val projectPath = segments.dropLast(1).joinToString(":")
|
||||
val segments = path.split("/")
|
||||
val projectPath = segments.dropLast(1).joinToString("/")
|
||||
val sourceSetName = segments.last()
|
||||
return IdeaKotlinSourceDependencyMatcher(type, projectPath, sourceSetName)
|
||||
}
|
||||
@@ -38,6 +38,13 @@ fun dependsOnDependency(project: Project, sourceSetName: String) =
|
||||
|
||||
fun dependsOnDependency(path: String) = ideSourceDependency(IdeaKotlinSourceDependency.Type.DependsOn, path)
|
||||
|
||||
fun projectArtifactDependency(
|
||||
type: IdeaKotlinSourceDependency.Type = IdeaKotlinSourceDependency.Type.Regular, projectPath: String, artifactFilePath: Regex
|
||||
): IdeaKotlinDependencyMatcher = IdeaKotlinProjectArtifactDependencyMatcher(
|
||||
type = type,
|
||||
projectPath = projectPath,
|
||||
artifactFilePath = artifactFilePath
|
||||
)
|
||||
|
||||
fun binaryCoordinates(regex: Regex): IdeaKotlinDependencyMatcher {
|
||||
return IdeaBinaryCoordinatesMatcher(regex)
|
||||
|
||||
Reference in New Issue
Block a user