Provide GraalVM metadata and substitutions
I recommend reviewing the first four commits in this PR one at a time, as they are logically independent and don't conflict with each other.
- Moved
native-image.propertiestosrc/main/resources/META-INF/native-image/native-image.properties. Note how now they are immediately under thenative-imagefolder. - Ensured that
MongoClientuses customcom.mongodb.spi.dns.DnsClientProviders in GraalVM viaServiceLoader. - Moved driver-specific reachability metadata from
:graalvm-native-image-appinto the relevant driver JARs. - Introduced GraalVM substitutions based on
MongoClientSubstitutionsin Quarkus. The introduced substitutions achieve the following: 4.1. Assert that substitutions are indeed used viaSubstitutions.assertUsed, which is called fromNativeImageApp. 4.2. Explicitly throw at run time ifUnixServerAddressis used. It allegedly does not work with GraalVM, we'll figure this out (or not) in JAVA-5400. 4.2. ~~Explicitly throw at run time if the Snappy compressor is used. I don't know why it allegedly does not work with GraalVM, we'll figure this out in JAVA-5383.~~
Note that I omitted some of Quarkus substitutions for various reasons:
- ~~We should not substitute
ConnectionString.buildCompressorssuch that it ignores the Snappy compressor. This method callsMongoCompressor.createSnappyCompressor, which is substituted and throws an exception. Throwing an exception should be our reaction to the Snappy compressor in all scenarios.~~ - ~~We should not substitute
InternalStreamConnection.createCompressor, as it can never be requested to create a Snappy compressor given thatMongoCompressor.createSnappyCompressoris substituted and throws in GraalVM native image. Moreover, the Quarkus substitution makes it always throw, thus breaking all compressors in GraalVM.~~ - There is no need for substitutions related to Snappy compression because it works in GraalVM, provided that the corresponding reachability metadata and dependency is present. We'll add that metadata to our JARs in JAVA-5383.
- There is no need for an alias for
UnixServerAddress. - Instead of having multiple substitutions related to
UnixServerAddress: a substititution forSocketStreamFactory.create, a deletion ofUnixSocketChannelStream, a substitution forServerAddressHelper.createServerAddress, we can substitute only the constructor ofUnixServerAddresssuch that it throws. - We should not have a substitution for
com.sun.jna.Native.getWebStartLibraryPath.
JAVA-5219
Hi, @cescoffier. I am unable to add you as a reviewer of this PR, but your review may be helpful. I am inviting you to take a look at this PR if you have time.
LGTM except for the one that requires waiting for the next mongodb-crypt release.
Converted to Draft PR while we await the mongodb-crypt release.
FYI @stIncMale the mongodb-crypt release has been completed.