[Gradle] Sources resolver test for multiple capabilities
If dependency has more than one capability sources still can be resolved. ^KT-63226 In Progress
This commit is contained in:
committed by
Space Team
parent
f266a44356
commit
7c9505d9b6
+33
-4
@@ -6,12 +6,11 @@
|
||||
package org.jetbrains.kotlin.gradle.idea.testFixtures.tcs
|
||||
|
||||
import org.gradle.api.Project
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinBinaryCoordinates
|
||||
import org.gradle.api.artifacts.component.BuildIdentifier
|
||||
import org.gradle.api.internal.project.ProjectInternal
|
||||
import org.gradle.internal.build.BuildState
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinSourceDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.*
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.extras.sourcesClasspath
|
||||
|
||||
fun buildIdeaKotlinDependencyMatchers(notation: Any?): List<IdeaKotlinDependencyMatcher> {
|
||||
return when (notation) {
|
||||
@@ -77,4 +76,34 @@ fun anyDependency(): IdeaKotlinDependencyMatcher = object : IdeaKotlinDependency
|
||||
|
||||
/* Duplicated: Aks Gradle for public API? */
|
||||
private fun Project.currentBuildId(): BuildIdentifier =
|
||||
(project as ProjectInternal).services.get(BuildState::class.java).buildIdentifier
|
||||
(project as ProjectInternal).services.get(BuildState::class.java).buildIdentifier
|
||||
|
||||
|
||||
class IdeaKotlinDependencyMatcherWithSourcesFile(
|
||||
private val upstreamMatcher: IdeaKotlinDependencyMatcher,
|
||||
private val filePattern: Regex,
|
||||
) : IdeaKotlinDependencyMatcher {
|
||||
override val description: String
|
||||
get() = upstreamMatcher.description + " with resolved sources file '$filePattern'"
|
||||
|
||||
override fun matches(dependency: IdeaKotlinDependency): Boolean {
|
||||
if (!upstreamMatcher.matches(dependency)) return false
|
||||
|
||||
// only binary dependencies can have resolved sources file attached
|
||||
if (dependency !is IdeaKotlinBinaryDependency) return false
|
||||
|
||||
// at the moment we expect only 1 source file be associated with dependency
|
||||
val sourcesFile = dependency.sourcesClasspath.singleOrNull() ?: return false
|
||||
|
||||
// require that *ALL* files in sourcesClasspath matches the file pattern
|
||||
return sourcesFile.toString().matches(filePattern)
|
||||
}
|
||||
|
||||
override fun toString(): String = "$upstreamMatcher with resolved sources file '$filePattern'"
|
||||
}
|
||||
|
||||
fun IdeaKotlinDependencyMatcher.withResolvedSourcesFile(endsWith: String) =
|
||||
IdeaKotlinDependencyMatcherWithSourcesFile(
|
||||
upstreamMatcher = this,
|
||||
filePattern = Regex(".*$endsWith")
|
||||
)
|
||||
+28
-4
@@ -8,10 +8,7 @@ package org.jetbrains.kotlin.gradle
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.commonizer.CommonizerTarget
|
||||
import org.jetbrains.kotlin.commonizer.identityString
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinBinaryDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinResolvedBinaryDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinUnresolvedBinaryDependency
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.*
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.extras.*
|
||||
import org.jetbrains.kotlin.gradle.idea.testFixtures.tcs.*
|
||||
import org.jetbrains.kotlin.gradle.testbase.*
|
||||
@@ -395,6 +392,33 @@ class MppIdeDependencyResolutionIT : KGPBaseTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@GradleTest
|
||||
fun `test resolve sources for dependency with multiple capabilities`(gradleVersion: GradleVersion) {
|
||||
project("kt-63226-multiple-capabilities", gradleVersion) {
|
||||
build(":producer:publish")
|
||||
|
||||
resolveIdeDependencies(":consumer") { dependencies ->
|
||||
dependencies["jvmMain"].getOrFail(
|
||||
binaryCoordinates("test:producer:1.0")
|
||||
.withResolvedSourcesFile("producer-1.0-sources.jar")
|
||||
)
|
||||
|
||||
// according to build.gradle.kts of test project jvmTest should have both artifacts from :producer
|
||||
// one with regular capabilities
|
||||
dependencies["jvmTest"].getOrFail(
|
||||
binaryCoordinates("test:producer:1.0")
|
||||
.withResolvedSourcesFile("producer-1.0-sources.jar")
|
||||
)
|
||||
|
||||
// and another with foo capability
|
||||
dependencies["jvmTest"].getOrFail(
|
||||
binaryCoordinates("test:producer:1.0")
|
||||
.withResolvedSourcesFile("producer-1.0-foo-sources.jar")
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Iterable<IdeaKotlinDependency>.cinteropDependencies() =
|
||||
this.filterIsInstance<IdeaKotlinBinaryDependency>().filter {
|
||||
it.klibExtra?.isInterop == true && !it.isNativeStdlib && !it.isNativeDistribution
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven(rootDir.resolve("repo"))
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
|
||||
sourceSets.jvmMain.dependencies {
|
||||
implementation("test:producer:1.0")
|
||||
}
|
||||
|
||||
sourceSets.jvmTest.dependencies {
|
||||
implementation("test:producer:1.0") {
|
||||
capabilities {
|
||||
requireCapability("test:foo:1.0")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
}
|
||||
|
||||
group = "test"
|
||||
version = "1.0"
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create("maven", MavenPublication::class.java) {
|
||||
from(components["java"])
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven(rootDir.resolve("repo"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
java {
|
||||
withSourcesJar()
|
||||
registerFeature("foo") {
|
||||
withSourcesJar()
|
||||
usingSourceSet(sourceSets.create("foo"))
|
||||
capability("test", "foo", "1.0")
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
public class Foo {
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
public class Main {
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
|
||||
include(":producer")
|
||||
include(":consumer")
|
||||
Reference in New Issue
Block a user