mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 20:19:06 +00:00
Add runtime hints for JavaVersion detection
Closes gh-47619
This commit is contained in:
+37
@@ -18,6 +18,7 @@ package org.springframework.boot.system;
|
||||
|
||||
import java.io.Console;
|
||||
import java.io.Reader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.NumberFormat;
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
@@ -26,6 +27,9 @@ import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.springframework.aot.hint.ExecutableMode;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.aot.hint.RuntimeHintsRegistrar;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
@@ -90,8 +94,17 @@ public enum JavaVersion {
|
||||
|
||||
private final boolean available;
|
||||
|
||||
private final Class<?> versionSpecificClass;
|
||||
|
||||
private final String versionSpecificMethod;
|
||||
|
||||
private final Class<?>[] paramTypes;
|
||||
|
||||
JavaVersion(String name, Class<?> versionSpecificClass, String versionSpecificMethod, Class<?>... paramTypes) {
|
||||
this.name = name;
|
||||
this.versionSpecificClass = versionSpecificClass;
|
||||
this.versionSpecificMethod = versionSpecificMethod;
|
||||
this.paramTypes = paramTypes;
|
||||
this.available = ClassUtils.hasMethod(versionSpecificClass, versionSpecificMethod, paramTypes);
|
||||
}
|
||||
|
||||
@@ -133,4 +146,28 @@ public enum JavaVersion {
|
||||
return compareTo(version) < 0;
|
||||
}
|
||||
|
||||
static class Hints implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
for (JavaVersion javaVersion : JavaVersion.values()) {
|
||||
Method method = findMethod(javaVersion);
|
||||
if (method != null) {
|
||||
hints.reflection().registerMethod(method, ExecutableMode.INTROSPECT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Method findMethod(JavaVersion javaVersion) {
|
||||
try {
|
||||
return ClassUtils.getMethod(javaVersion.versionSpecificClass, javaVersion.versionSpecificMethod,
|
||||
javaVersion.paramTypes);
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ org.springframework.boot.logging.logback.LogbackRuntimeHints,\
|
||||
org.springframework.boot.logging.structured.ElasticCommonSchemaProperties$ElasticCommonSchemaPropertiesRuntimeHints,\
|
||||
org.springframework.boot.logging.structured.GraylogExtendedLogFormatProperties$GraylogExtendedLogFormatPropertiesRuntimeHints,\
|
||||
org.springframework.boot.logging.structured.StructuredLoggingJsonProperties$StructuredLoggingJsonPropertiesRuntimeHints,\
|
||||
org.springframework.boot.system.JavaVersion$Hints,\
|
||||
org.springframework.boot.web.embedded.undertow.UndertowWebServer$UndertowWebServerRuntimeHints,\
|
||||
org.springframework.boot.web.server.MimeMappings$MimeMappingsRuntimeHints
|
||||
|
||||
|
||||
Reference in New Issue
Block a user