|
| 1 | +#!/usr/bin/env kotlin |
| 2 | + |
| 3 | +import java.io.File |
| 4 | +import java.net.URL |
| 5 | +import javax.xml.parsers.DocumentBuilderFactory |
| 6 | + |
| 7 | +fun main() { |
| 8 | + // Update versions in libraries.toml |
| 9 | + val kotlinVersion = getLatestVersion("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/org/jetbrains/kotlin/kotlin-stdlib/maven-metadata.xml") |
| 10 | + val kspVersion = getLatestVersion("https://oss.sonatype.org/content/repositories/snapshots/com/google/devtools/ksp/com.google.devtools.ksp.gradle.plugin/maven-metadata.xml") |
| 11 | + File("gradle/libraries.toml").let { file -> |
| 12 | + file.writeText( |
| 13 | + file.readText() |
| 14 | + .replaceVersion("kotlin-plugin", kotlinVersion) |
| 15 | + .replaceVersion("kotlin-plugin-max", kotlinVersion) |
| 16 | + .replaceVersion("kotlin-stdlib", kotlinVersion) |
| 17 | + .replaceVersion("ksp", kspVersion) |
| 18 | + ) |
| 19 | + } |
| 20 | + |
| 21 | + // Uncomment Kotlin dev maven repository, add Sonatype snapshots repository |
| 22 | + setOf( |
| 23 | + File("gradle/repositories.gradle.kts"), |
| 24 | + File("intellij-plugin/build.gradle.kts"), |
| 25 | + ) |
| 26 | + .forEach { file -> |
| 27 | + file.writeText( |
| 28 | + file.readText() |
| 29 | + .replace( |
| 30 | + """// maven { url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") }""", |
| 31 | + """ |
| 32 | + maven { url = uri("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev/") } |
| 33 | + maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots/") } |
| 34 | + """.trimIndent() |
| 35 | + ) |
| 36 | + ) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +fun String.replaceVersion(key: String, version: String): String { |
| 41 | + return replace(Regex("""$key = ".*""""), """$key = "$version"""") |
| 42 | +} |
| 43 | + |
| 44 | +fun getLatestVersion(url: String): String { |
| 45 | + return URL(url) |
| 46 | + .openConnection() |
| 47 | + .getInputStream().use { inputStream -> |
| 48 | + DocumentBuilderFactory.newInstance() |
| 49 | + .newDocumentBuilder() |
| 50 | + .parse(inputStream) |
| 51 | + } |
| 52 | + .getElementsByTagName("latest") |
| 53 | + .item(0) |
| 54 | + .textContent |
| 55 | +} |
| 56 | + |
| 57 | +main() |
0 commit comments