-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #1411 Implement `Version` class (and related logic) to handle dependencies versioning ## Test Plan > How do we know the code works? 1. run ``` git checkout master &&\ ./gradlew clean assemble &&\ ./gradlew dependencyUpdates -DoutputFormatter=json -DoutputDir=. &&\ java -jar ./flank-scripts/build/libs/flank-scripts.jar dependencies update &&\ git diff >> dep_master ``` 1. run ``` git checkout . &&\ git checkout 1411-implement-version &&\ ./gradlew clean assemble &&\ ./gradlew dependencyUpdates -DoutputFormatter=json -DoutputDir=. &&\ java -jar ./flank-scripts/build/libs/flank-scripts.jar dependencies update &&\ git diff >> dep_version ``` 1. compare dep files ``` diff dep_master dep_version ``` 1. there should be no differences (nothing is printed to the console, exit code = 0) ## Checklist - [x] Unit tested
- Loading branch information
1 parent
2b84392
commit 5bb6870
Showing
15 changed files
with
294 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
flank-scripts/src/main/kotlin/flank/scripts/dependencies/update/DependencyUpdate.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package flank.scripts.dependencies.update | ||
|
||
import flank.scripts.utils.Version | ||
|
||
data class DependencyUpdate( | ||
val name: String, | ||
val valName: String, | ||
val oldVersion: String, | ||
val newVersion: String | ||
val oldVersion: Version, | ||
val newVersion: Version | ||
) |
13 changes: 7 additions & 6 deletions
13
flank-scripts/src/main/kotlin/flank/scripts/dependencies/update/GradleDependency.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
flank-scripts/src/main/kotlin/flank/scripts/utils/Version.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package flank.scripts.utils | ||
|
||
import kotlinx.serialization.KSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.descriptors.PrimitiveKind | ||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor | ||
import kotlinx.serialization.encoding.Decoder | ||
import kotlinx.serialization.encoding.Encoder | ||
|
||
object VersionSerializer : KSerializer<Version> { | ||
override val descriptor = PrimitiveSerialDescriptor("Version", PrimitiveKind.STRING) | ||
|
||
override fun deserialize(decoder: Decoder): Version = parseToVersion(decoder.decodeString()) | ||
|
||
override fun serialize(encoder: Encoder, value: Version) = encoder.encodeString(value.toString()) | ||
} | ||
|
||
@Serializable(with = VersionSerializer::class) | ||
data class Version( | ||
private val major: Int? = null, | ||
private val minor: Int? = null, | ||
private val micro: Int? = null, | ||
private val patch: Int? = null, | ||
private val qualifier: String? = null | ||
) : Comparable<Version> { | ||
private val hasSuffix = major != null && qualifier != null | ||
|
||
override operator fun compareTo(other: Version): Int = when { | ||
major differs other.major -> compareValuesBy(major, other.major, { it ?: 0 }) | ||
minor differs other.minor -> compareValuesBy(minor, other.minor, { it ?: 0 }) | ||
micro differs other.micro -> compareValuesBy(micro, other.micro, { it ?: 0 }) | ||
patch differs other.patch -> compareValuesBy(patch, other.patch, { it ?: 0 }) | ||
else -> nullsLast<String>().compare(qualifier, other.qualifier) | ||
} | ||
|
||
private infix fun Int?.differs(other: Int?) = (this ?: 0) != (other ?: 0) | ||
|
||
override fun toString(): String = listOfNotNull(major, minor, micro, patch) | ||
.joinToString(".") + "${if (hasSuffix) "-" else ""}${qualifier ?: ""}" | ||
} | ||
|
||
fun parseToVersion(versionString: String): Version { | ||
val groups = "(\\d*)\\.?(\\d*)\\.?(\\d*)\\.?(\\d*)[-.]?([a-zA-Z0-9_.-]*)".toRegex().find(versionString)?.groupValues | ||
return if (groups == null) Version(qualifier = versionString) | ||
else Version( | ||
major = groups[1].toIntOrNull(), | ||
minor = groups[2].toIntOrNull(), | ||
micro = groups[3].toIntOrNull(), | ||
patch = groups[4].toIntOrNull(), | ||
qualifier = if (groups[5].isNotBlank()) groups[5] else null | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.