com.aliyun.openservices.log.util.VersionInfoUtils Maven / Gradle / Ivy
package com.aliyun.openservices.log.util;
import java.io.InputStream;
import java.util.Properties;
/**
* Unit test for VersionInfo.
*/
public class VersionInfoUtils {
private static final String VERSION_INFO_FILE = "versioninfo.properties";
private static final String USER_AGENT_PREFIX = "aliyun-log-sdk-java";
private static String version = null;
private static String defaultUserAgent = null;
public static String getVersion() {
if (version == null) {
initializeVersion();
}
return version;
}
public static String getDefaultUserAgent() {
if (defaultUserAgent == null) {
String version = null;
// note packageVersion not available in unittest
Package pkg = VersionInfoUtils.class.getPackage();
if (pkg != null) {
version = pkg.getImplementationVersion();
}
if (version == null) {
version = getVersion();
}
defaultUserAgent = USER_AGENT_PREFIX + "-" + version + "/" + System.getProperty("java.version");
}
return defaultUserAgent;
}
private static void initializeVersion() {
InputStream inputStream = VersionInfoUtils.class.getClassLoader().getResourceAsStream(VERSION_INFO_FILE);
Properties versionInfoProperties = new Properties();
try {
if (inputStream == null) {
throw new IllegalArgumentException(VERSION_INFO_FILE + " not found on classpath");
}
versionInfoProperties.load(inputStream);
version = versionInfoProperties.getProperty("version");
} catch (Exception e) {
version = "unknown-version";
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy