Skip to content

Commit 4796abc

Browse files
committed
Restore backward compatibility
1 parent 13eb9c2 commit 4796abc

File tree

3 files changed

+77
-8
lines changed

3 files changed

+77
-8
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-6.0.0-RC3.adoc

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,10 @@ JUnit repository on GitHub.
4040
* Deprecate
4141
`EngineDiscoveryRequestResolver.Builder.addResourceContainerSelectorResolver(Predicate)`
4242
method in favor of `addResourceContainerSelectorResolver(ResourceFilter)`.
43-
* Change signature of `scanForResourcesInPackage` and `scanForResourcesInClasspathRoot`
44-
in `org.junit.platform.commons.support.scanning.ClasspathScanner` methods to take a
45-
`ResourceFilter` rather than a
46-
`Predicate<org.junit.platform.commons.support.Resource>` and return
47-
`List<org.junit.platform.commons.io.Resource>` rather than
48-
`List<org.junit.platform.commons.support.Resource>`.
43+
* Deprecate `Resource`-related methods in `ClasspathScanner` in favor of new methods using
44+
`org.junit.platform.commons.io.Resource` and `ResourceFilter`:
45+
- `scanForResourcesInPackage(String, Predicate)`
46+
- `scanForResourcesInClasspathRoot(URI, Predicate)`
4947

5048
[[release-notes-6.0.0-RC3-junit-platform-new-features-and-improvements]]
5149
==== New Features and Improvements

junit-platform-commons/src/main/java/org/junit/platform/commons/support/scanning/ClasspathScanner.java

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010

1111
package org.junit.platform.commons.support.scanning;
1212

13+
import static org.apiguardian.api.API.Status.DEPRECATED;
1314
import static org.apiguardian.api.API.Status.MAINTAINED;
1415

1516
import java.net.URI;
1617
import java.util.List;
18+
import java.util.function.Predicate;
1719

1820
import org.apiguardian.api.API;
1921
import org.junit.platform.commons.io.Resource;
@@ -62,6 +64,55 @@ public interface ClasspathScanner {
6264
*/
6365
List<Class<?>> scanForClassesInClasspathRoot(URI root, ClassFilter classFilter);
6466

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+
65116
/**
66117
* Find all {@linkplain Resource resources} in the supplied classpath {@code root}
67118
* that match the specified {@code resourceFilter} predicate.
@@ -78,7 +129,12 @@ public interface ClasspathScanner {
78129
* @since 6.0
79130
*/
80131
@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+
}
82138

83139
/**
84140
* Find all {@linkplain Resource resources} in the supplied classpath {@code root}
@@ -95,6 +151,16 @@ public interface ClasspathScanner {
95151
* @since 6.0
96152
*/
97153
@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+
}
99165

100166
}

platform-tooling-support-tests/src/archUnit/java/platform/tooling/support/tests/ArchUnitTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.junit.jupiter.api.extension.MediaType;
6666
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
6767
import org.junit.jupiter.params.support.ParameterInfo;
68+
import org.junit.platform.commons.support.scanning.ClasspathScanner;
6869
import org.junit.platform.engine.TestDescriptor;
6970
import org.junit.platform.engine.reporting.OutputDirectoryProvider;
7071

@@ -153,13 +154,17 @@ void freeOfGroupCycles(JavaClasses classes) {
153154
slices().matching("org.junit.(*)..").should().beFreeOfCycles().check(classes);
154155
}
155156

157+
@SuppressWarnings("removal")
156158
@ArchTest
157159
void freeOfPackageCycles(JavaClasses classes) {
158160
slices().matching("org.junit.(**)").should().beFreeOfCycles() //
159161

160162
// https://github.com/junit-team/junit-framework/issues/4886
161163
.ignoreDependency(TestReporter.class, MediaType.class) //
162164

165+
// https://github.com/junit-team/junit-framework/issues/4885
166+
.ignoreDependency(ClasspathScanner.class, org.junit.platform.commons.support.Resource.class) //
167+
163168
// Needs more investigation
164169
.ignoreDependency(resideInAPackage("org.junit.platform.console.options"),
165170
resideInAPackage("org.junit.platform.console.tasks"))

0 commit comments

Comments
 (0)