From eeccc8614b9e861de977fed1efe11fedf4c97fe6 Mon Sep 17 00:00:00 2001 From: Kent Dong Date: Mon, 26 Feb 2024 15:15:12 +0800 Subject: [PATCH] feat: Suppress the exception log when git.properties doesn't exist (#291) --- .../console/service/SystemServiceImpl.java | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/backend/console/src/main/java/com/alibaba/higress/console/service/SystemServiceImpl.java b/backend/console/src/main/java/com/alibaba/higress/console/service/SystemServiceImpl.java index 7c84baf2..1b84b928 100644 --- a/backend/console/src/main/java/com/alibaba/higress/console/service/SystemServiceImpl.java +++ b/backend/console/src/main/java/com/alibaba/higress/console/service/SystemServiceImpl.java @@ -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; @@ -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); } @@ -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; + } + } }