mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-15 06:45:04 +01:00
Add jar version and commit date to startup message
This commit is contained in:
13
build.gradle
13
build.gradle
@@ -26,7 +26,7 @@ compileTestJava.options.encoding = "UTF-8"
|
|||||||
sourceCompatibility = JavaVersion.VERSION_17
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
|
||||||
version = '1.0.0'
|
version = '1.0.1'
|
||||||
|
|
||||||
var shouldGenerateProto = System.getenv("GENERATE_PROTO") == "true"
|
var shouldGenerateProto = System.getenv("GENERATE_PROTO") == "true"
|
||||||
System.out.println(shouldGenerateProto ?
|
System.out.println(shouldGenerateProto ?
|
||||||
@@ -174,7 +174,15 @@ tasks.register('injectGitHash') {
|
|||||||
try {
|
try {
|
||||||
return 'git rev-parse --verify --short HEAD'.execute().text.trim()
|
return 'git rev-parse --verify --short HEAD'.execute().text.trim()
|
||||||
} catch (ignored) {
|
} catch (ignored) {
|
||||||
return 'GIT_NOT_FOUND'
|
return ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def gitCommitTime = {
|
||||||
|
try {
|
||||||
|
return 'git log -1 --format=%cd --date=iso'.execute().text.trim()
|
||||||
|
} catch (ignored) {
|
||||||
|
return ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -184,6 +192,7 @@ package emu.lunarcore;
|
|||||||
public final class BuildConfig {
|
public final class BuildConfig {
|
||||||
public static final String VERSION = \"${version}\";
|
public static final String VERSION = \"${version}\";
|
||||||
public static final String GIT_HASH = \"${gitCommitHash()}\";
|
public static final String GIT_HASH = \"${gitCommitHash()}\";
|
||||||
|
public static final String GIT_HASH_TIME = \"${gitCommitTime()}\";
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class LunarCore {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
// Start Server
|
// Start Server
|
||||||
LunarCore.getLogger().info("Starting Lunar Core...");
|
LunarCore.getLogger().info("Starting Lunar Core " + getJarVersion());
|
||||||
LunarCore.getLogger().info("Git hash: " + getGitHash());
|
LunarCore.getLogger().info("Git hash: " + getGitHash());
|
||||||
LunarCore.getLogger().info("Game version: " + GameConstants.VERSION);
|
LunarCore.getLogger().info("Game version: " + GameConstants.VERSION);
|
||||||
boolean generateHandbook = true;
|
boolean generateHandbook = true;
|
||||||
@@ -197,13 +197,32 @@ public class LunarCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Git hash
|
// Build Config
|
||||||
|
|
||||||
|
private static String getJarVersion() {
|
||||||
|
// Safely get the build config class without errors even if it hasnt been generated yet
|
||||||
|
try {
|
||||||
|
Class<?> buildConfig = Class.forName(LunarCore.class.getPackageName() + ".BuildConfig");
|
||||||
|
return buildConfig.getField("VERSION").get(null).toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
private static String getGitHash() {
|
private static String getGitHash() {
|
||||||
// Safely get the build config without errors even if it hasnt been generated yet
|
// Safely get the build config class without errors even if it hasnt been generated yet
|
||||||
try {
|
try {
|
||||||
Class<?> buildConfig = Class.forName("emu.lunarcore.BuildConfig");
|
Class<?> buildConfig = Class.forName(LunarCore.class.getPackageName() + ".BuildConfig");
|
||||||
return buildConfig.getField("GIT_HASH").get(null).toString();
|
|
||||||
|
String hash = buildConfig.getField("GIT_HASH").get(null).toString();
|
||||||
|
String date = buildConfig.getField("GIT_HASH_TIME").get(null).toString();
|
||||||
|
|
||||||
|
if (date == null || date.isEmpty()) {
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash + " (" + date + ")";
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Ignored
|
// Ignored
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user