Class ResourceSupport
- java.lang.Object
-
- org.junit.platform.commons.support.ResourceSupport
-
@API(status=MAINTAINED, since="1.14") public class ResourceSupport extends java.lang.ObjectResourceSupportprovides static utility methods for common tasks dealing with resources; for example, scanning for resources on the class path or module path.TestEngineand 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:
AnnotationSupport,ClassSupport,ModifierSupport,ReflectionSupport
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.List<Resource>findAllResourcesInClasspathRoot(java.net.URI root, ResourceFilter resourceFilter)static java.util.List<Resource>findAllResourcesInModule(java.lang.String moduleName, ResourceFilter resourceFilter)static java.util.List<Resource>findAllResourcesInPackage(java.lang.String basePackageName, ResourceFilter resourceFilter)static java.util.stream.Stream<Resource>streamAllResourcesInClasspathRoot(java.net.URI root, ResourceFilter resourceFilter)static java.util.stream.Stream<Resource>streamAllResourcesInModule(java.lang.String moduleName, ResourceFilter resourceFilter)static java.util.stream.Stream<Resource>streamAllResourcesInPackage(java.lang.String basePackageName, ResourceFilter resourceFilter)static Try<java.util.Set<Resource>>tryToGetResources(java.lang.String classpathResourceName)Try to get the resources for the supplied classpath resource name.static Try<java.util.Set<Resource>>tryToGetResources(java.lang.String classpathResourceName, java.lang.ClassLoader classLoader)Try to load the resources for the supplied classpath resource name, using the suppliedClassLoader.
-
-
-
Method Detail
-
tryToGetResources
public static Try<java.util.Set<Resource>> tryToGetResources(java.lang.String classpathResourceName)
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(String, ClassLoader),ReflectionSupport.tryToLoadClass(String)
-
tryToGetResources
public static Try<java.util.Set<Resource>> tryToGetResources(java.lang.String classpathResourceName, java.lang.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:
tryToGetResources(String),ReflectionSupport.tryToLoadClass(String, ClassLoader)
-
findAllResourcesInClasspathRoot
public static java.util.List<Resource> findAllResourcesInClasspathRoot(java.net.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:
findAllResourcesInPackage(String, ResourceFilter),findAllResourcesInModule(String, ResourceFilter),ReflectionSupport.findAllClassesInClasspathRoot(URI, Predicate, Predicate)
-
streamAllResourcesInClasspathRoot
public static java.util.stream.Stream<Resource> streamAllResourcesInClasspathRoot(java.net.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:
streamAllResourcesInPackage(String, ResourceFilter),streamAllResourcesInModule(String, ResourceFilter),ReflectionSupport.streamAllClassesInClasspathRoot(URI, Predicate, Predicate)
-
findAllResourcesInPackage
public static java.util.List<Resource> findAllResourcesInPackage(java.lang.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:
findAllResourcesInClasspathRoot(URI, ResourceFilter),findAllResourcesInModule(String, ResourceFilter),ReflectionSupport.findAllClassesInPackage(String, Predicate, Predicate)
-
streamAllResourcesInPackage
public static java.util.stream.Stream<Resource> streamAllResourcesInPackage(java.lang.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:
streamAllResourcesInClasspathRoot(URI, ResourceFilter),streamAllResourcesInModule(String, ResourceFilter),ReflectionSupport.streamAllClassesInPackage(String, Predicate, Predicate)
-
findAllResourcesInModule
public static java.util.List<Resource> findAllResourcesInModule(java.lang.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:
findAllResourcesInClasspathRoot(URI, ResourceFilter),findAllResourcesInPackage(String, ResourceFilter),ReflectionSupport.findAllClassesInModule(String, Predicate, Predicate)
-
streamAllResourcesInModule
public static java.util.stream.Stream<Resource> streamAllResourcesInModule(java.lang.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:
streamAllResourcesInClasspathRoot(URI, ResourceFilter),streamAllResourcesInPackage(String, ResourceFilter),ReflectionSupport.streamAllClassesInModule(String, Predicate, Predicate)
-
-