Skip to content

Commit 01c5970

Browse files
committed
[575] Updated to graalvm-23.0.2.
1 parent 6ae4d4f commit 01c5970

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

common/junit-platform-native/src/main/java/org/graalvm/junit/platform/JUnitPlatformFeature.java

+10-30
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060

6161
import java.io.IOException;
6262
import java.io.UncheckedIOException;
63-
import java.lang.reflect.Method;
6463
import java.nio.file.Files;
6564
import java.nio.file.Path;
6665
import java.nio.file.Paths;
@@ -97,28 +96,17 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
9796
TestPlan testplan = discoverTestsAndRegisterTestClassesForReflection(launcher, selectors);
9897
ImageSingletons.add(NativeImageJUnitLauncher.class, new NativeImageJUnitLauncher(launcher, testplan));
9998

100-
Method registerAllDeclaredMethods = findMethodOrNull(RuntimeReflection.class, "registerAllDeclaredMethods", Class.class);
101-
if (registerAllDeclaredMethods != null) {
102-
// graalvm-23.0+ with `RuntimeReflection#registerAllDeclaredMethods` method.
103-
ClassLoader applicationLoader = access.getApplicationClassLoader();
104-
Class<?> typeSafeMatcher = findClassOrNull(applicationLoader, "org.hamcrest.TypeSafeMatcher");
105-
Class<?> typeSafeDiagnosingMatcher = findClassOrNull(applicationLoader, "org.hamcrest.TypeSafeDiagnosingMatcher");
106-
if (typeSafeMatcher != null || typeSafeDiagnosingMatcher != null) {
107-
BiConsumer<DuringAnalysisAccess, Class<?>> registerMatcherForReflection = (a, c) -> {
108-
try {
109-
registerAllDeclaredMethods.invoke(null, c);
110-
} catch (ReflectiveOperationException e) {
111-
throw new RuntimeException(e);
112-
}
113-
};
114-
if (typeSafeMatcher != null) {
115-
access.registerSubtypeReachabilityHandler(registerMatcherForReflection, typeSafeMatcher);
116-
}
117-
if (typeSafeDiagnosingMatcher != null) {
118-
access.registerSubtypeReachabilityHandler(registerMatcherForReflection, typeSafeDiagnosingMatcher);
119-
}
99+
ClassLoader applicationLoader = access.getApplicationClassLoader();
100+
Class<?> typeSafeMatcher = findClassOrNull(applicationLoader, "org.hamcrest.TypeSafeMatcher");
101+
Class<?> typeSafeDiagnosingMatcher = findClassOrNull(applicationLoader, "org.hamcrest.TypeSafeDiagnosingMatcher");
102+
if (typeSafeMatcher != null || typeSafeDiagnosingMatcher != null) {
103+
BiConsumer<DuringAnalysisAccess, Class<?>> registerMatcherForReflection = (a, c) -> RuntimeReflection.registerAllDeclaredMethods(c);
104+
if (typeSafeMatcher != null) {
105+
access.registerSubtypeReachabilityHandler(registerMatcherForReflection, typeSafeMatcher);
106+
}
107+
if (typeSafeDiagnosingMatcher != null) {
108+
access.registerSubtypeReachabilityHandler(registerMatcherForReflection, typeSafeDiagnosingMatcher);
120109
}
121-
122110
}
123111
}
124112

@@ -130,14 +118,6 @@ private static Class<?> findClassOrNull(ClassLoader loader, String className) {
130118
}
131119
}
132120

133-
private static Method findMethodOrNull(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
134-
try {
135-
return clazz.getDeclaredMethod(methodName, parameterTypes);
136-
} catch (NoSuchMethodException e) {
137-
return null;
138-
}
139-
}
140-
141121
private List<? extends DiscoverySelector> getSelectors(List<Path> classpathRoots) {
142122
try {
143123
Path outputDir = Paths.get(System.getProperty(UniqueIdTrackingListener.OUTPUT_DIR_PROPERTY_NAME));

0 commit comments

Comments
 (0)