forked from ktorio/ktor-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
synchronize_maven.kts
executable file
·33 lines (28 loc) · 1.1 KB
/
synchronize_maven.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env kscript
import java.io.*
import java.nio.charset.*
import java.util.*
val gradleProperties = Properties().apply { load(File("gradle.properties").readText().reader()) }
fun File.updateText(save: Boolean = true, charset: Charset = Charsets.UTF_8, callback: (String) -> String) {
val oldContent = readText()
val newContent = callback(oldContent)
if (save) {
writeText(newContent)
}
}
fun updatePomXml(pomFile: File) {
println("Processing $pomFile...")
pomFile.updateText(save = true) { oldContent ->
oldContent.replace(Regex("""<(\w+?)\.version>(.*?)</\1\.version>""")) {
val kind = it.groupValues[1]
val oldVersion = it.groupValues[2]
val newVersion = gradleProperties["${kind}_version"] ?: oldVersion
if (oldVersion != newVersion) {
println(" - Updating... $kind: '$oldVersion' -> '$newVersion'")
}
"<$kind.version>$newVersion</$kind.version>"
}
}
}
updatePomXml(File("other/maven-netty/pom.xml"))
updatePomXml(File("other/maven-google-appengine-standard/pom.xml"))