3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-28 17:10:14 +01:00
ViaBackwards/build-logic/src/main/kotlin/extensions.kt

46 Zeilen
1.4 KiB
Kotlin

2021-05-29 09:32:55 +02:00
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import java.io.ByteArrayOutputStream
fun Project.latestCommitHash(): String {
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "rev-parse", "--short", "HEAD")
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
}
fun Project.latestCommitMessage(): String {
2023-08-10 16:26:51 +02:00
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "log", "-1", "--pretty=%B")
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
}
fun Project.branchName(): String {
val byteOut = ByteArrayOutputStream()
exec {
2023-09-26 02:48:42 +02:00
commandLine = listOf("git", "rev-parse", "--abbrev-ref", "HEAD")
2023-08-10 16:26:51 +02:00
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
}
2023-08-11 03:42:13 +02:00
fun Project.parseMinecraftSnapshotVersion(version: String): String? {
val separatorIndex = version.indexOf('-')
val lastSeparatorIndex = version.lastIndexOf('-')
if (separatorIndex == -1 || separatorIndex == lastSeparatorIndex) {
return null
}
return version.substring(separatorIndex + 1, lastSeparatorIndex)
}
2021-05-29 09:32:55 +02:00
fun JavaPluginExtension.javaTarget(version: Int) {
sourceCompatibility = JavaVersion.toVersion(version)
targetCompatibility = JavaVersion.toVersion(version)
}