Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Add property to select io.cucumber.core.backend.ObjectFactory implementation #1700

Merged
merged 4 commits into from
Jul 16, 2019
Merged

[Core] Add property to select io.cucumber.core.backend.ObjectFactory implementation #1700

merged 4 commits into from
Jul 16, 2019

Conversation

ralphkar
Copy link
Contributor

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 using cucumber.properties and by implementing a custom factory of type cucumber.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 the cucumber.properties file, e.g.:

cucumber.api.java.ObjectFactory=my.company.CustomDeprecatedObjectFactory

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 in cucumber.propertiesin the following way:

cucumber.object-factory=my.company.CustomObjectFactory

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 new cucumber.object-factorysetting 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

  • [x ] Bug fix (non-breaking change which fixes an issue).
  • New feature (non-breaking change which adds functionality).
  • Breaking change (fix or feature that would cause existing functionality to not work as expected).

Checklist:

  • [ x] I've added tests for my code.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Ralph Kar added 4 commits July 16, 2019 10:13
possible for implementations of the deprecated and the new interface of
ObjectFactory. Implementation can be loaded via a service loader or
through reflection.
@mpkorstanje mpkorstanje changed the title ObjectFactory loading fixed (issue #1691) [Core] Add property to select io.cucumber.core.backend.ObjectFactory implementation Jul 16, 2019
@mpkorstanje mpkorstanje merged commit 28ecd7a into cucumber:master Jul 16, 2019
@aslakhellesoy
Copy link
Contributor

Hi @ralphkar,

Thanks for your making your first contribution to Cucumber, and welcome to the Cucumber committers team! You can now push directly to this repo and all other repos under the cucumber organization! 🍾

In return for this generous offer we hope you will:

  • ✅ Continue to use branches and pull requests. When someone on the core team approves a pull request (yours or someone else's), you're welcome to merge it yourself.
  • 💚 Commit to setting a good example by following and upholding our code of conduct in your interactions with other collaborators and users.
  • 💬 Join the community Slack channel to meet the rest of the team and make yourself at home.
  • ℹ️ Don't feel obliged to help, just do what you can if you have the time and the energy.
  • 🙋 Ask if you need anything. We're looking for feedback about how to make the project more welcoming, so please tell us!

On behalf of the Cucumber core team,
Aslak Hellesøy
Creator of Cucumber

@mpkorstanje
Copy link
Contributor

Cheers!

mpkorstanje added a commit that referenced this pull request Jul 16, 2019
@ralphkar ralphkar deleted the cucumber-jvm-1691 branch July 17, 2019 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants