60
60
61
61
import java .io .IOException ;
62
62
import java .io .UncheckedIOException ;
63
- import java .lang .reflect .Method ;
64
63
import java .nio .file .Files ;
65
64
import java .nio .file .Path ;
66
65
import java .nio .file .Paths ;
@@ -97,28 +96,17 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
97
96
TestPlan testplan = discoverTestsAndRegisterTestClassesForReflection (launcher , selectors );
98
97
ImageSingletons .add (NativeImageJUnitLauncher .class , new NativeImageJUnitLauncher (launcher , testplan ));
99
98
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 );
120
109
}
121
-
122
110
}
123
111
}
124
112
@@ -130,14 +118,6 @@ private static Class<?> findClassOrNull(ClassLoader loader, String className) {
130
118
}
131
119
}
132
120
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
-
141
121
private List <? extends DiscoverySelector > getSelectors (List <Path > classpathRoots ) {
142
122
try {
143
123
Path outputDir = Paths .get (System .getProperty (UniqueIdTrackingListener .OUTPUT_DIR_PROPERTY_NAME ));
0 commit comments