[Gradle] IdeaKotlinProjectArtifactDependencyMatcher: Use host independent path matcher
^KT-55112 Verification Pending
This commit is contained in:
committed by
Space Team
parent
3f24b690e2
commit
55cfe52e7d
+33
-4
@@ -8,20 +8,49 @@ package org.jetbrains.kotlin.gradle.idea.testFixtures.tcs
|
|||||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinProjectArtifactDependency
|
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinProjectArtifactDependency
|
||||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinSourceDependency
|
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinSourceDependency
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
internal class IdeaKotlinProjectArtifactDependencyMatcher(
|
internal class IdeaKotlinProjectArtifactDependencyMatcher(
|
||||||
val type: IdeaKotlinSourceDependency.Type,
|
val type: IdeaKotlinSourceDependency.Type,
|
||||||
val projectPath: String,
|
val projectPath: String,
|
||||||
val artifactFilePath: Regex
|
val artifactFilePath: FilePathRegex
|
||||||
) : IdeaKotlinDependencyMatcher {
|
) : IdeaKotlinDependencyMatcher {
|
||||||
override val description: String
|
override val description: String
|
||||||
get() = "project($type)::$projectPath/${artifactFilePath.pattern}"
|
get() = "project($type)::$projectPath/${artifactFilePath}"
|
||||||
|
|
||||||
override fun matches(dependency: IdeaKotlinDependency): Boolean {
|
override fun matches(dependency: IdeaKotlinDependency): Boolean {
|
||||||
if (dependency !is IdeaKotlinProjectArtifactDependency) return false
|
if (dependency !is IdeaKotlinProjectArtifactDependency) return false
|
||||||
return dependency.type == type &&
|
return dependency.type == type &&
|
||||||
dependency.coordinates.project.projectPath == projectPath &&
|
dependency.coordinates.project.projectPath == projectPath &&
|
||||||
dependency.coordinates.artifactFile.path.matches(artifactFilePath)
|
artifactFilePath.matches(dependency.coordinates.artifactFile)
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fun FilePathRegex(pattern: String): FilePathRegex = FilePathRegex.from(pattern)
|
||||||
|
|
||||||
|
class FilePathRegex private constructor(private val normalizedRegex: Regex) {
|
||||||
|
override fun toString(): String {
|
||||||
|
return normalizedRegex.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
if (other !is FilePathRegex) return false
|
||||||
|
return normalizedRegex == other.normalizedRegex
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return normalizedRegex.hashCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun matches(file: File) = normalizedRegex.matches(file.path)
|
||||||
|
|
||||||
|
fun matches(path: String) = normalizedRegex.matches(path)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun from(pattern: String): FilePathRegex {
|
||||||
|
return FilePathRegex(Regex(pattern.replace("/", Regex.escape(File.separator))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ fun dependsOnDependency(project: Project, sourceSetName: String) =
|
|||||||
fun dependsOnDependency(path: String) = ideSourceDependency(IdeaKotlinSourceDependency.Type.DependsOn, path)
|
fun dependsOnDependency(path: String) = ideSourceDependency(IdeaKotlinSourceDependency.Type.DependsOn, path)
|
||||||
|
|
||||||
fun projectArtifactDependency(
|
fun projectArtifactDependency(
|
||||||
type: IdeaKotlinSourceDependency.Type = IdeaKotlinSourceDependency.Type.Regular, projectPath: String, artifactFilePath: Regex
|
type: IdeaKotlinSourceDependency.Type = IdeaKotlinSourceDependency.Type.Regular, projectPath: String, artifactFilePath: FilePathRegex
|
||||||
): IdeaKotlinDependencyMatcher = IdeaKotlinProjectArtifactDependencyMatcher(
|
): IdeaKotlinDependencyMatcher = IdeaKotlinProjectArtifactDependencyMatcher(
|
||||||
type = type,
|
type = type,
|
||||||
projectPath = projectPath,
|
projectPath = projectPath,
|
||||||
|
|||||||
+6
-6
@@ -101,7 +101,7 @@ class IdeResolveSourceDependenciesTest {
|
|||||||
dependsOnDependency(":consumer/commonMain"),
|
dependsOnDependency(":consumer/commonMain"),
|
||||||
dependsOnDependency(":consumer/nativeMain"),
|
dependsOnDependency(":consumer/nativeMain"),
|
||||||
dependsOnDependency(":consumer/linuxMain"),
|
dependsOnDependency(":consumer/linuxMain"),
|
||||||
projectArtifactDependency(Regular, ":producer", Regex(".*/linuxX64/main/klib/producer.klib"))
|
projectArtifactDependency(Regular, ":producer", FilePathRegex(".*/linuxX64/main/klib/producer.klib"))
|
||||||
)
|
)
|
||||||
|
|
||||||
consumer.resolveDependencies("linuxX64Test").assertMatches(
|
consumer.resolveDependencies("linuxX64Test").assertMatches(
|
||||||
@@ -115,7 +115,7 @@ class IdeResolveSourceDependenciesTest {
|
|||||||
dependsOnDependency(":consumer/commonTest"),
|
dependsOnDependency(":consumer/commonTest"),
|
||||||
dependsOnDependency(":consumer/nativeTest"),
|
dependsOnDependency(":consumer/nativeTest"),
|
||||||
dependsOnDependency(":consumer/linuxTest"),
|
dependsOnDependency(":consumer/linuxTest"),
|
||||||
projectArtifactDependency(Regular, ":producer", Regex(".*/linuxX64/main/klib/producer.klib"))
|
projectArtifactDependency(Regular, ":producer", FilePathRegex(".*/linuxX64/main/klib/producer.klib"))
|
||||||
)
|
)
|
||||||
|
|
||||||
consumer.resolveDependencies("linuxArm64Main").assertMatches(
|
consumer.resolveDependencies("linuxArm64Main").assertMatches(
|
||||||
@@ -125,7 +125,7 @@ class IdeResolveSourceDependenciesTest {
|
|||||||
dependsOnDependency(":consumer/commonMain"),
|
dependsOnDependency(":consumer/commonMain"),
|
||||||
dependsOnDependency(":consumer/nativeMain"),
|
dependsOnDependency(":consumer/nativeMain"),
|
||||||
dependsOnDependency(":consumer/linuxMain"),
|
dependsOnDependency(":consumer/linuxMain"),
|
||||||
projectArtifactDependency(Regular, ":producer", Regex(".*/linuxArm64/main/klib/producer.klib"))
|
projectArtifactDependency(Regular, ":producer", FilePathRegex(".*/linuxArm64/main/klib/producer.klib"))
|
||||||
)
|
)
|
||||||
|
|
||||||
consumer.resolveDependencies("linuxArm64Test").assertMatches(
|
consumer.resolveDependencies("linuxArm64Test").assertMatches(
|
||||||
@@ -139,7 +139,7 @@ class IdeResolveSourceDependenciesTest {
|
|||||||
dependsOnDependency(":consumer/commonTest"),
|
dependsOnDependency(":consumer/commonTest"),
|
||||||
dependsOnDependency(":consumer/nativeTest"),
|
dependsOnDependency(":consumer/nativeTest"),
|
||||||
dependsOnDependency(":consumer/linuxTest"),
|
dependsOnDependency(":consumer/linuxTest"),
|
||||||
projectArtifactDependency(Regular, ":producer", Regex(".*/linuxArm64/main/klib/producer.klib"))
|
projectArtifactDependency(Regular, ":producer", FilePathRegex(".*/linuxArm64/main/klib/producer.klib"))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,14 +213,14 @@ class IdeResolveSourceDependenciesTest {
|
|||||||
|
|
||||||
consumer.resolveDependencies("jvmMain").assertMatches(
|
consumer.resolveDependencies("jvmMain").assertMatches(
|
||||||
dependsOnDependency(":consumer/commonMain"),
|
dependsOnDependency(":consumer/commonMain"),
|
||||||
projectArtifactDependency(Regular, ":producer", Regex(""".*/build/libs/producer.jar"""))
|
projectArtifactDependency(Regular, ":producer", FilePathRegex(".*/build/libs/producer.jar"))
|
||||||
)
|
)
|
||||||
|
|
||||||
consumer.resolveDependencies("jvmTest").assertMatches(
|
consumer.resolveDependencies("jvmTest").assertMatches(
|
||||||
friendSourceDependency(":consumer/commonMain"),
|
friendSourceDependency(":consumer/commonMain"),
|
||||||
friendSourceDependency(":consumer/jvmMain"),
|
friendSourceDependency(":consumer/jvmMain"),
|
||||||
dependsOnDependency(":consumer/commonTest"),
|
dependsOnDependency(":consumer/commonTest"),
|
||||||
projectArtifactDependency(Regular, ":producer", Regex(""".*/build/libs/producer.jar"""))
|
projectArtifactDependency(Regular, ":producer", FilePathRegex(".*/build/libs/producer.jar"))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user