[Core] Add property to select io.cucumber.core.backend.ObjectFactory implementation #1700
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
It is now possible to provide a custom ObjectFactory implementation that implements the new interface
io.cucumber.core.backend.ObjectFactory
.Details
With the change of applying a ServiceLoader to load the ObjectFactory it was not possible to create a custom ObjectFactory of type
io.cucumber.core.backend.ObjectFactory
. The disambiguation between the default factories (loaded through the ServiceLoader) and the custom implementation was only possible usingcucumber.properties
and by implementing a custom factory of typecucumber.api.java.ObjectFactory
.With this PR it is possible to use a custom ObjectFactory of the deprecated type
cucumber.api.java.ObjectFactory
. The class name of the type has to be specified in thecucumber.properties
file, e.g.:The mechanism is the same as before. At first a ServiceLoader will be asked to load the implementation. When it cannot find the service, reflection is being used to load the implementation from the classpath.
This is very similar as the previous behaviour. But is now also possible to provide a custom ObjectFactory of type
io.cucumber.core.backend.ObjectFactory
. In that case a disambiguation (from the default object factory) needs to be done incucumber.properties
in the following way:This one will also be tried to be loaded through a ServiceLoader first and then via reflection.
When both specifications occur in
cucumber.properties
the newcucumber.object-factory
setting has priority. When no specifications occur, the default object factory will be loaded.How Has This Been Tested?
I rpovided a few unit tests and beside that tested the behaviour in its various configurations together with our local project.
Types of changes
Checklist: