Do not print stdlib version substitution message if nothing changed
This commit is contained in:
@@ -30,21 +30,25 @@ val writeStdlibVersion by tasks.registering {
|
||||
inputs.property("version", kotlinVersionLocal)
|
||||
outputs.file(versionFile)
|
||||
|
||||
fun replaceVersion(versionFile: File, versionPattern: String, replacement: (MatchResult) -> String) {
|
||||
fun Task.replaceVersion(versionFile: File, versionPattern: String, replacement: (MatchResult) -> String) {
|
||||
check(versionFile.isFile) { "Version file $versionFile is not found" }
|
||||
val text = versionFile.readText()
|
||||
val pattern = Regex(versionPattern)
|
||||
val match = pattern.find(text) ?: error("Version pattern is missing in file $versionFile")
|
||||
val group = match.groups[1]!!
|
||||
val newValue = replacement(match)
|
||||
versionFile.writeText(text.replaceRange(match.groups[1]!!.range, newValue))
|
||||
if (newValue != group.value) {
|
||||
logger.lifecycle("Writing new standard library version components: $newValue (was: ${group.value})")
|
||||
versionFile.writeText(text.replaceRange(group.range, newValue))
|
||||
} else {
|
||||
logger.info("Standard library version components: ${group.value}")
|
||||
}
|
||||
}
|
||||
|
||||
doLast {
|
||||
replaceVersion(versionFile, """fun get\(\): KotlinVersion = KotlinVersion\((\d+, \d+, \d+)\)""") {
|
||||
val (major, minor, _, optPatch) = Regex("""^(\d+)\.(\d+)(\.(\d+))?""").find(kotlinVersionLocal)?.destructured ?: error("Cannot parse current version $kotlinVersionLocal")
|
||||
val newVersion = "$major, $minor, ${optPatch.takeIf { it.isNotEmpty() } ?: "0" }"
|
||||
logger.lifecycle("Writing new standard library version components: $newVersion")
|
||||
newVersion
|
||||
"$major, $minor, ${optPatch.takeIf { it.isNotEmpty() } ?: "0" }"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user