Support TestNG with @CompileWithTargetClassAccess

This commit is contained in:
Sam Brannen
2022-07-31 14:57:48 +03:00
parent e4395f2f8b
commit 9dd7f5412a

View File

@@ -20,16 +20,21 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Set;
/**
* {@link ClassLoader} implementation to support
* {@link CompileWithTargetClassAccess @CompileWithTargetClassAccess}.
*
* @author Phillip Webb
* @author Sam Brannen
* @since 6.0
*/
final class CompileWithTargetClassAccessClassLoader extends ClassLoader {
private static final Set<String> passthroughPackages =
Set.of("org.junit", "org.testng", "org.hamcrest");
private final ClassLoader testClassLoader;
@@ -41,7 +46,7 @@ final class CompileWithTargetClassAccessClassLoader extends ClassLoader {
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException {
if (name.startsWith("org.junit") || name.startsWith("org.hamcrest")) {
if (passthroughPackages.stream().anyMatch(pkg -> name.startsWith(pkg))) {
return Class.forName(name, false, this.testClassLoader);
}
return super.loadClass(name);