|
14 | 14 | package com.amazonaws.encryptionsdk.internal;
|
15 | 15 |
|
16 | 16 | import java.io.IOException;
|
| 17 | +import java.net.URL; |
| 18 | +import java.util.Enumeration; |
17 | 19 | import java.util.Properties;
|
18 | 20 |
|
19 | 21 | /** This class specifies the versioning system for the AWS KMS encryption client. */
|
@@ -43,8 +45,27 @@ public static String versionNumber() {
|
43 | 45 | try {
|
44 | 46 | final Properties properties = new Properties();
|
45 | 47 | final ClassLoader loader = VersionInfo.class.getClassLoader();
|
46 |
| - properties.load(loader.getResourceAsStream("project.properties")); |
47 |
| - return properties.getProperty("version"); |
| 48 | + // Other JARs on the classpath may also define project.properties |
| 49 | + // Enumerate through and find the one for the ESDK |
| 50 | + Enumeration<URL> urls = loader.getResources("project.properties"); |
| 51 | + if (urls == null) { |
| 52 | + return UNKNOWN_VERSION; |
| 53 | + } |
| 54 | + while (urls.hasMoreElements()) { |
| 55 | + URL thisURL = urls.nextElement(); |
| 56 | + if (thisURL.getPath().contains("aws-encryption-sdk-java")) { |
| 57 | + properties.load(thisURL.openStream()); |
| 58 | + break; |
| 59 | + } |
| 60 | + } |
| 61 | + String maybeVersion = properties.getProperty("esdkVersion"); |
| 62 | + if (maybeVersion == null) { |
| 63 | + // This should never happen in practice, |
| 64 | + // but is included for robustness. |
| 65 | + return UNKNOWN_VERSION; |
| 66 | + } else { |
| 67 | + return maybeVersion; |
| 68 | + } |
48 | 69 | } catch (final IOException ex) {
|
49 | 70 | return UNKNOWN_VERSION;
|
50 | 71 | }
|
|
0 commit comments