Skip to content

Commit

Permalink
[575] Updated to graalvm-23.0.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzezula committed Feb 20, 2024
1 parent 6ae4d4f commit 01c5970
Showing 1 changed file with 10 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@

import java.io.IOException;
import java.io.UncheckedIOException;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down Expand Up @@ -97,28 +96,17 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
TestPlan testplan = discoverTestsAndRegisterTestClassesForReflection(launcher, selectors);
ImageSingletons.add(NativeImageJUnitLauncher.class, new NativeImageJUnitLauncher(launcher, testplan));

Method registerAllDeclaredMethods = findMethodOrNull(RuntimeReflection.class, "registerAllDeclaredMethods", Class.class);
if (registerAllDeclaredMethods != null) {
// graalvm-23.0+ with `RuntimeReflection#registerAllDeclaredMethods` method.
ClassLoader applicationLoader = access.getApplicationClassLoader();
Class<?> typeSafeMatcher = findClassOrNull(applicationLoader, "org.hamcrest.TypeSafeMatcher");
Class<?> typeSafeDiagnosingMatcher = findClassOrNull(applicationLoader, "org.hamcrest.TypeSafeDiagnosingMatcher");
if (typeSafeMatcher != null || typeSafeDiagnosingMatcher != null) {
BiConsumer<DuringAnalysisAccess, Class<?>> registerMatcherForReflection = (a, c) -> {
try {
registerAllDeclaredMethods.invoke(null, c);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
};
if (typeSafeMatcher != null) {
access.registerSubtypeReachabilityHandler(registerMatcherForReflection, typeSafeMatcher);
}
if (typeSafeDiagnosingMatcher != null) {
access.registerSubtypeReachabilityHandler(registerMatcherForReflection, typeSafeDiagnosingMatcher);
}
ClassLoader applicationLoader = access.getApplicationClassLoader();
Class<?> typeSafeMatcher = findClassOrNull(applicationLoader, "org.hamcrest.TypeSafeMatcher");
Class<?> typeSafeDiagnosingMatcher = findClassOrNull(applicationLoader, "org.hamcrest.TypeSafeDiagnosingMatcher");
if (typeSafeMatcher != null || typeSafeDiagnosingMatcher != null) {
BiConsumer<DuringAnalysisAccess, Class<?>> registerMatcherForReflection = (a, c) -> RuntimeReflection.registerAllDeclaredMethods(c);
if (typeSafeMatcher != null) {
access.registerSubtypeReachabilityHandler(registerMatcherForReflection, typeSafeMatcher);
}
if (typeSafeDiagnosingMatcher != null) {
access.registerSubtypeReachabilityHandler(registerMatcherForReflection, typeSafeDiagnosingMatcher);
}

}
}

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

private static Method findMethodOrNull(Class<?> clazz, String methodName, Class<?>... parameterTypes) {
try {
return clazz.getDeclaredMethod(methodName, parameterTypes);
} catch (NoSuchMethodException e) {
return null;
}
}

private List<? extends DiscoverySelector> getSelectors(List<Path> classpathRoots) {
try {
Path outputDir = Paths.get(System.getProperty(UniqueIdTrackingListener.OUTPUT_DIR_PROPERTY_NAME));
Expand Down

0 comments on commit 01c5970

Please sign in to comment.