diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java index f9ef8ab066..1a42d0b5e3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnJavaTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 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. @@ -16,10 +16,8 @@ package org.springframework.boot.autoconfigure.condition; +import java.io.Console; import java.lang.reflect.Method; -import java.nio.file.Files; -import java.util.ServiceLoader; -import java.util.function.Function; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledOnJre; @@ -48,58 +46,59 @@ class ConditionalOnJavaTests { private final OnJavaCondition condition = new OnJavaCondition(); @Test - @EnabledOnJre(JRE.JAVA_8) + @EnabledOnJre(JRE.JAVA_17) void doesNotMatchIfBetterVersionIsRequired() { - this.contextRunner.withUserConfiguration(Java9Required.class) + this.contextRunner.withUserConfiguration(Java18Required.class) .run((context) -> assertThat(context).doesNotHaveBean(String.class)); } @Test + @EnabledOnJre(JRE.JAVA_18) void doesNotMatchIfLowerIsRequired() { - this.contextRunner.withUserConfiguration(Java7Required.class) + this.contextRunner.withUserConfiguration(OlderThan18Required.class) .run((context) -> assertThat(context).doesNotHaveBean(String.class)); } @Test void matchesIfVersionIsInRange() { - this.contextRunner.withUserConfiguration(Java8Required.class) + this.contextRunner.withUserConfiguration(Java17Required.class) .run((context) -> assertThat(context).hasSingleBean(String.class)); } @Test void boundsTests() { - testBounds(Range.EQUAL_OR_NEWER, JavaVersion.NINE, JavaVersion.EIGHT, true); - testBounds(Range.EQUAL_OR_NEWER, JavaVersion.EIGHT, JavaVersion.EIGHT, true); - testBounds(Range.EQUAL_OR_NEWER, JavaVersion.EIGHT, JavaVersion.NINE, false); - testBounds(Range.OLDER_THAN, JavaVersion.NINE, JavaVersion.EIGHT, false); - testBounds(Range.OLDER_THAN, JavaVersion.EIGHT, JavaVersion.EIGHT, false); - testBounds(Range.OLDER_THAN, JavaVersion.EIGHT, JavaVersion.NINE, true); + testBounds(Range.EQUAL_OR_NEWER, JavaVersion.EIGHTEEN, JavaVersion.SEVENTEEN, true); + testBounds(Range.EQUAL_OR_NEWER, JavaVersion.SEVENTEEN, JavaVersion.SEVENTEEN, true); + testBounds(Range.EQUAL_OR_NEWER, JavaVersion.SEVENTEEN, JavaVersion.EIGHTEEN, false); + testBounds(Range.OLDER_THAN, JavaVersion.EIGHTEEN, JavaVersion.SEVENTEEN, false); + testBounds(Range.OLDER_THAN, JavaVersion.SEVENTEEN, JavaVersion.SEVENTEEN, false); + testBounds(Range.OLDER_THAN, JavaVersion.SEVENTEEN, JavaVersion.EIGHTEEN, true); } @Test void equalOrNewerMessage() { - ConditionOutcome outcome = this.condition.getMatchOutcome(Range.EQUAL_OR_NEWER, JavaVersion.NINE, - JavaVersion.EIGHT); - assertThat(outcome.getMessage()).isEqualTo("@ConditionalOnJava (1.8 or newer) found 9"); + ConditionOutcome outcome = this.condition.getMatchOutcome(Range.EQUAL_OR_NEWER, JavaVersion.EIGHTEEN, + JavaVersion.SEVENTEEN); + assertThat(outcome.getMessage()).isEqualTo("@ConditionalOnJava (17 or newer) found 18"); } @Test void olderThanMessage() { - ConditionOutcome outcome = this.condition.getMatchOutcome(Range.OLDER_THAN, JavaVersion.NINE, - JavaVersion.EIGHT); - assertThat(outcome.getMessage()).isEqualTo("@ConditionalOnJava (older than 1.8) found 9"); + ConditionOutcome outcome = this.condition.getMatchOutcome(Range.OLDER_THAN, JavaVersion.EIGHTEEN, + JavaVersion.SEVENTEEN); + assertThat(outcome.getMessage()).isEqualTo("@ConditionalOnJava (older than 17) found 18"); } @Test - @EnabledOnJre(JRE.JAVA_8) - void java8IsDetected() throws Exception { - assertThat(getJavaVersion()).isEqualTo("1.8"); + @EnabledOnJre(JRE.JAVA_17) + void java17IsDetected() throws Exception { + assertThat(getJavaVersion()).isEqualTo("17"); } @Test - @EnabledOnJre(JRE.JAVA_8) - void java8IsTheFallback() throws Exception { - assertThat(getJavaVersion(Function.class, Files.class, ServiceLoader.class)).isEqualTo("1.8"); + @EnabledOnJre(JRE.JAVA_17) + void java17IsTheFallback() throws Exception { + assertThat(getJavaVersion(Console.class)).isEqualTo("17"); } private String getJavaVersion(Class... hiddenClasses) throws Exception { @@ -117,8 +116,8 @@ class ConditionalOnJavaTests { } @Configuration(proxyBeanMethods = false) - @ConditionalOnJava(JavaVersion.NINE) - static class Java9Required { + @ConditionalOnJava(JavaVersion.SEVENTEEN) + static class Java17Required { @Bean String foo() { @@ -128,8 +127,8 @@ class ConditionalOnJavaTests { } @Configuration(proxyBeanMethods = false) - @ConditionalOnJava(range = Range.OLDER_THAN, value = JavaVersion.EIGHT) - static class Java7Required { + @ConditionalOnJava(range = Range.OLDER_THAN, value = JavaVersion.EIGHTEEN) + static class OlderThan18Required { @Bean String foo() { @@ -139,8 +138,8 @@ class ConditionalOnJavaTests { } @Configuration(proxyBeanMethods = false) - @ConditionalOnJava(JavaVersion.EIGHT) - static class Java8Required { + @ConditionalOnJava(JavaVersion.EIGHTEEN) + static class Java18Required { @Bean String foo() { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzerTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzerTests.java index b6fa5c7db9..7dfa8484ba 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzerTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/diagnostics/analyzer/NoSuchBeanDefinitionFailureAnalyzerTests.java @@ -32,7 +32,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.diagnostics.FailureAnalysis; import org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter; -import org.springframework.boot.system.JavaVersion; import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -152,14 +151,8 @@ class NoSuchBeanDefinitionFailureAnalyzerTests { @Test void failureAnalysisForUnmatchedQualifier() { FailureAnalysis analysis = analyzeFailure(createFailure(QualifiedBeanConfiguration.class)); - assertThat(analysis.getDescription()).containsPattern(determineAnnotationValuePattern()); - } - - private String determineAnnotationValuePattern() { - if (JavaVersion.getJavaVersion().isEqualOrNewerThan(JavaVersion.FOURTEEN)) { - return "@org.springframework.beans.factory.annotation.Qualifier\\(\"*alpha\"*\\)"; - } - return "@org.springframework.beans.factory.annotation.Qualifier\\(value=\"*alpha\"*\\)"; + assertThat(analysis.getDescription()) + .containsPattern("@org.springframework.beans.factory.annotation.Qualifier\\(\"*alpha\"*\\)"); } private void assertDescriptionConstructorMissingType(FailureAnalysis analysis, Class component, int index, diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java index 1ce565362b..0981ce24a2 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/restart/Restarter.java @@ -46,7 +46,6 @@ import org.springframework.boot.devtools.restart.FailureHandler.Outcome; import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles; import org.springframework.boot.devtools.restart.classloader.RestartClassLoader; import org.springframework.boot.logging.DeferredLog; -import org.springframework.boot.system.JavaVersion; import org.springframework.cglib.core.ClassNameReader; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.GenericApplicationContext; @@ -333,9 +332,6 @@ public class Restarter { cleanCachedIntrospectionResultsCache(); ReflectionUtils.clearCache(); clearAnnotationUtilsCache(); - if (!JavaVersion.getJavaVersion().isEqualOrNewerThan(JavaVersion.NINE)) { - clear("com.sun.naming.internal.ResourceManager", "propertiesCache"); - } } private void cleanCachedIntrospectionResultsCache() throws Exception { 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 eedfe30b49..f4f38936d9 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 @@ -17,13 +17,10 @@ package org.springframework.boot.system; import java.io.Console; -import java.lang.invoke.MethodHandles; import java.time.Duration; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Optional; -import java.util.stream.Stream; import org.springframework.util.ClassUtils; @@ -36,51 +33,6 @@ import org.springframework.util.ClassUtils; */ public enum JavaVersion { - /** - * Java 1.8. - */ - EIGHT("1.8", Optional.class, "empty"), - - /** - * Java 9. - */ - NINE("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"), - - /** - * Java 14. - */ - FOURTEEN("14", MethodHandles.Lookup.class, "hasFullPrivilegeAccess"), - - /** - * Java 15. - */ - FIFTEEN("15", CharSequence.class, "isEmpty"), - - /** - * Java 16. - */ - SIXTEEN("16", Stream.class, "toList"), - /** * Java 17. */ @@ -117,7 +69,7 @@ public enum JavaVersion { return candidate; } } - return EIGHT; + return SEVENTEEN; } /** diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/system/JavaVersionTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/system/JavaVersionTests.java index 0793f99b4e..f73054eabc 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/system/JavaVersionTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/system/JavaVersionTests.java @@ -36,101 +36,47 @@ class JavaVersionTests { @Test void compareToWhenComparingSmallerToGreaterShouldBeLessThanZero() { - assertThat(JavaVersion.EIGHT.compareTo(JavaVersion.NINE)).isLessThan(0); + assertThat(JavaVersion.SEVENTEEN.compareTo(JavaVersion.EIGHTEEN)).isLessThan(0); } @Test void compareToWhenComparingGreaterToSmallerShouldBeGreaterThanZero() { - assertThat(JavaVersion.NINE.compareTo(JavaVersion.EIGHT)).isGreaterThan(0); + assertThat(JavaVersion.EIGHTEEN.compareTo(JavaVersion.SEVENTEEN)).isGreaterThan(0); } @Test void compareToWhenComparingSameShouldBeZero() { - assertThat(JavaVersion.EIGHT.compareTo(JavaVersion.EIGHT)).isEqualTo(0); + assertThat(JavaVersion.SEVENTEEN.compareTo(JavaVersion.SEVENTEEN)).isEqualTo(0); } @Test void isEqualOrNewerThanWhenComparingSameShouldBeTrue() { - assertThat(JavaVersion.EIGHT.isEqualOrNewerThan(JavaVersion.EIGHT)).isTrue(); + assertThat(JavaVersion.SEVENTEEN.isEqualOrNewerThan(JavaVersion.SEVENTEEN)).isTrue(); } @Test void isEqualOrNewerThanWhenSmallerToGreaterShouldBeFalse() { - assertThat(JavaVersion.EIGHT.isEqualOrNewerThan(JavaVersion.NINE)).isFalse(); + assertThat(JavaVersion.SEVENTEEN.isEqualOrNewerThan(JavaVersion.EIGHTEEN)).isFalse(); } @Test void isEqualOrNewerThanWhenGreaterToSmallerShouldBeTrue() { - assertThat(JavaVersion.NINE.isEqualOrNewerThan(JavaVersion.EIGHT)).isTrue(); + assertThat(JavaVersion.EIGHTEEN.isEqualOrNewerThan(JavaVersion.SEVENTEEN)).isTrue(); } @Test void isOlderThanThanWhenComparingSameShouldBeFalse() { - assertThat(JavaVersion.EIGHT.isOlderThan(JavaVersion.EIGHT)).isFalse(); + assertThat(JavaVersion.SEVENTEEN.isOlderThan(JavaVersion.SEVENTEEN)).isFalse(); } @Test void isOlderThanWhenSmallerToGreaterShouldBeTrue() { - assertThat(JavaVersion.EIGHT.isOlderThan(JavaVersion.NINE)).isTrue(); + assertThat(JavaVersion.SEVENTEEN.isOlderThan(JavaVersion.EIGHTEEN)).isTrue(); } @Test void isOlderThanWhenGreaterToSmallerShouldBeFalse() { - assertThat(JavaVersion.NINE.isOlderThan(JavaVersion.EIGHT)).isFalse(); - } - - @Test - @EnabledOnJre(JRE.JAVA_8) - void currentJavaVersionEight() { - assertThat(JavaVersion.getJavaVersion()).isEqualTo(JavaVersion.EIGHT); - } - - @Test - @EnabledOnJre(JRE.JAVA_9) - void currentJavaVersionNine() { - assertThat(JavaVersion.getJavaVersion()).isEqualTo(JavaVersion.NINE); - } - - @Test - @EnabledOnJre(JRE.JAVA_10) - void currentJavaVersionTen() { - assertThat(JavaVersion.getJavaVersion()).isEqualTo(JavaVersion.TEN); - } - - @Test - @EnabledOnJre(JRE.JAVA_11) - void currentJavaVersionEleven() { - assertThat(JavaVersion.getJavaVersion()).isEqualTo(JavaVersion.ELEVEN); - } - - @Test - @EnabledOnJre(JRE.JAVA_12) - void currentJavaVersionTwelve() { - assertThat(JavaVersion.getJavaVersion()).isEqualTo(JavaVersion.TWELVE); - } - - @Test - @EnabledOnJre(JRE.JAVA_13) - void currentJavaVersionThirteen() { - assertThat(JavaVersion.getJavaVersion()).isEqualTo(JavaVersion.THIRTEEN); - } - - @Test - @EnabledOnJre(JRE.JAVA_14) - void currentJavaVersionFourteen() { - assertThat(JavaVersion.getJavaVersion()).isEqualTo(JavaVersion.FOURTEEN); - } - - @Test - @EnabledOnJre(JRE.JAVA_15) - void currentJavaVersionFifteen() { - assertThat(JavaVersion.getJavaVersion()).isEqualTo(JavaVersion.FIFTEEN); - } - - @Test - @EnabledOnJre(JRE.JAVA_16) - void currentJavaVersionSixteen() { - assertThat(JavaVersion.getJavaVersion()).isEqualTo(JavaVersion.SIXTEEN); + assertThat(JavaVersion.EIGHTEEN.isOlderThan(JavaVersion.SEVENTEEN)).isFalse(); } @Test diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java index e2e6b3ab92..b7c6e8d803 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-loader-tests/src/intTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java @@ -108,7 +108,7 @@ class LoaderIntegrationTests { } static JavaRuntime openJdk(JavaVersion version) { - String imageVersion = (version != JavaVersion.EIGHT) ? version.toString() : "8"; + String imageVersion = version.toString(); DockerImageName image = DockerImageName.parse("bellsoft/liberica-openjdk-debian:" + imageVersion); return new JavaRuntime("OpenJDK " + imageVersion, version, () -> new GenericContainer<>(image)); }