-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add possibility to register launcher-discovery listeners via SPI #2457
Add possibility to register launcher-discovery listeners via SPI #2457
Conversation
`LauncherDiscoveryListeners` can now be registered via Java's `ServiceLoader` mechanism in addition to those passed as part of each `LauncherDiscoveryRequest` and the default one.
5a8c228
to
68b2244
Compare
Codecov Report
@@ Coverage Diff @@
## main #2457 +/- ##
============================================
+ Coverage 90.39% 90.41% +0.02%
- Complexity 4572 4584 +12
============================================
Files 399 400 +1
Lines 11292 11324 +32
Branches 909 910 +1
============================================
+ Hits 10207 10239 +32
Misses 808 808
Partials 277 277
Continue to review full report at Codecov.
|
Tentatively slated for 5.8 M1 solely for the purpose of team discussion. |
Just FYI doing something like this allows to have an SPI change the current thread context classloader and actually can help with #201 and #806. I needed to use a different classloader for loading the classes that are discovered and adding my own classloader before the discovery is started is one way to achieve this. I am sure that this is not the only use case for this, and the use case I have does not really fit this, I am sure that there are other more suitable use cases for this. |
if (discoveryListeners.contains(defaultDiscoveryListener)) { | ||
if (discoveryListeners.contains(defaultDiscoveryListener) && serviceLoaderListeners.isEmpty()) { | ||
return LauncherDiscoveryListeners.composite(discoveryListeners); | ||
} | ||
List<LauncherDiscoveryListener> allDiscoveryListeners = new ArrayList<>(discoveryListeners); | ||
allDiscoveryListeners.add(defaultDiscoveryListener); | ||
allDiscoveryListeners.addAll(serviceLoaderListeners); | ||
if (!allDiscoveryListeners.contains(defaultDiscoveryListener)) { | ||
allDiscoveryListeners.add(defaultDiscoveryListener); | ||
} | ||
return LauncherDiscoveryListeners.composite(allDiscoveryListeners); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this optimization is necessary. Let's get rid of the first if
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure no problem, I was not entirely sure about this part as well, it didn't feel quite right anyways. I'll make a small optimisation so that the list is created with a correct size at least (to avoid resizes)
73349b8
to
0973542
Compare
So this would let us stuff like changing the class path for the tests? |
I want to be really clear that the goal of this PR is not to fix the issues that need different classpath for the tests. I don't want the JUnit team to reject this PR solely on the fact of allowing users to change the classloader. However, it indeed allows implementors of this interface to change the current thread context classloader in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Could you please add this to the user guide and release notes as well?
...launcher/src/main/java/org/junit/platform/launcher/core/LauncherDiscoveryRequestBuilder.java
Outdated
Show resolved
Hide resolved
Thanks. I just pushed the update to the user guide and release notes. One thing that I just remembered. What would you like the default flag to be set to. Currently discovering |
Team decision: Let's include this feature in 5.8. |
Whether discovery listeners are picked up via ServiceLoader is now configurable via `LauncherConfig` for consistency with all other APIs potentially loaded that way. Moreover, discovery listeners are now registered via ServiceLoader by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@filiphr I took the liberty of reworking a few parts based on your implementation. I hope you don't mind!
Really appreciated @marcphilipp. Thanks for the work on it. One small comment though, I think that you missed a |
junit-platform-launcher/src/main/java/org/junit/platform/launcher/core/LauncherConfig.java
Show resolved
Hide resolved
994d405
to
95b2cad
Compare
That's great news @marcphilipp. Looking forward in using this and finalising the migration to JUnit 5 in the MapStruct project. |
LauncherDiscoveryListeners
can now be registered via Java'sServiceLoader
mechanism in addition to those
passed as part of each
LauncherDiscoveryRequest
and the default one.Overview
The idea of this PR is to enable registering
LauncherDiscoveryListener
through an SPI. I am creating this PR in order to hear the opinion of the JUnit Team. Is something like this acceptable for you? If it is I am going to add add the documentation and finish whatever needs to be finished from your feedback.I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@API
annotations