Top Description Constructors Methods
org.junit.platform.commons.support

public Class ResourceSupport

extends Object
Class Inheritance
Annotations
@API
status:MAINTAINED
since:1.14
Static Imports
org.apiguardian.api.API.Status.MAINTAINED

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
AnnotationSupport, ClassSupport, ModifierSupport, ReflectionSupport

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static List<Resource>

Returns:

an immutable list of all such resources found; never null but potentially empty
findAllResourcesInClasspathRoot
(URI
the URI for the classpath root in which to scan; never null
root
,
ResourceFilter
the resource type filter; never null
resourceFilter
)

Find all resources in the supplied classpath root that match the specified resourceFilter.

public static List<Resource>

Returns:

an immutable list of all such resources found; never null but potentially empty
findAllResourcesInModule
(String
the name of the module to scan; never null or empty
moduleName
,
ResourceFilter
the resource type filter; never null
resourceFilter
)

Find all resources in the supplied moduleName that match the specified resourceFilter.

public static List<Resource>

Returns:

an immutable list of all such classes found; never null but potentially empty
findAllResourcesInPackage
(String
the name of the base package in which to start scanning; must not be null and must be valid in terms of Java syntax
basePackageName
,
ResourceFilter
the resource type filter; never null
resourceFilter
)

Find all resources in the supplied basePackageName that match the specified resourceFilter.

public static Stream<Resource>

Returns:

a stream of all such classes found; never null but potentially empty
streamAllResourcesInClasspathRoot
(URI
the URI for the classpath root in which to scan; never null
root
,
ResourceFilter
the resource type filter; never null
resourceFilter
)

Find all resources in the supplied classpath root that match the specified resourceFilter.

public static Stream<Resource>

Returns:

a stream of all such resources found; never null but potentially empty
streamAllResourcesInModule
(String
the name of the module to scan; never null or empty
moduleName
,
ResourceFilter
the resource type filter; never null
resourceFilter
)

Find all resources in the supplied moduleName that match the specified resourceFilter.

public static Stream<Resource>

Returns:

a stream of all such resources found; never null but potentially empty
streamAllResourcesInPackage
(String
the name of the base package in which to start scanning; must not be null and must be valid in terms of Java syntax
basePackageName
,
ResourceFilter
the resource type filter; never null
resourceFilter
)

Find all resources in the supplied basePackageName that match the specified resourceFilter.

public static Try<Set<Resource>>

Returns:

a successful Try containing the set of loaded resources (potentially empty) or a failed Try containing the exception in case a failure occurred while trying to list resources; never null
tryToGetResources
(String
the name of the resource to load; never null or blank
classpathResourceName
)

Try to get the resources for the supplied classpath resource name.

public static Try<Set<Resource>>

Returns:

a successful Try containing the set of loaded resources (potentially empty) or a failed Try containing the exception in case a failure occurred while trying to list resources; never null
tryToGetResources
(String
the name of the resource to load; never null or blank
classpathResourceName
,
ClassLoader
the ClassLoader to use; never null
classLoader
)

Try to load the resources for the supplied classpath resource name, using the supplied ClassLoader.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ResourceSupportback to summary
private ResourceSupport()

Method Detail

findAllResourcesInClasspathRootback to summary
public static List<Resource> findAllResourcesInClasspathRoot(URI root, ResourceFilter resourceFilter)

Find all resources in the supplied classpath root that match the specified resourceFilter.

The classpath scanning algorithm searches recursively in subpackages beginning with the root of the classpath.

Parameters
root:URI

the URI for the classpath root in which to scan; never null

resourceFilter:ResourceFilter

the resource type filter; never null

Returns:List<Resource>

an immutable list of all such resources found; never null but potentially empty

See Also
findAllResourcesInPackage(String, ResourceFilter), findAllResourcesInModule(String, ResourceFilter), ReflectionSupport#findAllClassesInClasspathRoot(URI, Predicate, Predicate)
findAllResourcesInModuleback to summary
public static List<Resource> findAllResourcesInModule(String moduleName, ResourceFilter resourceFilter)

Find all resources in the supplied moduleName that match the specified resourceFilter.

The module-path scanning algorithm searches recursively in all packages contained in the module.

Parameters
moduleName:String

the name of the module to scan; never null or empty

resourceFilter:ResourceFilter

the resource type filter; never null

Returns:List<Resource>

an immutable list of all such resources found; never null but potentially empty

See Also
findAllResourcesInClasspathRoot(URI, ResourceFilter), findAllResourcesInPackage(String, ResourceFilter), ReflectionSupport#findAllClassesInModule(String, Predicate, Predicate)
findAllResourcesInPackageback to summary
public static List<Resource> findAllResourcesInPackage(String basePackageName, ResourceFilter resourceFilter)

Find all resources in the supplied basePackageName that match the specified resourceFilter.

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:String

the name of the base package in which to start scanning; must not be null and must be valid in terms of Java syntax

resourceFilter:ResourceFilter

the resource type filter; never null

Returns:List<Resource>

an immutable list of all such classes found; never null but potentially empty

See Also
findAllResourcesInClasspathRoot(URI, ResourceFilter), findAllResourcesInModule(String, ResourceFilter), ReflectionSupport#findAllClassesInPackage(String, Predicate, Predicate)
streamAllResourcesInClasspathRootback to summary
public static Stream<Resource> streamAllResourcesInClasspathRoot(URI root, ResourceFilter resourceFilter)

Find all resources in the supplied classpath root that match the specified resourceFilter.

The classpath scanning algorithm searches recursively in subpackages beginning with the root of the classpath.

Parameters
root:URI

the URI for the classpath root in which to scan; never null

resourceFilter:ResourceFilter

the resource type filter; never null

Returns:Stream<Resource>

a stream of all such classes found; never null but potentially empty

See Also
streamAllResourcesInPackage(String, ResourceFilter), streamAllResourcesInModule(String, ResourceFilter), ReflectionSupport#streamAllClassesInClasspathRoot(URI, Predicate, Predicate)
streamAllResourcesInModuleback to summary
public static Stream<Resource> streamAllResourcesInModule(String moduleName, ResourceFilter resourceFilter)

Find all resources in the supplied moduleName that match the specified resourceFilter.

The module-path scanning algorithm searches recursively in all packages contained in the module.

Parameters
moduleName:String

the name of the module to scan; never null or empty

resourceFilter:ResourceFilter

the resource type filter; never null

Returns:Stream<Resource>

a stream of all such resources found; never null but potentially empty

See Also
streamAllResourcesInClasspathRoot(URI, ResourceFilter), streamAllResourcesInPackage(String, ResourceFilter), ReflectionSupport#streamAllClassesInModule(String, Predicate, Predicate)
streamAllResourcesInPackageback to summary
public static Stream<Resource> streamAllResourcesInPackage(String basePackageName, ResourceFilter resourceFilter)

Find all resources in the supplied basePackageName that match the specified resourceFilter.

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:String

the name of the base package in which to start scanning; must not be null and must be valid in terms of Java syntax

resourceFilter:ResourceFilter

the resource type filter; never null

Returns:Stream<Resource>

a stream of all such resources found; never null but potentially empty

See Also
streamAllResourcesInClasspathRoot(URI, ResourceFilter), streamAllResourcesInModule(String, ResourceFilter), ReflectionSupport#streamAllClassesInPackage(String, Predicate, Predicate)
tryToGetResourcesback to summary
public static Try<Set<Resource>> tryToGetResources(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:String

the name of the resource to load; never null or blank

Returns:Try<Set<Resource>>

a successful Try containing the set of loaded resources (potentially empty) or a failed Try containing the exception in case a failure occurred while trying to list resources; never null

See Also
tryToGetResources(String, ClassLoader), ReflectionSupport#tryToLoadClass(String)
tryToGetResourcesback to summary
public static Try<Set<Resource>> tryToGetResources(String classpathResourceName, ClassLoader classLoader)

Try to load the resources for the supplied classpath resource name, using the supplied ClassLoader.

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:String

the name of the resource to load; never null or blank

classLoader:ClassLoader

the ClassLoader to use; never null

Returns:Try<Set<Resource>>

a successful Try containing the set of loaded resources (potentially empty) or a failed Try containing the exception in case a failure occurred while trying to list resources; never null

See Also
tryToGetResources(String), ReflectionSupport#tryToLoadClass(String, ClassLoader)