|
7 | 7 | import software.amazon.awssdk.core.ApiName;
|
8 | 8 |
|
9 | 9 | import java.io.IOException;
|
10 |
| -import java.io.InputStream; |
| 10 | +import java.net.URL; |
| 11 | +import java.util.Enumeration; |
11 | 12 | import java.util.Properties;
|
12 | 13 | import java.util.function.Consumer;
|
13 | 14 |
|
@@ -35,15 +36,27 @@ private static String apiVersion() {
|
35 | 36 | final Properties properties = new Properties();
|
36 | 37 | final ClassLoader loader = ApiNameVersion.class.getClassLoader();
|
37 | 38 |
|
38 |
| - final InputStream inputStream = loader.getResourceAsStream("project.properties"); |
39 |
| - // In some cases, e.g. native images, there is no way to load files, |
40 |
| - // and the inputStream returned is null. |
41 |
| - if (inputStream == null) { |
| 39 | + // Other JARs on the classpath may also define project.properties |
| 40 | + // Enumerate through and find the one for S3EC |
| 41 | + Enumeration<URL> urls = loader.getResources("project.properties"); |
| 42 | + if (urls == null) { |
42 | 43 | return API_VERSION_UNKNOWN;
|
43 | 44 | }
|
44 |
| - |
45 |
| - properties.load(inputStream); |
46 |
| - return properties.getProperty("version"); |
| 45 | + while (urls.hasMoreElements()) { |
| 46 | + URL thisURL = urls.nextElement(); |
| 47 | + if (thisURL.getPath().contains("amazon-s3-encryption-client-java")) { |
| 48 | + properties.load(thisURL.openStream()); |
| 49 | + break; |
| 50 | + } |
| 51 | + } |
| 52 | + String maybeVersion = properties.getProperty("s3ecVersion"); |
| 53 | + if (maybeVersion == null) { |
| 54 | + // This should never happen in practice, |
| 55 | + // but is included for robustness. |
| 56 | + return API_VERSION_UNKNOWN; |
| 57 | + } else { |
| 58 | + return maybeVersion; |
| 59 | + } |
47 | 60 | } catch (final IOException ex) {
|
48 | 61 | return API_VERSION_UNKNOWN;
|
49 | 62 | }
|
|
0 commit comments