Search in sources :

Example 1 with JavaVersion

use of org.springframework.boot.system.JavaVersion in project spring-boot by spring-projects.

the class OnJavaCondition method getMatchOutcome.

@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
    Map<String, Object> attributes = metadata.getAnnotationAttributes(ConditionalOnJava.class.getName());
    Range range = (Range) attributes.get("range");
    JavaVersion version = (JavaVersion) attributes.get("value");
    return getMatchOutcome(range, JVM_VERSION, version);
}
Also used : Range(org.springframework.boot.autoconfigure.condition.ConditionalOnJava.Range) JavaVersion(org.springframework.boot.system.JavaVersion)

Example 2 with JavaVersion

use of org.springframework.boot.system.JavaVersion in project spring-boot by spring-projects.

the class ConditionalOnJavaTests method getJavaVersion.

private String getJavaVersion(Class<?>... hiddenClasses) throws Exception {
    FilteredClassLoader classLoader = new FilteredClassLoader(hiddenClasses);
    Class<?> javaVersionClass = Class.forName(JavaVersion.class.getName(), false, classLoader);
    Method getJavaVersionMethod = ReflectionUtils.findMethod(javaVersionClass, "getJavaVersion");
    Object javaVersion = ReflectionUtils.invokeMethod(getJavaVersionMethod, null);
    classLoader.close();
    return javaVersion.toString();
}
Also used : Method(java.lang.reflect.Method) JavaVersion(org.springframework.boot.system.JavaVersion) FilteredClassLoader(org.springframework.boot.test.context.FilteredClassLoader)

Aggregations

JavaVersion (org.springframework.boot.system.JavaVersion)2 Method (java.lang.reflect.Method)1 Range (org.springframework.boot.autoconfigure.condition.ConditionalOnJava.Range)1 FilteredClassLoader (org.springframework.boot.test.context.FilteredClassLoader)1