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