Skip to content

Commit

Permalink
chore: show build branch in version detail
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Oct 20, 2024
1 parent 65c9910 commit 401a59c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<includeOnlyProperties>
<includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
<includeOnlyProperty>git.branch</includeOnlyProperty>
</includeOnlyProperties>
<commitIdGenerationMode>full</commitIdGenerationMode>
</configuration>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/city/norain/slimefun4/SlimefunExtended.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static boolean checkEnvironment(@Nonnull Slimefun sf) {
public static void init(@Nonnull Slimefun sf) {
EnvironmentChecker.scheduleSlimeGlueCheck(sf);

EnvUtil.init(sf);
EnvUtil.init();

checkDebug();

Expand Down
16 changes: 11 additions & 5 deletions src/main/java/city/norain/slimefun4/utils/EnvUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import javax.annotation.Nonnull;
import lombok.experimental.UtilityClass;
import org.bukkit.plugin.Plugin;

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

public void init(@Nonnull Plugin plugin) {
public void init() {
try (var resource = Slimefun.class.getResourceAsStream("/git.properties")) {
var prop = new Properties();
prop.load(resource);
Expand All @@ -23,11 +21,19 @@ public void init(@Nonnull Plugin plugin) {
}
}

private String getProperty(String key) {
return gitInfo == null ? "null" : gitInfo.getProperty(key);
}

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

public String getBuildCommitID() {
return gitInfo == null ? "null" : gitInfo.getProperty("git.commit.id.abbrev");
return getProperty("git.commit.id.abbrev");
}

public String getBranch() {
return getProperty("git.branch");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void onExecute(@Nonnull CommandSender sender, @Nonnull String[] args) {
.color(ChatColor.GREEN)
.append(Slimefun.getVersion()
+ (Slimefun.getVersion().toLowerCase(Locale.ROOT).contains("release")
? " (" + EnvUtil.getBuildCommitID() + ")"
? " (" + EnvUtil.getBuildCommitID() + "@" + EnvUtil.getBranch() + ")"
: "")
+ '\n')
.color(ChatColor.DARK_GREEN)
Expand Down

0 comments on commit 401a59c

Please sign in to comment.