From 6afc6d892665ce30b54b69e918150155e45cd763 Mon Sep 17 00:00:00 2001 From: xhaopan Date: Thu, 5 Jan 2023 20:53:43 +0800 Subject: [PATCH] improve: add auto version number. --- .../org/apache/hadoop/fs/CosNConfigKeys.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/hadoop/fs/CosNConfigKeys.java b/src/main/java/org/apache/hadoop/fs/CosNConfigKeys.java index 1fb922e0..450407d4 100644 --- a/src/main/java/org/apache/hadoop/fs/CosNConfigKeys.java +++ b/src/main/java/org/apache/hadoop/fs/CosNConfigKeys.java @@ -5,6 +5,10 @@ import org.apache.hadoop.fs.cosn.Constants; import org.apache.hadoop.fs.cosn.Unit; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + /** * This class contains constants for configuration keys used in the cos file system. */ @@ -12,7 +16,21 @@ @InterfaceStability.Unstable public class CosNConfigKeys extends CommonConfigurationKeys { public static final String USER_AGENT = "fs.cosn.user.agent"; - public static final String DEFAULT_USER_AGENT = "cos-hadoop-plugin-v8.2.0"; + + private static String version; + + static { + String path = "META-INF/maven/com.qcloud.cos/hadoop-cos/pom.properties"; + Properties properties = new Properties(); + try (InputStream in = CosNConfigKeys.class.getClassLoader().getResourceAsStream(path)) { + properties.load(in); + version = properties.getProperty("version"); + } catch (IOException e) { + version = "unknown"; + } + } + + public static final String DEFAULT_USER_AGENT = "cos-hadoop-plugin-v" + version; public static final String TENCENT_EMR_VERSION_KEY = "fs.emr.version";