mirror of
https://github.com/Melledy/LunarCore.git
synced 2025-12-12 21:34:35 +01:00
Format commit timestamp in local time
This commit is contained in:
@@ -180,7 +180,7 @@ tasks.register('injectGitHash') {
|
||||
|
||||
def gitCommitTime = {
|
||||
try {
|
||||
return 'git log -1 --format=%cd --date=iso'.execute().text.trim()
|
||||
return 'git log -1 --format=%at --date=unix'.execute().text.trim()
|
||||
} catch (ignored) {
|
||||
return ''
|
||||
}
|
||||
@@ -192,7 +192,7 @@ package emu.lunarcore;
|
||||
public final class BuildConfig {
|
||||
public static final String VERSION = \"${version}\";
|
||||
public static final String GIT_HASH = \"${gitCommitHash()}\";
|
||||
public static final String GIT_HASH_TIME = \"${gitCommitTime()}\";
|
||||
public static final long COMMIT_TIMESTAMP = ${gitCommitTime()};
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package emu.lunarcore;
|
||||
|
||||
import java.io.*;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import emu.lunarcore.plugin.PluginManager;
|
||||
import org.jline.reader.EndOfFileException;
|
||||
@@ -210,26 +212,33 @@ public class LunarCore {
|
||||
} catch (Exception e) {
|
||||
// Ignored
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private static String getGitHash() {
|
||||
// Use a string builder in case one of the build config fields are missing
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
// Safely get the build config class without errors even if it hasnt been generated yet
|
||||
try {
|
||||
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Class<?> buildConfig = Class.forName(LunarCore.class.getPackageName() + ".BuildConfig");
|
||||
|
||||
String hash = buildConfig.getField("GIT_HASH").get(null).toString();
|
||||
String date = buildConfig.getField("GIT_HASH_TIME").get(null).toString();
|
||||
builder.append(hash);
|
||||
|
||||
if (date == null || date.isEmpty()) {
|
||||
return hash;
|
||||
}
|
||||
|
||||
return hash + " (" + date + ")";
|
||||
long timestamp = buildConfig.getField("COMMIT_TIMESTAMP").getLong(null);
|
||||
builder.append(" (" + sf.format(new Date(timestamp * 1000)) + ")");
|
||||
} catch (Exception e) {
|
||||
// Ignored
|
||||
}
|
||||
return "Unknown";
|
||||
|
||||
if (builder.isEmpty()) {
|
||||
return "Unknown";
|
||||
} else {
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
||||
// Server console
|
||||
|
||||
Reference in New Issue
Block a user