Skip to content

Commit e498499

Browse files
sellmairSpace Team
authored and
Space Team
committed
[Gradle] Implement LazyResolvedConfigurationTest
KT-49933
1 parent 3162769 commit e498499

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
3+
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
4+
*/
5+
6+
@file:Suppress("FunctionName")
7+
8+
package org.jetbrains.kotlin.gradle.dependencyResolutionTests
9+
10+
import org.gradle.api.artifacts.Configuration
11+
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
12+
import org.jetbrains.kotlin.gradle.dsl.multiplatformExtension
13+
import org.jetbrains.kotlin.gradle.plugin.kotlinToolingVersion
14+
import org.jetbrains.kotlin.gradle.plugin.mpp.internal
15+
import org.jetbrains.kotlin.gradle.util.applyMultiplatformPlugin
16+
import org.jetbrains.kotlin.gradle.util.buildProject
17+
import org.jetbrains.kotlin.gradle.util.enableDependencyVerification
18+
import org.jetbrains.kotlin.gradle.utils.LazyResolvedConfiguration
19+
import org.jetbrains.kotlin.gradle.utils.allResolvedDependencies
20+
import org.junit.Test
21+
import kotlin.test.assertEquals
22+
import kotlin.test.fail
23+
24+
class LazyResolvedConfigurationTest {
25+
26+
@Test
27+
fun `test - creating LazyResolvedConfiguration - will not resolve source configuration`() {
28+
val project = buildProject()
29+
val configuration = project.configurations.create("forTest")
30+
LazyResolvedConfiguration(configuration)
31+
32+
assertEquals(
33+
Configuration.State.UNRESOLVED, configuration.state,
34+
"Expected construction of 'LazyResolvedConfiguration' to not cause resolution of source configuration"
35+
)
36+
}
37+
38+
@Test
39+
fun `test - okio - getArtifacts`() {
40+
val project = buildProject {
41+
enableDependencyVerification(false)
42+
repositories.mavenLocal()
43+
repositories.mavenCentral()
44+
applyMultiplatformPlugin()
45+
}
46+
47+
val kotlin = project.multiplatformExtension
48+
kotlin.jvm()
49+
kotlin.linuxX64()
50+
51+
kotlin.sourceSets.getByName("commonMain").dependencies {
52+
implementation("com.squareup.okio:okio:3.3.0")
53+
}
54+
55+
project.evaluate()
56+
57+
val commonMainCompileDependencies = kotlin.metadata().compilations.getByName("commonMain")
58+
.internal.configurations.compileDependencyConfiguration
59+
60+
val lazyCommonMainCompileDependencies = LazyResolvedConfiguration(commonMainCompileDependencies)
61+
assertEquals(lazyCommonMainCompileDependencies.allDependencies, lazyCommonMainCompileDependencies.allResolvedDependencies)
62+
if (lazyCommonMainCompileDependencies.allResolvedDependencies.isEmpty()) fail("Expected some resolved dependencies")
63+
64+
/* Check stdlib-common dependency on commonMainCompileDependencies */
65+
run {
66+
val resolvedStdlibCommon = lazyCommonMainCompileDependencies.allResolvedDependencies.filter { dependencyResult ->
67+
dependencyResult.resolvedVariant.owner.let { id -> id is ModuleComponentIdentifier && id.module == "kotlin-stdlib-common" }
68+
}
69+
70+
if (resolvedStdlibCommon.isEmpty()) fail("Expected kotlin-stdlib-common in resolved dependencies")
71+
resolvedStdlibCommon.forEach { dependencyResult ->
72+
val artifacts = lazyCommonMainCompileDependencies.getArtifacts(dependencyResult)
73+
if (artifacts.isEmpty()) fail("Expected some artifacts resolved for $dependencyResult")
74+
artifacts.forEach { artifact ->
75+
assertEquals(artifact.file.name, "kotlin-stdlib-common-${project.kotlinToolingVersion}.jar")
76+
}
77+
}
78+
}
79+
80+
/* Check okio dependency on commonMainCompileDependencies */
81+
run {
82+
val resolvedOkio = lazyCommonMainCompileDependencies.allResolvedDependencies.filter { dependencyResult ->
83+
dependencyResult.resolvedVariant.owner.let { id -> id is ModuleComponentIdentifier && id.module == "okio" }
84+
}
85+
86+
if (resolvedOkio.isEmpty()) fail("Expected okio in resolved dependencies")
87+
resolvedOkio.forEach { dependencyResult ->
88+
val artifacts = lazyCommonMainCompileDependencies.getArtifacts(dependencyResult)
89+
if (artifacts.isEmpty()) fail("Expected some artifacts resolved for $dependencyResult")
90+
artifacts.forEach { artifact ->
91+
assertEquals("okio-metadata-3.3.0-all.jar", artifact.file.name)
92+
}
93+
}
94+
}
95+
96+
/* Check okio dependency on linuxX64MainCompile */
97+
run {
98+
val lazyLinuxX64CompileDependencies = LazyResolvedConfiguration(
99+
kotlin.linuxX64().compilations.getByName("main").internal.configurations.compileDependencyConfiguration
100+
)
101+
102+
val resolvedOkio = lazyLinuxX64CompileDependencies.allResolvedDependencies.filter { dependencyResult ->
103+
dependencyResult.resolvedVariant.owner.let { id -> id is ModuleComponentIdentifier && id.module == "okio" }
104+
}
105+
if (resolvedOkio.isEmpty()) fail("Expected okio in resolved dependencies")
106+
resolvedOkio.forEach { dependencyResult ->
107+
val artifacts = lazyLinuxX64CompileDependencies.getArtifacts(dependencyResult)
108+
if (artifacts.isEmpty()) fail("Expected some artifacts resolved for $dependencyResult")
109+
artifacts.forEach { artifact ->
110+
val artifactComponentIdentifier = artifact.id.componentIdentifier as ModuleComponentIdentifier
111+
assertEquals("okio-linuxx64", artifactComponentIdentifier.module, "Expected linux specific component identifier")
112+
}
113+
}
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)