Przeglądaj źródła

remove hard coded version

jianghua 4 lat temu
rodzic
commit
d6fe49ccff

+ 6 - 0
pom.xml

@@ -231,6 +231,12 @@
     </profiles>
 
     <build>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
         <extensions>
             <extension>
                 <groupId>kr.motd.maven</groupId>

+ 27 - 3
src/main/java/io/milvus/client/MilvusClient.java

@@ -20,15 +20,39 @@
 package io.milvus.client;
 
 import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.List;
+import java.util.Properties;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Supplier;
 
 /** The Milvus Client Interface */
 public interface MilvusClient {
 
-  String clientVersion = "0.8.4";
-
-  /** @return current Milvus client version: 0.8.4 */
+  String clientVersion = new Supplier<String>() {
+    @Override
+    public String get() {
+      Properties properties = new Properties();
+      InputStream inputStream = MilvusClient.class
+          .getClassLoader().getResourceAsStream("milvus-client.properties");
+      try {
+        properties.load(inputStream);
+      } catch (IOException ex) {
+        ExceptionUtils.wrapAndThrow(ex);
+      } finally {
+        try {
+          inputStream.close();
+        } catch (IOException ex) {
+        }
+      }
+      return properties.getProperty("version");
+    }
+  }.get();
+
+  /** @return current Milvus client version */
   default String getClientVersion() {
     return clientVersion;
   }

+ 3 - 0
src/main/resources/milvus-client.properties

@@ -0,0 +1,3 @@
+groupId=${project.groupId}
+artifactId=${project.artifactId}
+version=${project.version}