Skip to content

Commit

Permalink
chore: add build info in sf version
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Oct 15, 2024
1 parent b5c0ddf commit 420dfdd
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 37 deletions.
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,33 @@
</java>
</configuration>
</plugin>

<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<version>9.0.1</version>

<executions>
<execution>
<id>get-the-git-infos</id>
<goals>
<goal>revision</goal>
</goals>
<phase>initialize</phase>
</execution>
</executions>

<configuration>
<dateFormat>yyyy-MM-dd HH:mm:ss</dateFormat>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<includeOnlyProperties>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
</includeOnlyProperties>
<commitIdGenerationMode>full</commitIdGenerationMode>
</configuration>
</plugin>
</plugins>

<resources>
Expand All @@ -226,6 +253,7 @@
<include>biome-maps/*.json</include>

<include>languages/**/*.yml</include>
<include>git.properties</include>
</includes>
</resource>

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/city/norain/slimefun4/SlimefunExtended.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import city.norain.slimefun4.compatibillty.VersionedEvent;
import city.norain.slimefun4.listener.SlimefunMigrateListener;
import city.norain.slimefun4.utils.EnvUtil;
import io.github.bakedlibs.dough.versions.MinecraftVersion;
import io.github.bakedlibs.dough.versions.UnknownServerVersionException;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
Expand Down Expand Up @@ -63,6 +64,8 @@ public static boolean checkEnvironment(@Nonnull Slimefun sf) {
public static void init(@Nonnull Slimefun sf) {
EnvironmentChecker.scheduleSlimeGlueCheck(sf);

EnvUtil.init();

checkDebug();

VaultIntegration.register(sf);
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/city/norain/slimefun4/utils/EnvUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package city.norain.slimefun4.utils;

import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import lombok.experimental.UtilityClass;

@UtilityClass
public class EnvUtil {
public static Properties gitInfo = null;

public void init() {
try (var resource = Slimefun.class.getClassLoader().getResourceAsStream("build.properties")) {
var prop = new Properties();
prop.load(resource);

gitInfo = prop;
} catch (IOException e) {
Slimefun.logger().log(Level.WARNING, "无法加载构建信息", e);
}
}

public String getBuildTime() {
return gitInfo == null ? "null" : gitInfo.getProperty("git.build.time");
}

public String getBuildCommitID() {
return gitInfo == null ? "null" : gitInfo.getProperty("git.commit.id.abbrev");
}
}
35 changes: 0 additions & 35 deletions src/main/java/city/norain/slimefun4/utils/SimpleTimer.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.core.commands.subcommands;

import city.norain.slimefun4.utils.EnvUtil;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.core.commands.SlimefunCommand;
import io.github.thebusybiscuit.slimefun4.core.commands.SubCommand;
Expand Down Expand Up @@ -64,7 +65,13 @@ public void onExecute(@Nonnull CommandSender sender, @Nonnull String[] args) {
.color(ChatColor.DARK_GREEN)
.append("Slimefun ")
.color(ChatColor.GREEN)
.append(Slimefun.getVersion() + '\n')
.append(Slimefun.getVersion()
+ (Slimefun.getVersion().contains("release") ? "" : " (" + EnvUtil.getBuildCommitID() + ")")
+ '\n')
.color(ChatColor.DARK_GREEN)
.append("构建时间 ")
.color(ChatColor.GREEN)
.append(EnvUtil.getBuildTime())
.color(ChatColor.DARK_GREEN);
// @formatter:on

Expand All @@ -79,7 +86,7 @@ public void onExecute(@Nonnull CommandSender sender, @Nonnull String[] args) {

addJavaVersion(builder);

// Add notice to warn those smart people
// Specify we are NOT OFFICIAL build so no support from upstream
builder.append("\n由 StarWishsama 汉化")
.color(ChatColor.WHITE)
.append("\n请不要将此版本信息截图到 Discord/Github 反馈 Bug" + "\n优先到汉化页面反馈" + "\n")
Expand Down

0 comments on commit 420dfdd

Please sign in to comment.