Class ResourceSupport
ResourceSupport provides static utility methods for common tasks
dealing with resources; for example, scanning for resources on the class path
or module path.
TestEngine and extension
authors are encouraged to use these supported methods in order to align with
the behavior of the JUnit Platform.
- Since:
- 1.14
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionfindAllResourcesInClasspathRoot(URI root, ResourceFilter resourceFilter) findAllResourcesInModule(String moduleName, ResourceFilter resourceFilter) findAllResourcesInPackage(String basePackageName, ResourceFilter resourceFilter) streamAllResourcesInClasspathRoot(URI root, ResourceFilter resourceFilter) streamAllResourcesInModule(String moduleName, ResourceFilter resourceFilter) streamAllResourcesInPackage(String basePackageName, ResourceFilter resourceFilter) tryToGetResources(String classpathResourceName) Try to get the resources for the supplied classpath resource name.tryToGetResources(String classpathResourceName, ClassLoader classLoader) Try to load the resources for the supplied classpath resource name, using the suppliedClassLoader.
-
Method Details
-
tryToGetResources
Try to get the resources for the supplied classpath resource name.The name of a classpath resource must follow the semantics for resource paths as defined in
ClassLoader.getResource(String).If the supplied classpath resource name is prefixed with a slash (
/), the slash will be removed.- Parameters:
classpathResourceName- the name of the resource to load; nevernullor blank- Returns:
- a successful
Trycontaining the set of loaded resources (potentially empty) or a failedTrycontaining the exception in case a failure occurred while trying to list resources; nevernull - See Also:
-
tryToGetResources
public static Try<Set<Resource>> tryToGetResources(String classpathResourceName, ClassLoader classLoader) Try to load the resources for the supplied classpath resource name, using the suppliedClassLoader.The name of a classpath resource must follow the semantics for resource paths as defined in
ClassLoader.getResource(String).If the supplied classpath resource name is prefixed with a slash (
/), the slash will be removed.- Parameters:
classpathResourceName- the name of the resource to load; nevernullor blankclassLoader- theClassLoaderto use; nevernull- Returns:
- a successful
Trycontaining the set of loaded resources (potentially empty) or a failedTrycontaining the exception in case a failure occurred while trying to list resources; nevernull - See Also:
-
findAllResourcesInClasspathRoot
public static List<Resource> findAllResourcesInClasspathRoot(URI root, ResourceFilter resourceFilter) Find all resources in the supplied classpathrootthat match the specifiedresourceFilter.The classpath scanning algorithm searches recursively in subpackages beginning with the root of the classpath.
- Parameters:
root- the URI for the classpath root in which to scan; nevernullresourceFilter- the resource type filter; nevernull- Returns:
- an immutable list of all such resources found; never
nullbut potentially empty - See Also:
-
streamAllResourcesInClasspathRoot
public static Stream<Resource> streamAllResourcesInClasspathRoot(URI root, ResourceFilter resourceFilter) Find all resources in the supplied classpathrootthat match the specifiedresourceFilter.The classpath scanning algorithm searches recursively in subpackages beginning with the root of the classpath.
- Parameters:
root- the URI for the classpath root in which to scan; nevernullresourceFilter- the resource type filter; nevernull- Returns:
- a stream of all such classes found; never
nullbut potentially empty - See Also:
-
findAllResourcesInPackage
public static List<Resource> findAllResourcesInPackage(String basePackageName, ResourceFilter resourceFilter) Find all resources in the suppliedbasePackageNamethat match the specifiedresourceFilter.The classpath scanning algorithm searches recursively in subpackages beginning within the supplied base package. The resulting list may include identically named resources from different classpath roots.
- Parameters:
basePackageName- the name of the base package in which to start scanning; must not benulland must be valid in terms of Java syntaxresourceFilter- the resource type filter; nevernull- Returns:
- an immutable list of all such classes found; never
nullbut potentially empty - See Also:
-
streamAllResourcesInPackage
public static Stream<Resource> streamAllResourcesInPackage(String basePackageName, ResourceFilter resourceFilter) Find all resources in the suppliedbasePackageNamethat match the specifiedresourceFilter.The classpath scanning algorithm searches recursively in subpackages beginning within the supplied base package. The resulting stream may include identically named resources from different classpath roots.
- Parameters:
basePackageName- the name of the base package in which to start scanning; must not benulland must be valid in terms of Java syntaxresourceFilter- the resource type filter; nevernull- Returns:
- a stream of all such resources found; never
nullbut potentially empty - See Also:
-
findAllResourcesInModule
public static List<Resource> findAllResourcesInModule(String moduleName, ResourceFilter resourceFilter) Find all resources in the suppliedmoduleNamethat match the specifiedresourceFilter.The module-path scanning algorithm searches recursively in all packages contained in the module.
- Parameters:
moduleName- the name of the module to scan; nevernullor emptyresourceFilter- the resource type filter; nevernull- Returns:
- an immutable list of all such resources found; never
nullbut potentially empty - See Also:
-
streamAllResourcesInModule
public static Stream<Resource> streamAllResourcesInModule(String moduleName, ResourceFilter resourceFilter) Find all resources in the suppliedmoduleNamethat match the specifiedresourceFilter.The module-path scanning algorithm searches recursively in all packages contained in the module.
- Parameters:
moduleName- the name of the module to scan; nevernullor emptyresourceFilter- the resource type filter; nevernull- Returns:
- a stream of all such resources found; never
nullbut potentially empty - See Also:
-