mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-13 13:54:37 +01:00
Show git hash when starting the server
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -72,4 +72,5 @@ Lunar Core Handbook.txt
|
|||||||
config.json
|
config.json
|
||||||
*.mv
|
*.mv
|
||||||
*.exe
|
*.exe
|
||||||
|
BuildConfig.java
|
||||||
Test.java
|
Test.java
|
||||||
20
build.gradle
20
build.gradle
@@ -102,6 +102,8 @@ application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
jar {
|
jar {
|
||||||
|
dependsOn 'injectGitHash'
|
||||||
|
|
||||||
exclude '*.proto'
|
exclude '*.proto'
|
||||||
|
|
||||||
manifest {
|
manifest {
|
||||||
@@ -145,6 +147,24 @@ eclipse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tasks.register('injectGitHash') {
|
||||||
|
def gitCommitHash = {
|
||||||
|
try {
|
||||||
|
return 'git rev-parse --verify --short HEAD'.execute().text.trim()
|
||||||
|
} catch (ignored) {
|
||||||
|
return 'GIT_NOT_FOUND'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new File(project.projectDir.getAbsolutePath() + '/src/main/java/emu/lunarcore/BuildConfig.java').text = """
|
||||||
|
package emu.lunarcore;
|
||||||
|
|
||||||
|
public final class BuildConfig {
|
||||||
|
public static final String GIT_HASH = \"${gitCommitHash()}\";
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
task updateProto {
|
task updateProto {
|
||||||
group 'Build'
|
group 'Build'
|
||||||
description 'Cleans generated proto folder and regenerates protos'
|
description 'Cleans generated proto folder and regenerates protos'
|
||||||
|
|||||||
@@ -59,6 +59,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...");
|
||||||
|
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;
|
||||||
|
|
||||||
@@ -168,6 +169,19 @@ public class LunarCore {
|
|||||||
getLogger().error("Config save error");
|
getLogger().error("Config save error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Git hash
|
||||||
|
|
||||||
|
private static String getGitHash() {
|
||||||
|
// Safely get the build config without errors even if it hasnt been generated yet
|
||||||
|
try {
|
||||||
|
Class<?> buildConfig = Class.forName("emu.lunarcore.BuildConfig");
|
||||||
|
return buildConfig.getField("GIT_HASH").get(null).toString();
|
||||||
|
} catch (Exception e) {
|
||||||
|
// Ignored
|
||||||
|
}
|
||||||
|
return "Unknown";
|
||||||
|
}
|
||||||
|
|
||||||
// Server console
|
// Server console
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user