@@ -4,6 +4,8 @@ import kotlinx.serialization.Serializable
4
4
import kotlinx.serialization.SerialName
5
5
import org.jetbrains.kotlin.utils.addToStdlib.sequenceOfLazyValues
6
6
7
+ private const val ORG_JETBRAINS_KOTLIN = " org.jetbrains.kotlin"
8
+
7
9
fun Sequence<Int>.firstNonZeroOrZero () = firstOrNull { it != 0 } ? : 0
8
10
9
11
private fun <T : Comparable <T >> compareLists (
@@ -50,6 +52,11 @@ data class GradleMetadata(
50
52
variants.forEach { it.sortListsRecursively() }
51
53
}
52
54
55
+ fun replaceKotlinVersion (oldVersion : String , newVersion : String ) {
56
+ component.replaceKotlinVersion(oldVersion, newVersion)
57
+ variants.forEach { it.replaceKotlinVersion(oldVersion, newVersion) }
58
+ }
59
+
53
60
override fun compareTo (other : GradleMetadata ): Int {
54
61
return sequenceOf(
55
62
compareValuesBy(this , other, { it.formatVersion }, { it.component }, { it.createdBy }),
@@ -60,12 +67,19 @@ data class GradleMetadata(
60
67
61
68
@Serializable
62
69
data class Component (
63
- val url : String? = null ,
70
+ var url : String? = null ,
64
71
val group : String ,
65
72
val module : String ,
66
- val version : String ,
73
+ var version : String ,
67
74
val attributes : ComponentAttributes ? = null ,
68
75
) : 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
+
69
83
override fun compareTo (other : Component ): Int {
70
84
return compareValuesBy(
71
85
this , other,
@@ -115,6 +129,14 @@ data class Variant(
115
129
val files : MutableList <File >? = null ,
116
130
val capabilities : MutableList <Capability >? = null ,
117
131
) : 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
+
118
140
fun removeFilesFingerprint () {
119
141
files?.forEach { it.removeFingerprint() }
120
142
}
@@ -195,6 +217,12 @@ data class Dependency(
195
217
requestedCapabilities?.sort()
196
218
}
197
219
220
+ fun replaceKotlinVersion (oldVersion : String , newVersion : String ) {
221
+ if (group == ORG_JETBRAINS_KOTLIN ) {
222
+ version.requires = version.requires.replace(oldVersion, newVersion)
223
+ }
224
+ }
225
+
198
226
override fun compareTo (other : Dependency ): Int {
199
227
return sequenceOfLazyValues(
200
228
{
@@ -215,7 +243,7 @@ data class Dependency(
215
243
216
244
@Serializable
217
245
data class Version (
218
- val requires : String ,
246
+ var requires : String ,
219
247
) : Comparable<Version> {
220
248
override fun compareTo (other : Version ): Int {
221
249
return compareValuesBy(this , other, { it.requires })
@@ -253,8 +281,8 @@ data class RequestedCapability(
253
281
254
282
@Serializable
255
283
data class File (
256
- val name : String ,
257
- val url : String ,
284
+ var name : String ,
285
+ var url : String ,
258
286
var size : Int? ,
259
287
var sha512 : String? ,
260
288
var sha256 : String? ,
@@ -269,6 +297,11 @@ data class File(
269
297
md5 = null
270
298
}
271
299
300
+ fun replaceKotlinVersion (oldVersion : String , newVersion : String ) {
301
+ name = name.replace(oldVersion, newVersion)
302
+ url = url.replace(oldVersion, newVersion)
303
+ }
304
+
272
305
override fun compareTo (other : File ) = compareValuesBy(
273
306
this , other,
274
307
{ it.name },
@@ -285,9 +318,15 @@ data class File(
285
318
data class Capability (
286
319
val group : String ,
287
320
val name : String ,
288
- val version : String ,
321
+ var version : String ,
289
322
) : Comparable<Capability> {
290
323
override fun compareTo (other : Capability ): Int {
291
324
return compareValuesBy(this , other, { it.group }, { it.name }, { it.version })
292
325
}
326
+
327
+ fun replaceKotlinVersion (oldVersion : String , newVersion : String ) {
328
+ if (group == ORG_JETBRAINS_KOTLIN ) {
329
+ version = version.replace(oldVersion, newVersion)
330
+ }
331
+ }
293
332
}
0 commit comments