forked from didi/KnowStreaming
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request didi#494 from didi/dev
1、打包时自动生成版本信息及git提交信息;2、优化swagger对版本信息的获取;
- Loading branch information
Showing
4 changed files
with
90 additions
and
10 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
...a-manager-common/src/main/java/com/xiaojukeji/kafka/manager/common/utils/GitPropUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.xiaojukeji.kafka.manager.common.utils; | ||
|
||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.Properties; | ||
|
||
public class GitPropUtil { | ||
private static final Logger log = LoggerFactory.getLogger(GitPropUtil.class); | ||
|
||
private static Properties props = null; | ||
|
||
public static final String VERSION_FIELD_NAME = "git.build.version"; | ||
|
||
public static final String COMMIT_ID_FIELD_NAME = "git.commit.id.abbrev"; | ||
|
||
public static String getProps(String fieldName) { | ||
if (props == null) { | ||
props = JsonUtils.stringToObj(readGitPropertiesInJarFile(), Properties.class); | ||
} | ||
|
||
return props.getProperty(fieldName); | ||
} | ||
|
||
public static Properties getProps() { | ||
if (props == null) { | ||
props = JsonUtils.stringToObj(readGitPropertiesInJarFile(), Properties.class); | ||
} | ||
|
||
return props; | ||
} | ||
|
||
private static String readGitPropertiesInJarFile() { | ||
InputStream inputStream = null; | ||
try { | ||
inputStream = GitPropUtil.class.getClassLoader().getResourceAsStream("git.properties"); | ||
|
||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); | ||
String line = null; | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
while ((line = bufferedReader.readLine()) != null) { | ||
sb.append(line).append("\n"); | ||
} | ||
return sb.toString(); | ||
} catch (Exception e) { | ||
log.error("method=readGitPropertiesInJarFile||errMsg=exception.", e); | ||
} finally { | ||
try { | ||
if (inputStream != null) { | ||
inputStream.close(); | ||
} | ||
} catch (Exception e) { | ||
log.error("method=readGitPropertiesInJarFile||msg=close failed||errMsg=exception.", e); | ||
} | ||
} | ||
|
||
return "{}"; | ||
} | ||
|
||
private GitPropUtil() { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters