Skip to content

Commit ae1d6ad

Browse files
committed
chore: guard against properties conflicts
1 parent 6d45ec5 commit ae1d6ad

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

src/main/java/software/amazon/encryption/s3/internal/ApiNameVersion.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import software.amazon.awssdk.core.ApiName;
88

99
import java.io.IOException;
10-
import java.io.InputStream;
10+
import java.net.URL;
11+
import java.util.Enumeration;
1112
import java.util.Properties;
1213
import java.util.function.Consumer;
1314

@@ -35,15 +36,27 @@ private static String apiVersion() {
3536
final Properties properties = new Properties();
3637
final ClassLoader loader = ApiNameVersion.class.getClassLoader();
3738

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) {
4243
return API_VERSION_UNKNOWN;
4344
}
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+
}
4760
} catch (final IOException ex) {
4861
return API_VERSION_UNKNOWN;
4962
}

src/main/resources/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=${project.version}
1+
s3ecVersion=${project.version}

0 commit comments

Comments
 (0)