Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import software.amazon.awssdk.core.ApiName;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Properties;
import java.util.function.Consumer;

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

final InputStream inputStream = loader.getResourceAsStream("project.properties");
// In some cases, e.g. native images, there is no way to load files,
// and the inputStream returned is null.
if (inputStream == null) {
// Other JARs on the classpath may also define project.properties
// Enumerate through and find the one for S3EC
Enumeration<URL> urls = loader.getResources("project.properties");
if (urls == null) {
return API_VERSION_UNKNOWN;
}

properties.load(inputStream);
return properties.getProperty("version");
while (urls.hasMoreElements()) {
URL thisURL = urls.nextElement();
if (thisURL.getPath().contains("amazon-s3-encryption-client-java")) {
properties.load(thisURL.openStream());
break;
}
}
String maybeVersion = properties.getProperty("s3ecVersion");
if (maybeVersion == null) {
// This should never happen in practice,
// but is included for robustness.
return API_VERSION_UNKNOWN;
} else {
return maybeVersion;
}
} catch (final IOException ex) {
return API_VERSION_UNKNOWN;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/project.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=${project.version}
s3ecVersion=${project.version}