Skip to content

Commit def7d8e

Browse files
ozzushSpace Team
authored andcommitted
Replace Kotlin version placeholder in actual instead of expected
KTI-1321
1 parent 2fab558 commit def7d8e

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

repo/artifacts-tests/src/test/kotlin/org/jetbrains/kotlin/code/GradleMetadataSchema.kt

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import kotlinx.serialization.Serializable
44
import kotlinx.serialization.SerialName
55
import org.jetbrains.kotlin.utils.addToStdlib.sequenceOfLazyValues
66

7+
private const val ORG_JETBRAINS_KOTLIN = "org.jetbrains.kotlin"
8+
79
fun Sequence<Int>.firstNonZeroOrZero() = firstOrNull { it != 0 } ?: 0
810

911
private fun <T : Comparable<T>> compareLists(
@@ -50,6 +52,11 @@ data class GradleMetadata(
5052
variants.forEach { it.sortListsRecursively() }
5153
}
5254

55+
fun replaceKotlinVersion(oldVersion: String, newVersion: String) {
56+
component.replaceKotlinVersion(oldVersion, newVersion)
57+
variants.forEach { it.replaceKotlinVersion(oldVersion, newVersion) }
58+
}
59+
5360
override fun compareTo(other: GradleMetadata): Int {
5461
return sequenceOf(
5562
compareValuesBy(this, other, { it.formatVersion }, { it.component }, { it.createdBy }),
@@ -60,12 +67,19 @@ data class GradleMetadata(
6067

6168
@Serializable
6269
data class Component(
63-
val url: String? = null,
70+
var url: String? = null,
6471
val group: String,
6572
val module: String,
66-
val version: String,
73+
var version: String,
6774
val attributes: ComponentAttributes? = null,
6875
) : Comparable<Component> {
76+
fun replaceKotlinVersion(oldVersion: String, newVersion: String) {
77+
if (group == ORG_JETBRAINS_KOTLIN) {
78+
url = url?.replace(oldVersion, newVersion)
79+
version = version.replace(oldVersion, newVersion)
80+
}
81+
}
82+
6983
override fun compareTo(other: Component): Int {
7084
return compareValuesBy(
7185
this, other,
@@ -115,6 +129,14 @@ data class Variant(
115129
val files: MutableList<File>? = null,
116130
val capabilities: MutableList<Capability>? = null,
117131
) : Comparable<Variant> {
132+
fun replaceKotlinVersion(oldVersion: String, newVersion: String) {
133+
files?.forEach { it.replaceKotlinVersion(oldVersion, newVersion) }
134+
capabilities?.forEach { it.replaceKotlinVersion(oldVersion, newVersion) }
135+
dependencies?.forEach { it.replaceKotlinVersion(oldVersion, newVersion) }
136+
dependencyConstraints?.forEach { it.replaceKotlinVersion(oldVersion, newVersion) }
137+
availableAt?.replaceKotlinVersion(oldVersion, newVersion)
138+
}
139+
118140
fun removeFilesFingerprint() {
119141
files?.forEach { it.removeFingerprint() }
120142
}
@@ -195,6 +217,12 @@ data class Dependency(
195217
requestedCapabilities?.sort()
196218
}
197219

220+
fun replaceKotlinVersion(oldVersion: String, newVersion: String) {
221+
if (group == ORG_JETBRAINS_KOTLIN) {
222+
version.requires = version.requires.replace(oldVersion, newVersion)
223+
}
224+
}
225+
198226
override fun compareTo(other: Dependency): Int {
199227
return sequenceOfLazyValues(
200228
{
@@ -215,7 +243,7 @@ data class Dependency(
215243

216244
@Serializable
217245
data class Version(
218-
val requires: String,
246+
var requires: String,
219247
) : Comparable<Version> {
220248
override fun compareTo(other: Version): Int {
221249
return compareValuesBy(this, other, { it.requires })
@@ -253,8 +281,8 @@ data class RequestedCapability(
253281

254282
@Serializable
255283
data class File(
256-
val name: String,
257-
val url: String,
284+
var name: String,
285+
var url: String,
258286
var size: Int?,
259287
var sha512: String?,
260288
var sha256: String?,
@@ -269,6 +297,11 @@ data class File(
269297
md5 = null
270298
}
271299

300+
fun replaceKotlinVersion(oldVersion: String, newVersion: String) {
301+
name = name.replace(oldVersion, newVersion)
302+
url = url.replace(oldVersion, newVersion)
303+
}
304+
272305
override fun compareTo(other: File) = compareValuesBy(
273306
this, other,
274307
{ it.name },
@@ -285,9 +318,15 @@ data class File(
285318
data class Capability(
286319
val group: String,
287320
val name: String,
288-
val version: String,
321+
var version: String,
289322
) : Comparable<Capability> {
290323
override fun compareTo(other: Capability): Int {
291324
return compareValuesBy(this, other, { it.group }, { it.name }, { it.version })
292325
}
326+
327+
fun replaceKotlinVersion(oldVersion: String, newVersion: String) {
328+
if (group == ORG_JETBRAINS_KOTLIN) {
329+
version = version.replace(oldVersion, newVersion)
330+
}
331+
}
293332
}

repo/artifacts-tests/src/test/kotlin/org/jetbrains/kotlin/code/GradleMetadataTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEqualsToFile
1111
import org.jetbrains.kotlin.test.services.JUnit5Assertions.isTeamCityBuild
1212
import org.junit.jupiter.api.DynamicTest
1313
import org.junit.jupiter.api.TestFactory
14+
import java.nio.file.Files
1415
import java.util.stream.Stream
1516
import kotlin.io.path.absolute
17+
import kotlin.io.path.name
1618
import kotlin.streams.asStream
1719
import kotlin.test.assertTrue
1820
import kotlin.test.fail

0 commit comments

Comments
 (0)