|
18 | 18 |
|
19 | 19 | import java.io.Console; |
20 | 20 | import java.io.Reader; |
| 21 | +import java.lang.reflect.Method; |
21 | 22 | import java.text.NumberFormat; |
22 | 23 | import java.time.Duration; |
23 | 24 | import java.util.Arrays; |
|
26 | 27 | import java.util.SortedSet; |
27 | 28 | import java.util.concurrent.Future; |
28 | 29 |
|
| 30 | +import org.springframework.aot.hint.ExecutableMode; |
| 31 | +import org.springframework.aot.hint.RuntimeHints; |
| 32 | +import org.springframework.aot.hint.RuntimeHintsRegistrar; |
29 | 33 | import org.springframework.util.ClassUtils; |
30 | 34 |
|
31 | 35 | /** |
@@ -90,8 +94,17 @@ public enum JavaVersion { |
90 | 94 |
|
91 | 95 | private final boolean available; |
92 | 96 |
|
| 97 | + private final Class<?> versionSpecificClass; |
| 98 | + |
| 99 | + private final String versionSpecificMethod; |
| 100 | + |
| 101 | + private final Class<?>[] paramTypes; |
| 102 | + |
93 | 103 | JavaVersion(String name, Class<?> versionSpecificClass, String versionSpecificMethod, Class<?>... paramTypes) { |
94 | 104 | this.name = name; |
| 105 | + this.versionSpecificClass = versionSpecificClass; |
| 106 | + this.versionSpecificMethod = versionSpecificMethod; |
| 107 | + this.paramTypes = paramTypes; |
95 | 108 | this.available = ClassUtils.hasMethod(versionSpecificClass, versionSpecificMethod, paramTypes); |
96 | 109 | } |
97 | 110 |
|
@@ -133,4 +146,28 @@ public boolean isOlderThan(JavaVersion version) { |
133 | 146 | return compareTo(version) < 0; |
134 | 147 | } |
135 | 148 |
|
| 149 | + static class Hints implements RuntimeHintsRegistrar { |
| 150 | + |
| 151 | + @Override |
| 152 | + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { |
| 153 | + for (JavaVersion javaVersion : JavaVersion.values()) { |
| 154 | + Method method = findMethod(javaVersion); |
| 155 | + if (method != null) { |
| 156 | + hints.reflection().registerMethod(method, ExecutableMode.INTROSPECT); |
| 157 | + } |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + private Method findMethod(JavaVersion javaVersion) { |
| 162 | + try { |
| 163 | + return ClassUtils.getMethod(javaVersion.versionSpecificClass, javaVersion.versionSpecificMethod, |
| 164 | + javaVersion.paramTypes); |
| 165 | + } |
| 166 | + catch (IllegalStateException ex) { |
| 167 | + return null; |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + } |
| 172 | + |
136 | 173 | } |
0 commit comments