Add build number back for local builds

I couldn't find a more efficient way to do this
This commit is contained in:
Telesphoreo 2023-12-01 23:43:27 -06:00
parent 6d80d5f4e3
commit 187226ff45
3 changed files with 21 additions and 8 deletions

View File

@ -1,4 +1,5 @@
import net.minecrell.pluginyml.paper.PaperPluginDescription import net.minecrell.pluginyml.paper.PaperPluginDescription
import java.io.ByteArrayOutputStream
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
@ -18,7 +19,9 @@ dependencies {
library("org.apache.maven.resolver:maven-resolver-transport-http:1.9.18") library("org.apache.maven.resolver:maven-resolver-transport-http:1.9.18")
library("org.jetbrains:annotations:24.1.0") library("org.jetbrains:annotations:24.1.0")
compileOnly("dev.folia:folia-api:1.20.2-R0.1-SNAPSHOT") compileOnly("dev.folia:folia-api:1.20.2-R0.1-SNAPSHOT")
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") compileOnly("com.github.MilkBowl:VaultAPI:1.7.1") {
exclude("org.bukkit", "bukkit")
}
implementation("org.bstats:bstats-base:3.0.2") implementation("org.bstats:bstats-base:3.0.2")
implementation("org.bstats:bstats-bukkit:3.0.2") implementation("org.bstats:bstats-bukkit:3.0.2")
} }
@ -63,6 +66,20 @@ paper {
} }
} }
fun getBuildNumber(): String {
val stdout = ByteArrayOutputStream()
try {
exec {
commandLine("git", "rev-list", "HEAD", "--count")
standardOutput = stdout
isIgnoreExitValue = true
}
} catch (e: GradleException) {
logger.error("Couldn't determine build number because Git is not installed. " + e.message)
}
return if (stdout.size() > 0) stdout.toString().trim() else "unknown"
}
tasks { tasks {
build { build {
dependsOn(shadowJar) dependsOn(shadowJar)
@ -77,7 +94,7 @@ tasks {
blossom { blossom {
resources { resources {
property("author", if (System.getenv("JENKINS_URL") != null) "jenkins" else System.getProperty("user.name")) property("author", if (System.getenv("JENKINS_URL") != null) "jenkins" else System.getProperty("user.name"))
property("buildNumber", if (System.getenv("BUILD_NUMBER") != null) System.getenv("BUILD_NUMBER") else "unknown") property("buildNumber", if (System.getenv("BUILD_NUMBER") != null) System.getenv("BUILD_NUMBER") else getBuildNumber())
property("date", SimpleDateFormat("MM/dd/yyyy '<light_purple>at<gold>' hh:mm:ss a z").format(Date())) property("date", SimpleDateFormat("MM/dd/yyyy '<light_purple>at<gold>' hh:mm:ss a z").format(Date()))
property("gitCommit", grgit.head().abbreviatedId) property("gitCommit", grgit.head().abbreviatedId)
} }

View File

@ -13,7 +13,6 @@ import org.bukkit.Bukkit;
public class PlayerMeta public class PlayerMeta
{ {
public static Component getPrefix(PlexPlayer plexPlayer) public static Component getPrefix(PlexPlayer plexPlayer)
{ {
if (plexPlayer.getPrefix() != null && !plexPlayer.getPrefix().isEmpty()) if (plexPlayer.getPrefix() != null && !plexPlayer.getPrefix().isEmpty())

View File

@ -1,10 +1,7 @@
author={{ author | default("unknown") }} author={{ author | default("unknown") }}
buildNumber={{ buildNumber }} buildNumber={{ buildNumber | default("unknown") }}
date={{ date }} date={{ date }}
gitCommit={{ gitCommit | default("unknown") }} gitCommit={{ gitCommit | default("unknown") }}
gitHead={{ gitHead | default("unknown") }}