Skip to content

Commit 978fb39

Browse files
TapchicomaSpace Team
authored andcommitted
[Gradle] Track 'webTest' dependencies usage
^KT-79482 Fixed
1 parent 8148d3d commit 978fb39

File tree

4 files changed

+120
-11
lines changed

4 files changed

+120
-11
lines changed

libraries/tools/kotlin-gradle-plugin/src/common/kotlin/org/jetbrains/kotlin/gradle/plugin/statistics/FusMetrics.kt

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ internal object KotlinSourceSetMetrics : FusMetrics {
412412
project.reportSourceSetDependenciesUsage(
413413
mapOf(
414414
"webMain" to BooleanMetrics.KOTLIN_WEB_MAIN_DEPENDENCIES_PRESENT,
415+
"webTest" to BooleanMetrics.KOTLIN_WEB_TEST_DEPENDENCIES_PRESENT,
415416
)
416417
)
417418
}
@@ -431,12 +432,11 @@ internal object KotlinSourceSetMetrics : FusMetrics {
431432
sourceSetNameToMetricMap: Map<String, BooleanMetrics>
432433
) {
433434
project.kotlinExtension.awaitSourceSets().configureEach { sourceSet ->
434-
if (sourceSetNameToMetricMap.keys.any { it == sourceSet.name }) {
435+
val metric = sourceSetNameToMetricMap[sourceSet.name]
436+
if (metric != null) {
435437
if (!sourceSet.allKotlinSources.isEmpty) {
436438
project.addConfigurationMetrics { metricsContainer ->
437-
sourceSetNameToMetricMap[sourceSet.name]?.let { metric ->
438-
metricsContainer.put(metric, true)
439-
}
439+
metricsContainer.put(metric, true)
440440
}
441441
}
442442
}
@@ -447,7 +447,8 @@ internal object KotlinSourceSetMetrics : FusMetrics {
447447
sourceSetNameToMetricMap: Map<String, BooleanMetrics>
448448
) {
449449
project.kotlinExtension.awaitSourceSets().configureEach { sourceSet ->
450-
if (sourceSetNameToMetricMap.keys.any { it == sourceSet.name }) {
450+
val metric = sourceSetNameToMetricMap[sourceSet.name]
451+
if (metric != null) {
451452
listOf(
452453
sourceSet.apiConfigurationName,
453454
sourceSet.implementationConfigurationName,
@@ -456,10 +457,8 @@ internal object KotlinSourceSetMetrics : FusMetrics {
456457
).map { project.configurations.getByName(it) }
457458
.forEach { configuration ->
458459
if (configuration.dependencies.isNotEmpty()) {
459-
sourceSetNameToMetricMap[sourceSet.name]?.let { metric ->
460-
project.addConfigurationMetrics { metricsContainer ->
461-
metricsContainer.put(metric, true)
462-
}
460+
project.addConfigurationMetrics { metricsContainer ->
461+
metricsContainer.put(metric, true)
463462
}
464463
}
465464
}

libraries/tools/kotlin-gradle-plugin/src/functionalTest/kotlin/org/jetbrains/kotlin/gradle/unitTests/fus/FUSWebTestSourceSetTest.kt

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,113 @@ class FUSWebTestSourceSetTest {
5656
)
5757
}
5858

59+
@Test
60+
fun emptyWebTestDependenciesAreNotReported() {
61+
val project = buildProjectWithMPP(preApplyCode = enableFusOnCI) {
62+
with(multiplatformExtension) {
63+
js { nodejs() }
64+
wasmJs()
65+
}
66+
}
67+
68+
project.evaluate()
69+
70+
assertNotNull(
71+
project.collectedFusConfigurationTimeMetrics.booleanMetrics.keys.none {
72+
it.name == BooleanMetrics.KOTLIN_WEB_TEST_DEPENDENCIES_PRESENT.name
73+
}
74+
)
75+
}
76+
77+
@Test
78+
fun explicitlyAddedWebTestApiDependencyIsReported() {
79+
val project = buildProjectWithMPP(preApplyCode = enableFusOnCI) {
80+
with(multiplatformExtension) {
81+
js { browser() }
82+
wasmJs { browser() }
83+
84+
applyDefaultHierarchyTemplate()
85+
86+
sourceSets.getByName("webTest").dependencies {
87+
api("com.example:some-dependency:0.1")
88+
}
89+
}
90+
}
91+
project.evaluate()
92+
93+
assertNotNull(
94+
project.collectedFusConfigurationTimeMetrics.booleanMetrics.entries.singleOrNull {
95+
it.key == BooleanMetrics.KOTLIN_WEB_TEST_DEPENDENCIES_PRESENT && it.value
96+
}
97+
)
98+
}
99+
100+
@Test
101+
fun explicitlyAddedWebTestImplementationDependencyIsReported() {
102+
val project = buildProjectWithMPP(preApplyCode = enableFusOnCI) {
103+
with(multiplatformExtension) {
104+
js { browser() }
105+
wasmJs { browser() }
106+
107+
applyDefaultHierarchyTemplate()
108+
109+
sourceSets.getByName("webTest").dependencies {
110+
implementation("com.example:some-dependency:0.1")
111+
}
112+
}
113+
}
114+
project.evaluate()
115+
116+
assertNotNull(
117+
project.collectedFusConfigurationTimeMetrics.booleanMetrics.entries.singleOrNull {
118+
it.key == BooleanMetrics.KOTLIN_WEB_TEST_DEPENDENCIES_PRESENT && it.value
119+
}
120+
)
121+
}
122+
123+
@Test
124+
fun explicitlyAddedWebTestCompileOnlyDependencyIsReported() {
125+
val project = buildProjectWithMPP(preApplyCode = enableFusOnCI) {
126+
with(multiplatformExtension) {
127+
js { browser() }
128+
wasmJs { browser() }
129+
130+
applyDefaultHierarchyTemplate()
131+
132+
sourceSets.getByName("webTest").dependencies {
133+
compileOnly("com.example:some-dependency:0.1")
134+
}
135+
}
136+
}
137+
project.evaluate()
138+
139+
assertNotNull(
140+
project.collectedFusConfigurationTimeMetrics.booleanMetrics.entries.singleOrNull {
141+
it.key == BooleanMetrics.KOTLIN_WEB_TEST_DEPENDENCIES_PRESENT && it.value
142+
}
143+
)
144+
}
145+
146+
@Test
147+
fun explicitlyAddedWebTestRuntimeOnlyDependencyIsReported() {
148+
val project = buildProjectWithMPP(preApplyCode = enableFusOnCI) {
149+
with(multiplatformExtension) {
150+
js { browser() }
151+
wasmJs { browser() }
152+
153+
applyDefaultHierarchyTemplate()
154+
155+
sourceSets.getByName("webTest").dependencies {
156+
runtimeOnly("com.example:some-dependency:0.1")
157+
}
158+
}
159+
}
160+
project.evaluate()
161+
162+
assertNotNull(
163+
project.collectedFusConfigurationTimeMetrics.booleanMetrics.entries.singleOrNull {
164+
it.key == BooleanMetrics.KOTLIN_WEB_TEST_DEPENDENCIES_PRESENT && it.value
165+
}
166+
)
167+
}
59168
}

libraries/tools/kotlin-gradle-statistics/src/main/kotlin/org/jetbrains/kotlin/statistics/metrics/BooleanMetrics.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ enum class BooleanMetrics(val type: BooleanOverridePolicy, val anonymization: Bo
5252
KOTLIN_WEB_MAIN_SOURCES_USED(OR, SAFE),
5353
KOTLIN_WEB_TEST_SOURCES_USED(OR, SAFE),
5454
KOTLIN_WEB_MAIN_DEPENDENCIES_PRESENT(OR, SAFE),
55+
KOTLIN_WEB_TEST_DEPENDENCIES_PRESENT(OR, SAFE),
5556

5657
// Disabled explicitly by the user
5758
KOTLIN_CROSS_COMPILATION_DISABLED(OR, SAFE),
@@ -131,6 +132,6 @@ enum class BooleanMetrics(val type: BooleanOverridePolicy, val anonymization: Bo
131132
;
132133

133134
companion object {
134-
const val VERSION = 23
135+
const val VERSION = 24
135136
}
136137
}

libraries/tools/kotlin-gradle-statistics/src/test/kotlin/org/jetbrains/kotlin/statistics/ModuleChangesCatchingTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private const val STRING_METRICS_RELATIVE_PATH = "$SOURCE_CODE_RELATIVE_PATH/Str
2323
private const val NUMERICAL_METRICS_RELATIVE_PATH = "$SOURCE_CODE_RELATIVE_PATH/NumericalMetrics.kt"
2424

2525
private val STRING_METRICS_EXPECTED_VERSION_AND_HASH = Pair(7, "68c988d45b3d7a9a3bacd2aa886fb490")
26-
private val BOOLEAN_METRICS_EXPECTED_VERSION_AND_HASH = Pair(20, "3214d8e1eaae57ffb16212800ecd4877")
26+
private val BOOLEAN_METRICS_EXPECTED_VERSION_AND_HASH = Pair(24, "8ee2f98f71ae139c89344c7db8c6dd12")
2727
private val NUMERICAL_METRICS_EXPECTED_VERSION_AND_HASH = Pair(2, "d8c1a1f4fb7227fbe8247320bf3370ca")
2828
private val SOURCE_FOLDER_EXPECTED_VERSION_AND_HASH =
2929
Pair(

0 commit comments

Comments
 (0)