-
-
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
Support scanning for classpath resources #3630
Comments
We never implemented that, because we never needed to scan for resources (other than What's the concrete use case you're thinking of -- scanning for Cucumber files or similar? |
Yup. Cucumber uses The benefits would be two-fold
|
interface Resource {
URI getUri();
default InputStream getInputStream() throws IOException {
return getUri().toURL().openStream();
}
} |
Team decision: Let's add the two extra methods to As a follow-up task, we should add an |
@mpkorstanje A PR would be most welcome! 🙂 |
Cheers. I'll give it a shot.
Oh that would be really nice! |
I am still working on this, unfortunately due to circumstances it is going a bit slower than usual. |
Thanks for letting us know, @mpkorstanje. This is currently assigned to the 5.11 M2 milestone, so you've got a bit more time. |
As a follow up for junit-team#3630 and junit-team#3705 this adds a `addResourceContainerSelectorResolver()` method to `EngineDiscoveryRequestResolver.Builder` analogous to `addClassContainerSelectorResolver()`. Points of note: * As classpath resources can be selected from packages, the package filter should also be applied. To make this possible the base path of a resource is rewritten to a package name prior to being filtered. * The `ClasspathResourceSelector` now has a `getClasspathResource` method. This method will lazily try to load the resource if not was not already provided when discovering resources in a container. * `selectClasspathResource(Resource)` was added to short circuit the need to resolve resources twice. And to make it possible to use this method as part of the public API, `ReflectionSupport.tryToLoadResource` was also added.
As a follow up for #3630 and #3705 this adds a `addResourceContainerSelectorResolver()` method to `EngineDiscoveryRequestResolver.Builder` analogous to `addClassContainerSelectorResolver()`. Points of note: * As classpath resources can be selected from packages, the package filter should also be applied. To make this possible the base path of a resource is rewritten to a package name prior to being filtered. * The `ClasspathResourceSelector` now has a `getClasspathResources` method. This method will lazily try to load the resources if not already provided when discovering resources in a container. * `selectClasspathResource(Resource)` was added to short circuit the need to resolve resources twice. And to make it possible to use this method as part of the public API, `ReflectionSupport.tryToLoadResource` was also added. --------- Co-authored-by: Marc Philipp <[email protected]>
Currently
ReflectionUtils
supports resolving class based selectors such asPackageSelector
andClasspathRootSelector
. These can be resolved usingfindAllClassesInPackage
andfindAllClassesInClasspathRoot
respectively.Unfortunately there are no resource based equivalents to help resolve resources contained in a class path directory targeted by a
ClasspathResourceSelector
orClasspathRootSelector
e.g:As this functionality is backed by the
ClasspathScanner
I believe it would be prudent to add this functionality prior to making theClasspathScanner
part of the public API as proposed in #3628. This would avoid breaking changes by adding more methods to an interface, or potential bug reports caused by a default implementation that always returns an empty collection of resources.And I would be happy to provide a PR that facilitates this.
Deliverables
ReflectionUtils
andClasspathScanner
.The text was updated successfully, but these errors were encountered: