Skip to content

Commit

Permalink
feat: Suppress the exception log when git.properties doesn't exist (#291
Browse files Browse the repository at this point in the history
)
  • Loading branch information
CH3CHO committed Feb 26, 2024
1 parent 842f7c1 commit eeccc86
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package com.alibaba.higress.console.service;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
Expand Down Expand Up @@ -41,12 +43,7 @@ public class SystemServiceImpl implements SystemService {
static {
String commitId = null;
try {
Properties properties = new Properties();
properties.load(SystemServiceImpl.class.getResourceAsStream("/git.properties"));
commitId = properties.getProperty("git.commit.id");
if (commitId != null && commitId.length() > 7) {
commitId = commitId.substring(0, 7);
}
commitId = loadGitCommitId();
} catch (Exception ex) {
log.error("Failed to load git properties.", ex);
}
Expand Down Expand Up @@ -90,4 +87,20 @@ public void initialize() {
public SystemInfo getSystemInfo() {
return new SystemInfo(fullVersion, capabilities);
}

private static String loadGitCommitId() throws IOException {
try (InputStream input = SystemServiceImpl.class.getResourceAsStream("/git.properties")) {
if (input == null) {
log.warn("git.properties not found.");
return null;
}
Properties properties = new Properties();
properties.load(input);
String commitId = properties.getProperty("git.commit.id");
if (commitId != null && commitId.length() > 7) {
commitId = commitId.substring(0, 7);
}
return commitId;
}
}
}

0 comments on commit eeccc86

Please sign in to comment.