10
10
11
11
package org .junit .platform .commons .support .scanning ;
12
12
13
+ import static org .apiguardian .api .API .Status .DEPRECATED ;
13
14
import static org .apiguardian .api .API .Status .MAINTAINED ;
14
15
15
16
import java .net .URI ;
16
17
import java .util .List ;
18
+ import java .util .function .Predicate ;
17
19
18
20
import org .apiguardian .api .API ;
19
21
import org .junit .platform .commons .io .Resource ;
@@ -62,6 +64,55 @@ public interface ClasspathScanner {
62
64
*/
63
65
List <Class <?>> scanForClassesInClasspathRoot (URI root , ClassFilter classFilter );
64
66
67
+ /**
68
+ * Find all {@linkplain org.junit.platform.commons.support.Resource resources} in the supplied classpath {@code root}
69
+ * that match the specified {@code resourceFilter} predicate.
70
+ *
71
+ * <p>The classpath scanning algorithm searches recursively in subpackages
72
+ * beginning with the root of the classpath.
73
+ *
74
+ * @param basePackageName the name of the base package in which to start
75
+ * scanning; must not be {@code null} and must be valid in terms of Java
76
+ * syntax
77
+ * @param resourceFilter the resource type filter; never {@code null}
78
+ * @return a list of all such resources found; never {@code null}
79
+ * but potentially empty
80
+ * @deprecated Please implement
81
+ * {@link #scanForResourcesInPackage(String, ResourceFilter)} instead
82
+ */
83
+ @ API (status = DEPRECATED , since = "6.0" )
84
+ @ Deprecated (since = "6.0" , forRemoval = true )
85
+ @ SuppressWarnings ({ "removal" , "unused" })
86
+ default List <org .junit .platform .commons .support .Resource > scanForResourcesInPackage (String basePackageName ,
87
+ Predicate <org .junit .platform .commons .support .Resource > resourceFilter ) {
88
+ throw new UnsupportedOperationException ("Implement scanForResourcesInPackage(String, ResourceFilter) instead" );
89
+ }
90
+
91
+ /**
92
+ * Find all {@linkplain org.junit.platform.commons.support.Resource resources} in the supplied classpath {@code root}
93
+ * that match the specified {@code resourceFilter} predicate.
94
+ *
95
+ * <p>The classpath scanning algorithm searches recursively in subpackages
96
+ * beginning with the root of the classpath.
97
+ *
98
+ * @param root the URI for the classpath root in which to scan; never
99
+ * {@code null}
100
+ * @param resourceFilter the resource type filter; never {@code null}
101
+ * @return a list of all such resources found; never {@code null}
102
+ * but potentially empty
103
+ * @deprecated Please implement
104
+ * {@link #scanForResourcesInClasspathRoot(URI, ResourceFilter)} instead
105
+ */
106
+ @ API (status = DEPRECATED , since = "6.0" )
107
+ @ Deprecated (since = "6.0" , forRemoval = true )
108
+ @ SuppressWarnings ("removal" )
109
+ default List <org .junit .platform .commons .support .Resource > scanForResourcesInClasspathRoot (URI root ,
110
+ Predicate <org .junit .platform .commons .support .Resource > resourceFilter ) {
111
+ throw new UnsupportedOperationException (
112
+ "Implement scanForResourcesInClasspathRoot(URI, ResourceFilter) instead" );
113
+
114
+ }
115
+
65
116
/**
66
117
* Find all {@linkplain Resource resources} in the supplied classpath {@code root}
67
118
* that match the specified {@code resourceFilter} predicate.
@@ -78,7 +129,12 @@ public interface ClasspathScanner {
78
129
* @since 6.0
79
130
*/
80
131
@ API (status = MAINTAINED , since = "6.0" )
81
- List <Resource > scanForResourcesInPackage (String basePackageName , ResourceFilter resourceFilter );
132
+ @ SuppressWarnings ("removal" )
133
+ default List <Resource > scanForResourcesInPackage (String basePackageName , ResourceFilter resourceFilter ) {
134
+ return scanForResourcesInPackage (basePackageName , resource -> resourceFilter .match (oldToNew (resource ))).stream () //
135
+ .map (ClasspathScanner ::oldToNew ) //
136
+ .toList ();
137
+ }
82
138
83
139
/**
84
140
* Find all {@linkplain Resource resources} in the supplied classpath {@code root}
@@ -95,6 +151,16 @@ public interface ClasspathScanner {
95
151
* @since 6.0
96
152
*/
97
153
@ API (status = MAINTAINED , since = "6.0" )
98
- List <Resource > scanForResourcesInClasspathRoot (URI root , ResourceFilter resourceFilter );
154
+ @ SuppressWarnings ("removal" )
155
+ default List <Resource > scanForResourcesInClasspathRoot (URI root , ResourceFilter resourceFilter ) {
156
+ return scanForResourcesInClasspathRoot (root , r -> resourceFilter .match (oldToNew (r ))).stream () //
157
+ .map (ClasspathScanner ::oldToNew ) //
158
+ .toList ();
159
+ }
160
+
161
+ @ SuppressWarnings ("removal" )
162
+ private static Resource oldToNew (org .junit .platform .commons .support .Resource oldResource ) {
163
+ return Resource .of (oldResource .getName (), oldResource .getUri ());
164
+ }
99
165
100
166
}
0 commit comments