[Gradle] Implement tests for IdePlatformDependencyResolver
^KT-54948 Verification Pending
This commit is contained in:
committed by
Space Team
parent
bc9296d646
commit
ee7989eb3b
+8
-2
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.gradle.idea.testFixtures.tcs
|
||||
import org.jetbrains.kotlin.gradle.idea.tcs.IdeaKotlinDependency
|
||||
import kotlin.test.fail
|
||||
|
||||
fun Iterable<IdeaKotlinDependency>.assertMatches(vararg notation: Any?) {
|
||||
fun Iterable<IdeaKotlinDependency>.assertMatches(vararg notation: Any?): Iterable<IdeaKotlinDependency> {
|
||||
val thisList = toList()
|
||||
val matchers = notation.flatMap { buildIdeaKotlinDependencyMatchers(it) }
|
||||
|
||||
@@ -16,7 +16,7 @@ fun Iterable<IdeaKotlinDependency>.assertMatches(vararg notation: Any?) {
|
||||
val missingDependencies = matchers.filter { matcher -> thisList.none { dependency -> matcher.matches(dependency) } }
|
||||
|
||||
if (unexpectedDependencies.isEmpty() && missingDependencies.isEmpty()) {
|
||||
return
|
||||
return this
|
||||
}
|
||||
|
||||
fail(
|
||||
@@ -42,6 +42,12 @@ fun Iterable<IdeaKotlinDependency>.assertMatches(vararg notation: Any?) {
|
||||
thisList.forEach { dependency ->
|
||||
appendLine("\"${dependency}\",")
|
||||
}
|
||||
|
||||
appendLine()
|
||||
appendLine("Dependencies (coordinates):")
|
||||
thisList.forEach { dependency ->
|
||||
appendLine("\"${dependency.coordinates}\"")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
+2
-3
@@ -9,7 +9,6 @@ import org.gradle.api.artifacts.ArtifactView
|
||||
import org.gradle.api.artifacts.component.ComponentIdentifier
|
||||
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
|
||||
import org.gradle.api.artifacts.component.ModuleComponentSelector
|
||||
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
|
||||
import org.gradle.api.attributes.AttributeContainer
|
||||
import org.gradle.api.logging.Logging
|
||||
import org.gradle.internal.resolve.ModuleVersionResolveException
|
||||
@@ -109,7 +108,7 @@ internal class IdePlatformDependencyResolver(
|
||||
|
||||
return compilation.internal.configurations.compileDependencyConfiguration.incoming.artifactView { view ->
|
||||
view.isLenient = true
|
||||
view.componentFilter { id -> id !is ProjectComponentIdentifier }
|
||||
view.componentFilter { id -> id is ModuleComponentIdentifier }
|
||||
view.attributes.setupArtifactViewAttributes(sourceSet)
|
||||
}
|
||||
}
|
||||
@@ -140,7 +139,7 @@ internal class IdePlatformDependencyResolver(
|
||||
|
||||
return sourceSetCompileDependencies.incoming.artifactView { view ->
|
||||
view.isLenient = true
|
||||
view.componentFilter { id -> id !is ProjectComponentIdentifier }
|
||||
view.componentFilter { id -> id is ModuleComponentIdentifier }
|
||||
view.attributes.setupArtifactViewAttributes(sourceSet)
|
||||
}
|
||||
}
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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")
|
||||
|
||||
package org.jetbrains.kotlin.gradle.ide
|
||||
|
||||
import org.jetbrains.kotlin.gradle.*
|
||||
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
|
||||
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.ide.dependencyResolvers.IdeJvmAndAndroidPlatformDependencyResolver
|
||||
import org.jetbrains.kotlin.gradle.utils.androidExtension
|
||||
import kotlin.test.BeforeTest
|
||||
import kotlin.test.Test
|
||||
|
||||
class IdeJvmAndAndroidPlatformDependencyResolverTest {
|
||||
|
||||
@BeforeTest
|
||||
fun checkEnvironment() {
|
||||
assumeAndroidSdkAvailable()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test - MVIKotlin - on jvmAndAndroidMain`() {
|
||||
val project = buildProject {
|
||||
enableDefaultStdlibDependency(false)
|
||||
enableDependencyVerification(false)
|
||||
applyMultiplatformPlugin()
|
||||
plugins.apply("com.android.library")
|
||||
androidExtension.compileSdkVersion(33)
|
||||
repositories.mavenCentralCacheRedirector()
|
||||
}
|
||||
|
||||
val kotlin = project.multiplatformExtension
|
||||
kotlin.targetHierarchy.custom {
|
||||
common {
|
||||
group("jvmAndAndroid") {
|
||||
jvm()
|
||||
android()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kotlin.jvm()
|
||||
kotlin.android()
|
||||
|
||||
kotlin.sourceSets.getByName("commonMain").dependencies {
|
||||
implementation("com.arkivanov.mvikotlin:mvikotlin:3.0.2")
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
val jvmAndAndroidDependencies = listOf(
|
||||
binaryCoordinates("com.arkivanov.mvikotlin:mvikotlin-jvm:3.0.2"),
|
||||
binaryCoordinates("com.arkivanov.essenty:lifecycle-jvm:0.4.2"),
|
||||
binaryCoordinates("com.arkivanov.essenty:instance-keeper-jvm:0.4.2"),
|
||||
binaryCoordinates("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10"),
|
||||
binaryCoordinates("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10"),
|
||||
binaryCoordinates("org.jetbrains.kotlin:kotlin-stdlib:1.7.10"),
|
||||
binaryCoordinates("org.jetbrains:annotations:13.0"),
|
||||
/* This resolver cannot differentiate between non-hmpp metadata libraries and platform libraries. This is OK */
|
||||
binaryCoordinates("org.jetbrains.kotlin:kotlin-stdlib-common:1.7.10")
|
||||
)
|
||||
|
||||
IdeJvmAndAndroidPlatformDependencyResolver(project).resolve(kotlin.sourceSets.getByName("jvmAndAndroidMain"))
|
||||
.assertMatches(jvmAndAndroidDependencies)
|
||||
|
||||
IdeJvmAndAndroidPlatformDependencyResolver(project).resolve(kotlin.sourceSets.getByName("jvmAndAndroidTest"))
|
||||
.assertMatches(jvmAndAndroidDependencies)
|
||||
}
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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.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.ide.dependencyResolvers.IdePlatformDependencyResolver
|
||||
import kotlin.test.Test
|
||||
|
||||
class IdePlatformDependencyResolverTest {
|
||||
|
||||
@Test
|
||||
fun `test - MVIKotlin - on jvm and linux platform source sets`() {
|
||||
val project = buildProject {
|
||||
enableDefaultStdlibDependency(false)
|
||||
enableDependencyVerification(false)
|
||||
applyMultiplatformPlugin()
|
||||
repositories.mavenCentralCacheRedirector()
|
||||
}
|
||||
|
||||
val kotlin = project.multiplatformExtension
|
||||
kotlin.targetHierarchy.default()
|
||||
|
||||
kotlin.jvm()
|
||||
kotlin.linuxX64()
|
||||
|
||||
val commonMain = kotlin.sourceSets.getByName("commonMain")
|
||||
val jvmMain = kotlin.sourceSets.getByName("jvmMain")
|
||||
val linuxX64Main = kotlin.sourceSets.getByName("linuxX64Main")
|
||||
val jvmTest = kotlin.sourceSets.getByName("jvmTest")
|
||||
val linuxX64Test = kotlin.sourceSets.getByName("linuxX64Test")
|
||||
|
||||
commonMain.dependencies {
|
||||
implementation("com.arkivanov.mvikotlin:mvikotlin:3.0.2")
|
||||
}
|
||||
|
||||
/* This resolver shall refuse to resolve for dependencies for metadata based dependencies */
|
||||
IdePlatformDependencyResolver().resolve(commonMain).assertMatches()
|
||||
|
||||
val jvmDependencies = listOf(
|
||||
binaryCoordinates("com.arkivanov.mvikotlin:mvikotlin-jvm:3.0.2"),
|
||||
binaryCoordinates("com.arkivanov.essenty:lifecycle-jvm:0.4.2"),
|
||||
binaryCoordinates("com.arkivanov.essenty:instance-keeper-jvm:0.4.2"),
|
||||
binaryCoordinates("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10"),
|
||||
binaryCoordinates("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10"),
|
||||
binaryCoordinates("org.jetbrains.kotlin:kotlin-stdlib:1.7.10"),
|
||||
binaryCoordinates("org.jetbrains:annotations:13.0")
|
||||
)
|
||||
|
||||
val linuxDependencies = listOf(
|
||||
binaryCoordinates("com.arkivanov.mvikotlin:mvikotlin-linuxx64:3.0.2"),
|
||||
binaryCoordinates("com.arkivanov.essenty:lifecycle-linuxx64:0.4.2"),
|
||||
binaryCoordinates("com.arkivanov.essenty:instance-keeper-linuxx64:0.4.2"),
|
||||
binaryCoordinates("org.jetbrains.kotlin:kotlin-stdlib:1.7.10"),
|
||||
binaryCoordinates("org.jetbrains:annotations:13.0"),
|
||||
|
||||
/* Special in K/N: There are no 'runtimeOnly' dependencies */
|
||||
binaryCoordinates("com.arkivanov.mvikotlin:rx-internal-linuxx64:3.0.2"),
|
||||
binaryCoordinates("com.arkivanov.mvikotlin:utils-internal-linuxx64:3.0.2"),
|
||||
binaryCoordinates("com.arkivanov.mvikotlin:rx-linuxx64:3.0.2"),
|
||||
binaryCoordinates("com.arkivanov.essenty:utils-internal-linuxx64:0.4.2"),
|
||||
)
|
||||
|
||||
IdePlatformDependencyResolver().resolve(jvmMain).assertMatches(jvmDependencies)
|
||||
IdePlatformDependencyResolver().resolve(jvmTest).assertMatches(jvmDependencies)
|
||||
IdePlatformDependencyResolver().resolve(linuxX64Main).assertMatches(linuxDependencies)
|
||||
IdePlatformDependencyResolver().resolve(linuxX64Test).assertMatches(linuxDependencies)
|
||||
}
|
||||
}
|
||||
-2
@@ -39,8 +39,6 @@ class IdeTransformedMetadataDependencyResolverTest {
|
||||
|
||||
commonMain.dependencies {
|
||||
implementation("com.arkivanov.mvikotlin:mvikotlin:3.0.2")
|
||||
implementation("com.arkivanov.essenty:lifecycle:0.4.2")
|
||||
implementation("com.arkivanov.essenty:instance-keeper:0.4.2")
|
||||
}
|
||||
|
||||
project.evaluate()
|
||||
|
||||
Reference in New Issue
Block a user