[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")
|
||||
)
|
||||
Reference in New Issue
Block a user