|
19 | 19 |
|
20 | 20 | package co.elastic.clients.base;
|
21 | 21 |
|
| 22 | +import java.io.IOException; |
| 23 | +import java.io.InputStream; |
22 | 24 | import java.util.Collections;
|
23 | 25 | import java.util.Map;
|
| 26 | +import java.util.Properties; |
24 | 27 |
|
25 | 28 | /**
|
26 | 29 | * Models a user agent, consisting of a name, version,
|
27 | 30 | * and optional key-value metadata.
|
28 | 31 | */
|
29 | 32 | public class UserAgent {
|
30 | 33 |
|
31 |
| - // TODO: move this to a resource file |
32 | 34 | static final String DEFAULT_NAME = "elasticsearch-java";
|
33 | 35 |
|
34 |
| - // TODO: move this to a resource file |
35 |
| - static final String DEFAULT_VERSION = "1.2.3"; |
| 36 | + // The client version is loaded from the 'version.properties' file |
| 37 | + static final String DEFAULT_VERSION; |
| 38 | + static { |
| 39 | + InputStream in = UserAgent.class.getResourceAsStream("/co.elastic.clients.elasticsearch/version.properties"); |
| 40 | + if (in != null) { |
| 41 | + Properties prop = new Properties(); |
| 42 | + String version; |
| 43 | + try { |
| 44 | + prop.load(in); |
| 45 | + version = prop.getProperty("version", "?"); |
| 46 | + } catch (IOException e) { |
| 47 | + // Unable to read properties file |
| 48 | + version = "?"; |
| 49 | + } |
| 50 | + DEFAULT_VERSION = version; |
| 51 | + } |
| 52 | + else { |
| 53 | + // Unable to locate properties file |
| 54 | + DEFAULT_VERSION = "?"; |
| 55 | + } |
| 56 | + // TODO: log error if DEFAULT_VERSION now equals "?" |
| 57 | + } |
36 | 58 |
|
37 | 59 | // Default user agent, constructed from default repo name and version
|
38 | 60 | public static final UserAgent DEFAULT = new UserAgent(DEFAULT_NAME, DEFAULT_VERSION);
|
|
0 commit comments