|
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 | /** |
@@ -96,8 +100,17 @@ public enum JavaVersion { |
96 | 100 |
|
97 | 101 | private final boolean available; |
98 | 102 |
|
| 103 | + private final Class<?> versionSpecificClass; |
| 104 | + |
| 105 | + private final String versionSpecificMethod; |
| 106 | + |
| 107 | + private final Class<?>[] paramTypes; |
| 108 | + |
99 | 109 | JavaVersion(String name, Class<?> versionSpecificClass, String versionSpecificMethod, Class<?>... paramTypes) { |
100 | 110 | this.name = name; |
| 111 | + this.versionSpecificClass = versionSpecificClass; |
| 112 | + this.versionSpecificMethod = versionSpecificMethod; |
| 113 | + this.paramTypes = paramTypes; |
101 | 114 | this.available = ClassUtils.hasMethod(versionSpecificClass, versionSpecificMethod, paramTypes); |
102 | 115 | } |
103 | 116 |
|
@@ -139,4 +152,28 @@ public boolean isOlderThan(JavaVersion version) { |
139 | 152 | return compareTo(version) < 0; |
140 | 153 | } |
141 | 154 |
|
| 155 | + static class Hints implements RuntimeHintsRegistrar { |
| 156 | + |
| 157 | + @Override |
| 158 | + public void registerHints(RuntimeHints hints, ClassLoader classLoader) { |
| 159 | + for (JavaVersion javaVersion : JavaVersion.values()) { |
| 160 | + Method method = findMethod(javaVersion); |
| 161 | + if (method != null) { |
| 162 | + hints.reflection().registerMethod(method, ExecutableMode.INTROSPECT); |
| 163 | + } |
| 164 | + } |
| 165 | + } |
| 166 | + |
| 167 | + private Method findMethod(JavaVersion javaVersion) { |
| 168 | + try { |
| 169 | + return ClassUtils.getMethod(javaVersion.versionSpecificClass, javaVersion.versionSpecificMethod, |
| 170 | + javaVersion.paramTypes); |
| 171 | + } |
| 172 | + catch (IllegalStateException ex) { |
| 173 | + return null; |
| 174 | + } |
| 175 | + } |
| 176 | + |
| 177 | + } |
| 178 | + |
142 | 179 | } |
0 commit comments