Improve git version naming
This commit is contained in:
parent
4a6fd46114
commit
76169cc912
@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream
|
import it.unimi.dsi.fastutil.io.FastByteArrayOutputStream
|
||||||
|
import kotlin.text.Regex
|
||||||
|
|
||||||
val mod_version: String by project
|
val mod_version: String by project
|
||||||
val mc_version: String by project
|
val mc_version: String by project
|
||||||
@ -11,7 +12,6 @@ val mod_id: String by project
|
|||||||
val handle_deps: String by project
|
val handle_deps: String by project
|
||||||
val use_commit_hash_in_version: String by project
|
val use_commit_hash_in_version: String by project
|
||||||
val handleDeps = handle_deps == "true"
|
val handleDeps = handle_deps == "true"
|
||||||
val useCommitHashInVersion = use_commit_hash_in_version == "true"
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
java
|
java
|
||||||
@ -26,10 +26,41 @@ configurations {
|
|||||||
get("implementation").extendsFrom(get("library"), get("klibrary"))
|
get("implementation").extendsFrom(get("library"), get("klibrary"))
|
||||||
}
|
}
|
||||||
|
|
||||||
version = if (useCommitHashInVersion) getCommitVersion() else mod_version
|
data class GitInfo(val version: String, val count: String, val tag: String) {
|
||||||
|
// val tagIsVersion: Boolean get() = tag != "" && tag.matches(Regex("v[0-9]+\\.[0-9]\\.[0-9]"))
|
||||||
|
|
||||||
|
val mainVersion: String get() = if (tag != "") tag else mod_version
|
||||||
|
|
||||||
|
val jarName: String get() {
|
||||||
|
if (count != "") {
|
||||||
|
return "$mainVersion-SNAPSHOT-${version}_$count"
|
||||||
|
}
|
||||||
|
|
||||||
|
if (version != "") {
|
||||||
|
return "$mainVersion-SNAPSHOT-$version"
|
||||||
|
} else {
|
||||||
|
return "$mainVersion-SNAPSHOT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val modVersion: String get() {
|
||||||
|
if (tag != "")
|
||||||
|
return mod_version
|
||||||
|
|
||||||
|
if (version != "") {
|
||||||
|
return "$mainVersion-SNAPSHOT-$version"
|
||||||
|
} else {
|
||||||
|
return "$mainVersion-SNAPSHOT"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val gitVersion = getCommitVersion() ?: GitInfo("", "", "")
|
||||||
|
|
||||||
|
version = gitVersion.modVersion
|
||||||
group = "ru.dbotthepony"
|
group = "ru.dbotthepony"
|
||||||
|
|
||||||
fun getCommitVersion(): String {
|
fun getCommitVersion(): GitInfo? {
|
||||||
try {
|
try {
|
||||||
val versionStream = FastByteArrayOutputStream()
|
val versionStream = FastByteArrayOutputStream()
|
||||||
val tagStream = FastByteArrayOutputStream()
|
val tagStream = FastByteArrayOutputStream()
|
||||||
@ -53,33 +84,21 @@ fun getCommitVersion(): String {
|
|||||||
standardOutput = tagStream
|
standardOutput = tagStream
|
||||||
}.exitValue == 0
|
}.exitValue == 0
|
||||||
|
|
||||||
|
if (!gotVersion || !gotCount || !gotTag) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
val version = versionStream.array.copyOfRange(0, versionStream.length).toString(Charsets.UTF_8).trim()
|
val version = versionStream.array.copyOfRange(0, versionStream.length).toString(Charsets.UTF_8).trim()
|
||||||
val tag = tagStream.array.copyOfRange(0, tagStream.length).toString(Charsets.UTF_8).trim()
|
val tag = tagStream.array.copyOfRange(0, tagStream.length).toString(Charsets.UTF_8).trim()
|
||||||
val count = countStream.array.copyOfRange(0, countStream.length).toString(Charsets.UTF_8).trim()
|
val count = countStream.array.copyOfRange(0, countStream.length).toString(Charsets.UTF_8).trim()
|
||||||
|
|
||||||
if (!gotVersion) {
|
return GitInfo(version, count, tag)
|
||||||
return mod_version
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gotTag && tag != "") {
|
|
||||||
if (gotCount && count != "") {
|
|
||||||
return "$tag-SNAPSHOT-${version}_$count"
|
|
||||||
} else {
|
|
||||||
return "$tag-SNAPSHOT-$version"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gotCount && count != "") {
|
|
||||||
return "$mod_version-SNAPSHOT-${version}_$count"
|
|
||||||
}
|
|
||||||
|
|
||||||
return "$mod_version-SNAPSHOT-$version"
|
|
||||||
} catch(err: Throwable) {
|
} catch(err: Throwable) {
|
||||||
println("Error getting git version")
|
println("Error getting git version")
|
||||||
println(err)
|
println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return mod_version
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))
|
||||||
@ -268,7 +287,7 @@ fun org.gradle.jvm.tasks.Jar.attachManifest() {
|
|||||||
"Specification-Vendor" to "DBotThePony",
|
"Specification-Vendor" to "DBotThePony",
|
||||||
"Specification-Version" to "1", // We are version 1 of ourselves
|
"Specification-Version" to "1", // We are version 1 of ourselves
|
||||||
"Implementation-Title" to project.name,
|
"Implementation-Title" to project.name,
|
||||||
"Implementation-Version" to tasks.jar.get().archiveVersion,
|
"Implementation-Version" to gitVersion.modVersion,
|
||||||
"Implementation-Vendor" to "DBotThePony",
|
"Implementation-Vendor" to "DBotThePony",
|
||||||
"Implementation-Timestamp" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date())
|
"Implementation-Timestamp" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date())
|
||||||
))
|
))
|
||||||
@ -281,6 +300,7 @@ tasks.jar.configure {
|
|||||||
from(configurations["library"].map { if (it.isDirectory) it else zipTree(it) })
|
from(configurations["library"].map { if (it.isDirectory) it else zipTree(it) })
|
||||||
finalizedBy("reobfJar")
|
finalizedBy("reobfJar")
|
||||||
attachManifest()
|
attachManifest()
|
||||||
|
archiveVersion.set(gitVersion.jarName)
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
Loading…
Reference in New Issue
Block a user