From c2b6939ae1e6cc0b2f8c7161ce448759a8e9417c Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Fri, 19 Jul 2019 23:27:52 +0200 Subject: [PATCH] Cover more known Java versions in JavaVersion See gh-17590 --- .../boot/system/JavaVersion.java | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java index 2953b02baf..89c141cf4b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/system/JavaVersion.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2017 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,12 @@ package org.springframework.boot.system; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Optional; import org.springframework.util.ClassUtils; /** - * Supported Java versions. + * Known Java versions. * * @author Oliver Gierke * @author Phillip Webb @@ -34,20 +35,40 @@ public enum JavaVersion { /** * Java 1.8. */ - EIGHT("1.8", "java.util.function.Function"), + EIGHT("1.8", Optional.class, "empty"), /** * Java 1.9. */ - NINE("1.9", "java.security.cert.URICertStoreParameters"); + NINE("1.9", Optional.class, "stream"), + + /** + * Java 10. + */ + TEN("10", Optional.class, "orElseThrow"), + + /** + * Java 11. + */ + ELEVEN("11", String.class, "strip"), + + /** + * Java 12. + */ + TWELVE("12", String.class, "describeConstable"), + + /** + * Java 13. + */ + THIRTEEN("13", String.class, "stripIndent"); private final String name; private final boolean available; - JavaVersion(String name, String className) { + JavaVersion(String name, Class clazz, String methodName) { this.name = name; - this.available = ClassUtils.isPresent(className, getClass().getClassLoader()); + this.available = ClassUtils.hasMethod(clazz, methodName); } @Override