forked from StarRocks/starrocks-connector-for-apache-flink
-
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.
[Feature] use git-commit-id-plugin to get git information at runtime (S…
…tarRocks#213) [Feature] use git-commit-id-plugin to get git information at runtime Signed-off-by: PengFei Li <lpengfei2016@gmail.com>
- Loading branch information
Showing
8 changed files
with
139 additions
and
34 deletions.
There are no files selected for viewing
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
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
99 changes: 99 additions & 0 deletions
99
src/main/java/com/starrocks/connector/flink/tools/EnvUtils.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,99 @@ | ||
package com.starrocks.connector.flink.tools; | ||
|
||
import org.apache.flink.runtime.util.EnvironmentInformation; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
public class EnvUtils { | ||
|
||
private static class SRFCPropertiesHolder { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(SRFCPropertiesHolder.class); | ||
private static final Properties instance = loadProperties(); | ||
public static Properties loadProperties() { | ||
Properties props = new Properties(); | ||
try { | ||
props.load(SRFCPropertiesHolder.class.getClassLoader().getResourceAsStream("srfc.properties")); | ||
} catch (IOException e) { | ||
logger.warn("load srfc properties failed.", e); | ||
} | ||
return props; | ||
} | ||
} | ||
|
||
public static String getSRFCVersion() { | ||
return SRFCPropertiesHolder.instance.getProperty("srfc.version", ""); | ||
} | ||
|
||
private static final class GitInformation { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(GitInformation.class); | ||
private static final String PROP_FILE = "starrocks-connector-git.properties"; | ||
private static final String UNKNOWN = "unknown"; | ||
|
||
private static final GitInformation INSTANCE = new GitInformation(); | ||
|
||
private String gitBuildTime = UNKNOWN; | ||
private String gitCommitId = UNKNOWN; | ||
private String gitCommitIdAbbrev = UNKNOWN; | ||
private String gitCommitTime = UNKNOWN; | ||
|
||
private String getProperty(Properties properties, String key, String defaultValue) { | ||
String value = properties.getProperty(key); | ||
if (value == null || value.charAt(0) == '$') { | ||
return defaultValue; | ||
} | ||
return value; | ||
} | ||
|
||
public GitInformation() { | ||
ClassLoader classLoader = EnvironmentInformation.class.getClassLoader(); | ||
try (InputStream propFile = classLoader.getResourceAsStream(PROP_FILE)) { | ||
if (propFile != null) { | ||
Properties properties = new Properties(); | ||
properties.load(propFile); | ||
gitBuildTime = getProperty(properties, "git.build.time", UNKNOWN); | ||
gitCommitId = getProperty(properties, "git.commit.id", UNKNOWN); | ||
gitCommitIdAbbrev = getProperty(properties, "git.commit.id.abbrev", UNKNOWN); | ||
gitCommitTime = getProperty(properties, "git.commit.time", UNKNOWN); | ||
} | ||
} catch (Exception e) { | ||
LOG.warn("Can't load git information, exception message: {}", e.getMessage()); | ||
} | ||
} | ||
|
||
public String getGitBuildTime() { | ||
return gitBuildTime; | ||
} | ||
|
||
public String getGitCommitId() { | ||
return gitCommitId; | ||
} | ||
|
||
public String getGitCommitIdAbbrev() { | ||
return gitCommitIdAbbrev; | ||
} | ||
|
||
public String getGitCommitTime() { | ||
return gitCommitTime; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "GitInformation{" + | ||
"gitBuildTime='" + gitBuildTime + '\'' + | ||
", gitCommitId='" + gitCommitId + '\'' + | ||
", gitCommitIdAbbrev='" + gitCommitIdAbbrev + '\'' + | ||
", gitCommitTime='" + gitCommitTime + '\'' + | ||
'}'; | ||
} | ||
} | ||
|
||
public static GitInformation getGitInformation() { | ||
return GitInformation.INSTANCE; | ||
} | ||
} |
29 changes: 0 additions & 29 deletions
29
src/main/java/com/starrocks/connector/flink/tools/SRFCUtils.java
This file was deleted.
Oops, something went wrong.