[Gradle] Implement IdeSourcesAndDocumentationResolutionTest
^KT-55289 Verification Pending
This commit is contained in:
committed by
Space Team
parent
7b2c4856c4
commit
7a89f4087a
+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.testFixtures.tcs
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinBinaryCoordinates
|
||||||
|
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinBinaryDependency
|
||||||
|
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||||
|
|
||||||
|
internal class IdeaBinaryCoordinatesInstanceMatcher(
|
||||||
|
private val coordinates: IdeaKotlinBinaryCoordinates
|
||||||
|
) : IdeaKotlinDependencyMatcher {
|
||||||
|
override val description: String
|
||||||
|
get() = "coordinates:$coordinates"
|
||||||
|
|
||||||
|
override fun matches(dependency: IdeaKotlinDependency): Boolean {
|
||||||
|
if (dependency !is IdeaKotlinBinaryDependency) return false
|
||||||
|
return coordinates == dependency.coordinates
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.gradle.idea.testFixtures.tcs
|
package org.jetbrains.kotlin.gradle.idea.testFixtures.tcs
|
||||||
|
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinBinaryCoordinates
|
||||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinSourceDependency
|
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinSourceDependency
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ fun buildIdeaKotlinDependencyMatchers(notation: Any?): List<IdeaKotlinDependency
|
|||||||
return when (notation) {
|
return when (notation) {
|
||||||
null -> return emptyList()
|
null -> return emptyList()
|
||||||
is IdeaKotlinDependency -> listOf(IdeaKotlinDependencyInstanceMatcher(notation))
|
is IdeaKotlinDependency -> listOf(IdeaKotlinDependencyInstanceMatcher(notation))
|
||||||
|
is IdeaKotlinBinaryCoordinates -> listOf(IdeaBinaryCoordinatesInstanceMatcher(notation))
|
||||||
is IdeaKotlinDependencyMatcher -> listOf(notation)
|
is IdeaKotlinDependencyMatcher -> listOf(notation)
|
||||||
is Iterable<*> -> notation.flatMap { buildIdeaKotlinDependencyMatchers(it) }
|
is Iterable<*> -> notation.flatMap { buildIdeaKotlinDependencyMatchers(it) }
|
||||||
else -> error("Can't build ${IdeaKotlinSourceDependencyMatcher::class.java.simpleName} from $notation")
|
else -> error("Can't build ${IdeaKotlinSourceDependencyMatcher::class.java.simpleName} from $notation")
|
||||||
|
|||||||
+10
-1
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers
|
package org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers
|
||||||
|
|
||||||
|
import org.gradle.api.artifacts.Configuration
|
||||||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
|
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
|
||||||
import org.gradle.api.artifacts.result.ArtifactResolutionResult
|
import org.gradle.api.artifacts.result.ArtifactResolutionResult
|
||||||
import org.gradle.api.artifacts.result.ResolvedArtifactResult
|
import org.gradle.api.artifacts.result.ResolvedArtifactResult
|
||||||
@@ -14,9 +15,11 @@ import org.gradle.language.base.artifact.SourcesArtifact
|
|||||||
import org.gradle.language.java.artifact.JavadocArtifact
|
import org.gradle.language.java.artifact.JavadocArtifact
|
||||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinResolvedBinaryDependency
|
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinResolvedBinaryDependency
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
import org.jetbrains.kotlin.gradle.plugin.ide.IdeDependencyResolver
|
import org.jetbrains.kotlin.gradle.plugin.ide.IdeDependencyResolver
|
||||||
import org.jetbrains.kotlin.gradle.plugin.ide.IdeaKotlinBinaryCoordinates
|
import org.jetbrains.kotlin.gradle.plugin.ide.IdeaKotlinBinaryCoordinates
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.mpp.internal
|
||||||
import org.jetbrains.kotlin.gradle.plugin.mpp.resolvableMetadataConfiguration
|
import org.jetbrains.kotlin.gradle.plugin.mpp.resolvableMetadataConfiguration
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
import org.jetbrains.kotlin.gradle.plugin.sources.internal
|
||||||
import org.jetbrains.kotlin.gradle.plugin.sources.project
|
import org.jetbrains.kotlin.gradle.plugin.sources.project
|
||||||
@@ -32,7 +35,7 @@ import org.jetbrains.kotlin.gradle.plugin.sources.project
|
|||||||
internal object IdeArtifactResolutionQuerySourcesAndDocumentationResolver : IdeDependencyResolver {
|
internal object IdeArtifactResolutionQuerySourcesAndDocumentationResolver : IdeDependencyResolver {
|
||||||
override fun resolve(sourceSet: KotlinSourceSet): Set<IdeaKotlinDependency> {
|
override fun resolve(sourceSet: KotlinSourceSet): Set<IdeaKotlinDependency> {
|
||||||
val project = sourceSet.project
|
val project = sourceSet.project
|
||||||
val configuration = sourceSet.internal.resolvableMetadataConfiguration
|
val configuration = selectConfiguration(sourceSet)
|
||||||
val resolutionResult = project.dependencies.createArtifactResolutionQuery()
|
val resolutionResult = project.dependencies.createArtifactResolutionQuery()
|
||||||
.forComponents(configuration.incoming.resolutionResult.allComponents.map { it.id })
|
.forComponents(configuration.incoming.resolutionResult.allComponents.map { it.id })
|
||||||
.withArtifacts(JvmLibrary::class.java, SourcesArtifact::class.java, JavadocArtifact::class.java)
|
.withArtifacts(JvmLibrary::class.java, SourcesArtifact::class.java, JavadocArtifact::class.java)
|
||||||
@@ -58,4 +61,10 @@ internal object IdeArtifactResolutionQuerySourcesAndDocumentationResolver : IdeD
|
|||||||
}
|
}
|
||||||
}.toSet()
|
}.toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun selectConfiguration(sourceSet: KotlinSourceSet): Configuration {
|
||||||
|
val platformCompilation = sourceSet.internal.compilations.singleOrNull { it.platformType != KotlinPlatformType.common }
|
||||||
|
return platformCompilation?.internal?.configurations?.compileDependencyConfiguration
|
||||||
|
?: sourceSet.internal.resolvableMetadataConfiguration
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+147
@@ -0,0 +1,147 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@file:Suppress("FunctionName", "DuplicatedCode")
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.gradle.ide
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.applyMultiplatformPlugin
|
||||||
|
import org.jetbrains.kotlin.gradle.buildProject
|
||||||
|
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||||
|
import org.jetbrains.kotlin.gradle.enableDefaultStdlibDependency
|
||||||
|
import org.jetbrains.kotlin.gradle.enableDependencyVerification
|
||||||
|
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||||
|
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinResolvedBinaryDependency
|
||||||
|
import org.jetbrains.kotlin.gradle.idea.testFixtures.tcs.assertMatches
|
||||||
|
import org.jetbrains.kotlin.gradle.idea.testFixtures.tcs.binaryCoordinates
|
||||||
|
import org.jetbrains.kotlin.gradle.kpm.idea.mavenCentralCacheRedirector
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.ide.dependencyResolvers.IdeNativeStdlibDependencyResolver
|
||||||
|
import org.jetbrains.kotlin.gradle.plugin.ide.kotlinIdeMultiplatformImport
|
||||||
|
import kotlin.test.Test
|
||||||
|
import kotlin.test.fail
|
||||||
|
import kotlin.text.Regex.Companion.escape
|
||||||
|
|
||||||
|
class IdeSourcesAndDocumentationResolutionTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `test - MVIKotlin`() {
|
||||||
|
val project = buildProject {
|
||||||
|
enableDefaultStdlibDependency(false)
|
||||||
|
enableDependencyVerification(false)
|
||||||
|
applyMultiplatformPlugin()
|
||||||
|
repositories.mavenCentralCacheRedirector()
|
||||||
|
}
|
||||||
|
|
||||||
|
val kotlin = project.multiplatformExtension
|
||||||
|
kotlin.targetHierarchy.default()
|
||||||
|
kotlin.jvm()
|
||||||
|
kotlin.linuxX64()
|
||||||
|
kotlin.linuxArm64()
|
||||||
|
|
||||||
|
val commonMain = kotlin.sourceSets.getByName("commonMain")
|
||||||
|
val commonTest = kotlin.sourceSets.getByName("commonTest")
|
||||||
|
val nativeMain = kotlin.sourceSets.getByName("nativeMain")
|
||||||
|
val nativeTest = kotlin.sourceSets.getByName("nativeTest")
|
||||||
|
val linuxX64Main = kotlin.sourceSets.getByName("linuxX64Main")
|
||||||
|
val linuxX64Test = kotlin.sourceSets.getByName("linuxX64Test")
|
||||||
|
|
||||||
|
commonMain.dependencies {
|
||||||
|
implementation("com.arkivanov.mvikotlin:mvikotlin:3.0.2")
|
||||||
|
}
|
||||||
|
|
||||||
|
project.evaluate()
|
||||||
|
|
||||||
|
fun resolveDependencySources(sourceSet: KotlinSourceSet): List<IdeaKotlinResolvedBinaryDependency> =
|
||||||
|
project.kotlinIdeMultiplatformImport.resolveDependencies(sourceSet)
|
||||||
|
.filterIsInstance<IdeaKotlinResolvedBinaryDependency>()
|
||||||
|
.filter { it.binaryType == IdeaKotlinDependency.SOURCES_BINARY_TYPE }
|
||||||
|
|
||||||
|
|
||||||
|
/* Check commonMain&commonTest */
|
||||||
|
run {
|
||||||
|
val expectedDependencies = listOf(
|
||||||
|
binaryCoordinates("com.arkivanov.mvikotlin:mvikotlin:3.0.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.essenty:lifecycle:0.4.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.essenty:instance-keeper:0.4.2"),
|
||||||
|
|
||||||
|
/* sources.jar resolution using ArtifactResolutionQuery will resolve those additionally */
|
||||||
|
binaryCoordinates("org.jetbrains:annotations:13.0"),
|
||||||
|
binaryCoordinates(Regex(escape("org.jetbrains.kotlin:kotlin-stdlib") + ".*"))
|
||||||
|
)
|
||||||
|
|
||||||
|
val resolvedDependencies = resolveDependencySources(commonMain)
|
||||||
|
resolvedDependencies.assertMatches(expectedDependencies)
|
||||||
|
resolveDependencySources(commonTest).assertMatches(resolvedDependencies)
|
||||||
|
resolvedDependencies.assertFilesEndWith("-sources.jar")
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check nativeMain&nativeTest */
|
||||||
|
run {
|
||||||
|
val expectedDependencies = listOf(
|
||||||
|
binaryCoordinates("com.arkivanov.mvikotlin:mvikotlin:3.0.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.essenty:lifecycle:0.4.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.essenty:instance-keeper:0.4.2"),
|
||||||
|
IdeNativeStdlibDependencyResolver.nativeStdlibCoordinates(project),
|
||||||
|
|
||||||
|
/* sources.jar resolution using ArtifactResolutionQuery will resolve those additionally */
|
||||||
|
binaryCoordinates("org.jetbrains:annotations:13.0"),
|
||||||
|
binaryCoordinates(Regex(escape("org.jetbrains.kotlin:kotlin-stdlib") + ".*"))
|
||||||
|
)
|
||||||
|
|
||||||
|
val resolvedDependencies = resolveDependencySources(nativeMain)
|
||||||
|
resolvedDependencies.assertMatches(expectedDependencies)
|
||||||
|
resolveDependencySources(nativeTest).assertMatches(resolvedDependencies)
|
||||||
|
resolvedDependencies.assertFilesEndWith("-sources.jar", "-sources.zip")
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check linuxX64Main and linuxX64Test */
|
||||||
|
run {
|
||||||
|
val expectedDependencies = listOf(
|
||||||
|
/* Artifact Query is 'over providing' */
|
||||||
|
listOf(
|
||||||
|
binaryCoordinates("com.arkivanov.mvikotlin:mvikotlin:3.0.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.mvikotlin:utils-internal:3.0.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.mvikotlin:rx:3.0.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.mvikotlin:rx-internal:3.0.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.essenty:utils-internal:0.4.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.essenty:lifecycle:0.4.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.essenty:instance-keeper:0.4.2")
|
||||||
|
),
|
||||||
|
|
||||||
|
/* Required dependencies */
|
||||||
|
listOf(
|
||||||
|
binaryCoordinates("com.arkivanov.mvikotlin:rx-internal-linuxx64:3.0.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.mvikotlin:rx-linuxx64:3.0.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.mvikotlin:utils-internal-linuxx64:3.0.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.mvikotlin:mvikotlin-linuxx64:3.0.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.essenty:utils-internal-linuxx64:0.4.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.essenty:lifecycle-linuxx64:0.4.2"),
|
||||||
|
binaryCoordinates("com.arkivanov.essenty:instance-keeper-linuxx64:0.4.2")
|
||||||
|
),
|
||||||
|
|
||||||
|
/* Stdlib */
|
||||||
|
listOf(
|
||||||
|
binaryCoordinates("org.jetbrains:annotations:13.0"),
|
||||||
|
IdeNativeStdlibDependencyResolver.nativeStdlibCoordinates(project),
|
||||||
|
binaryCoordinates(Regex(escape("org.jetbrains.kotlin:kotlin-stdlib") + ".*"))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
val resolvedDependencies = resolveDependencySources(linuxX64Main)
|
||||||
|
resolvedDependencies.assertMatches(expectedDependencies)
|
||||||
|
resolveDependencySources(linuxX64Test).assertMatches(resolvedDependencies)
|
||||||
|
resolvedDependencies.assertFilesEndWith("-sources.jar", "-sources.zip")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Iterable<IdeaKotlinResolvedBinaryDependency>.assertFilesEndWith(vararg suffixes: String) {
|
||||||
|
forEach { dependency ->
|
||||||
|
if (suffixes.none { suffix -> dependency.binaryFile.path.endsWith(suffix) }) {
|
||||||
|
fail("Expected binaryFile to end with one of ${suffixes.toList()}. Found: ${dependency.binaryFile}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user