Standardize optional/excludable dependency checks

Description

There are a number of places where we check for the presence of libraries at runtime. The generic pattern is:

This is either because the dependency is optional, or because we want to allow users to exclude them if they don't use the corresponding feature.

A quick search yields the following use cases:

  • fail if compression is enabled without adding the corresponding optional library (Lz4Compressor and SnappyCompressor)

  • don't register geo codecs if ESRI is excluded (DefaultDriverContext.buildCodecRegistry())

  • don't register graph and reactive requests if the corresponding libraries are excluded (DefaultDriverContext.buildRequestProcessorRegistry(), RequestProcessorRegistry.defaultCqlProcessors())

  • don't start Insights if the "modern" Jackson dependencies are excluded (DefaultDriverContext.buildLifeCycleListeners())

  • fall back to non-native alternatives if JNR libraries are excluded (Native)

We could extract the pattern into a nice enum:

With methods such as isPresent(), failIfAbsent(String errorMessage)... (to be refined)

That would also be a good opportunity to standardize on:

  • exceptions: ClassNotFoundException vs NoClassDefFoundError vs LinkageError?

  • error messages

  • log levels. WARN feels a bit too high, maybe INFO would be sufficient since excluding unneeded dependencies is a normal thing.

Environment

None

Pull Requests

None

Status

Assignee

Unassigned

Reporter

Olivier Michallat

Labels

None

PM Priority

None

Reproduced in

None

Affects versions

None

Fix versions

Pull Request

None

Doc Impact

None

Size

None

External issue ID

None

External issue ID

None

External issue ID

None

External issue ID

None

External issue ID

None

External issue ID

None

Priority

Minor
Configure