Remove versions less than 17 from JavaVersion enum

Closes gh-29503
pull/30157/head
Andy Wilkinson 3 years ago
parent a031c0c659
commit f5ca568014

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,10 +16,8 @@
package org.springframework.boot.autoconfigure.condition; package org.springframework.boot.autoconfigure.condition;
import java.io.Console;
import java.lang.reflect.Method; 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.Test;
import org.junit.jupiter.api.condition.EnabledOnJre; import org.junit.jupiter.api.condition.EnabledOnJre;
@ -48,58 +46,59 @@ class ConditionalOnJavaTests {
private final OnJavaCondition condition = new OnJavaCondition(); private final OnJavaCondition condition = new OnJavaCondition();
@Test @Test
@EnabledOnJre(JRE.JAVA_8) @EnabledOnJre(JRE.JAVA_17)
void doesNotMatchIfBetterVersionIsRequired() { void doesNotMatchIfBetterVersionIsRequired() {
this.contextRunner.withUserConfiguration(Java9Required.class) this.contextRunner.withUserConfiguration(Java18Required.class)
.run((context) -> assertThat(context).doesNotHaveBean(String.class)); .run((context) -> assertThat(context).doesNotHaveBean(String.class));
} }
@Test @Test
@EnabledOnJre(JRE.JAVA_18)
void doesNotMatchIfLowerIsRequired() { void doesNotMatchIfLowerIsRequired() {
this.contextRunner.withUserConfiguration(Java7Required.class) this.contextRunner.withUserConfiguration(OlderThan18Required.class)
.run((context) -> assertThat(context).doesNotHaveBean(String.class)); .run((context) -> assertThat(context).doesNotHaveBean(String.class));
} }
@Test @Test
void matchesIfVersionIsInRange() { void matchesIfVersionIsInRange() {
this.contextRunner.withUserConfiguration(Java8Required.class) this.contextRunner.withUserConfiguration(Java17Required.class)
.run((context) -> assertThat(context).hasSingleBean(String.class)); .run((context) -> assertThat(context).hasSingleBean(String.class));
} }
@Test @Test
void boundsTests() { void boundsTests() {
testBounds(Range.EQUAL_OR_NEWER, JavaVersion.NINE, JavaVersion.EIGHT, true); testBounds(Range.EQUAL_OR_NEWER, JavaVersion.EIGHTEEN, JavaVersion.SEVENTEEN, true);
testBounds(Range.EQUAL_OR_NEWER, JavaVersion.EIGHT, JavaVersion.EIGHT, true); testBounds(Range.EQUAL_OR_NEWER, JavaVersion.SEVENTEEN, JavaVersion.SEVENTEEN, true);
testBounds(Range.EQUAL_OR_NEWER, JavaVersion.EIGHT, JavaVersion.NINE, false); testBounds(Range.EQUAL_OR_NEWER, JavaVersion.SEVENTEEN, JavaVersion.EIGHTEEN, false);
testBounds(Range.OLDER_THAN, JavaVersion.NINE, JavaVersion.EIGHT, false); testBounds(Range.OLDER_THAN, JavaVersion.EIGHTEEN, JavaVersion.SEVENTEEN, false);
testBounds(Range.OLDER_THAN, JavaVersion.EIGHT, JavaVersion.EIGHT, false); testBounds(Range.OLDER_THAN, JavaVersion.SEVENTEEN, JavaVersion.SEVENTEEN, false);
testBounds(Range.OLDER_THAN, JavaVersion.EIGHT, JavaVersion.NINE, true); testBounds(Range.OLDER_THAN, JavaVersion.SEVENTEEN, JavaVersion.EIGHTEEN, true);
} }
@Test @Test
void equalOrNewerMessage() { void equalOrNewerMessage() {
ConditionOutcome outcome = this.condition.getMatchOutcome(Range.EQUAL_OR_NEWER, JavaVersion.NINE, ConditionOutcome outcome = this.condition.getMatchOutcome(Range.EQUAL_OR_NEWER, JavaVersion.EIGHTEEN,
JavaVersion.EIGHT); JavaVersion.SEVENTEEN);
assertThat(outcome.getMessage()).isEqualTo("@ConditionalOnJava (1.8 or newer) found 9"); assertThat(outcome.getMessage()).isEqualTo("@ConditionalOnJava (17 or newer) found 18");
} }
@Test @Test
void olderThanMessage() { void olderThanMessage() {
ConditionOutcome outcome = this.condition.getMatchOutcome(Range.OLDER_THAN, JavaVersion.NINE, ConditionOutcome outcome = this.condition.getMatchOutcome(Range.OLDER_THAN, JavaVersion.EIGHTEEN,
JavaVersion.EIGHT); JavaVersion.SEVENTEEN);
assertThat(outcome.getMessage()).isEqualTo("@ConditionalOnJava (older than 1.8) found 9"); assertThat(outcome.getMessage()).isEqualTo("@ConditionalOnJava (older than 17) found 18");
} }
@Test @Test
@EnabledOnJre(JRE.JAVA_8) @EnabledOnJre(JRE.JAVA_17)
void java8IsDetected() throws Exception { void java17IsDetected() throws Exception {
assertThat(getJavaVersion()).isEqualTo("1.8"); assertThat(getJavaVersion()).isEqualTo("17");
} }
@Test @Test
@EnabledOnJre(JRE.JAVA_8) @EnabledOnJre(JRE.JAVA_17)
void java8IsTheFallback() throws Exception { void java17IsTheFallback() throws Exception {
assertThat(getJavaVersion(Function.class, Files.class, ServiceLoader.class)).isEqualTo("1.8"); assertThat(getJavaVersion(Console.class)).isEqualTo("17");
} }
private String getJavaVersion(Class<?>... hiddenClasses) throws Exception { private String getJavaVersion(Class<?>... hiddenClasses) throws Exception {
@ -117,8 +116,8 @@ class ConditionalOnJavaTests {
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnJava(JavaVersion.NINE) @ConditionalOnJava(JavaVersion.SEVENTEEN)
static class Java9Required { static class Java17Required {
@Bean @Bean
String foo() { String foo() {
@ -128,8 +127,8 @@ class ConditionalOnJavaTests {
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnJava(range = Range.OLDER_THAN, value = JavaVersion.EIGHT) @ConditionalOnJava(range = Range.OLDER_THAN, value = JavaVersion.EIGHTEEN)
static class Java7Required { static class OlderThan18Required {
@Bean @Bean
String foo() { String foo() {
@ -139,8 +138,8 @@ class ConditionalOnJavaTests {
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)
@ConditionalOnJava(JavaVersion.EIGHT) @ConditionalOnJava(JavaVersion.EIGHTEEN)
static class Java8Required { static class Java18Required {
@Bean @Bean
String foo() { String foo() {

@ -32,7 +32,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.diagnostics.FailureAnalysis; import org.springframework.boot.diagnostics.FailureAnalysis;
import org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter; import org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter;
import org.springframework.boot.system.JavaVersion;
import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -152,14 +151,8 @@ class NoSuchBeanDefinitionFailureAnalyzerTests {
@Test @Test
void failureAnalysisForUnmatchedQualifier() { void failureAnalysisForUnmatchedQualifier() {
FailureAnalysis analysis = analyzeFailure(createFailure(QualifiedBeanConfiguration.class)); FailureAnalysis analysis = analyzeFailure(createFailure(QualifiedBeanConfiguration.class));
assertThat(analysis.getDescription()).containsPattern(determineAnnotationValuePattern()); assertThat(analysis.getDescription())
} .containsPattern("@org.springframework.beans.factory.annotation.Qualifier\\(\"*alpha\"*\\)");
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\"*\\)";
} }
private void assertDescriptionConstructorMissingType(FailureAnalysis analysis, Class<?> component, int index, private void assertDescriptionConstructorMissingType(FailureAnalysis analysis, Class<?> component, int index,

@ -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.ClassLoaderFiles;
import org.springframework.boot.devtools.restart.classloader.RestartClassLoader; import org.springframework.boot.devtools.restart.classloader.RestartClassLoader;
import org.springframework.boot.logging.DeferredLog; import org.springframework.boot.logging.DeferredLog;
import org.springframework.boot.system.JavaVersion;
import org.springframework.cglib.core.ClassNameReader; import org.springframework.cglib.core.ClassNameReader;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericApplicationContext; import org.springframework.context.support.GenericApplicationContext;
@ -333,9 +332,6 @@ public class Restarter {
cleanCachedIntrospectionResultsCache(); cleanCachedIntrospectionResultsCache();
ReflectionUtils.clearCache(); ReflectionUtils.clearCache();
clearAnnotationUtilsCache(); clearAnnotationUtilsCache();
if (!JavaVersion.getJavaVersion().isEqualOrNewerThan(JavaVersion.NINE)) {
clear("com.sun.naming.internal.ResourceManager", "propertiesCache");
}
} }
private void cleanCachedIntrospectionResultsCache() throws Exception { private void cleanCachedIntrospectionResultsCache() throws Exception {

@ -17,13 +17,10 @@
package org.springframework.boot.system; package org.springframework.boot.system;
import java.io.Console; import java.io.Console;
import java.lang.invoke.MethodHandles;
import java.time.Duration; import java.time.Duration;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
@ -36,51 +33,6 @@ import org.springframework.util.ClassUtils;
*/ */
public enum JavaVersion { 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. * Java 17.
*/ */
@ -117,7 +69,7 @@ public enum JavaVersion {
return candidate; return candidate;
} }
} }
return EIGHT; return SEVENTEEN;
} }
/** /**

@ -36,101 +36,47 @@ class JavaVersionTests {
@Test @Test
void compareToWhenComparingSmallerToGreaterShouldBeLessThanZero() { void compareToWhenComparingSmallerToGreaterShouldBeLessThanZero() {
assertThat(JavaVersion.EIGHT.compareTo(JavaVersion.NINE)).isLessThan(0); assertThat(JavaVersion.SEVENTEEN.compareTo(JavaVersion.EIGHTEEN)).isLessThan(0);
} }
@Test @Test
void compareToWhenComparingGreaterToSmallerShouldBeGreaterThanZero() { void compareToWhenComparingGreaterToSmallerShouldBeGreaterThanZero() {
assertThat(JavaVersion.NINE.compareTo(JavaVersion.EIGHT)).isGreaterThan(0); assertThat(JavaVersion.EIGHTEEN.compareTo(JavaVersion.SEVENTEEN)).isGreaterThan(0);
} }
@Test @Test
void compareToWhenComparingSameShouldBeZero() { void compareToWhenComparingSameShouldBeZero() {
assertThat(JavaVersion.EIGHT.compareTo(JavaVersion.EIGHT)).isEqualTo(0); assertThat(JavaVersion.SEVENTEEN.compareTo(JavaVersion.SEVENTEEN)).isEqualTo(0);
} }
@Test @Test
void isEqualOrNewerThanWhenComparingSameShouldBeTrue() { void isEqualOrNewerThanWhenComparingSameShouldBeTrue() {
assertThat(JavaVersion.EIGHT.isEqualOrNewerThan(JavaVersion.EIGHT)).isTrue(); assertThat(JavaVersion.SEVENTEEN.isEqualOrNewerThan(JavaVersion.SEVENTEEN)).isTrue();
} }
@Test @Test
void isEqualOrNewerThanWhenSmallerToGreaterShouldBeFalse() { void isEqualOrNewerThanWhenSmallerToGreaterShouldBeFalse() {
assertThat(JavaVersion.EIGHT.isEqualOrNewerThan(JavaVersion.NINE)).isFalse(); assertThat(JavaVersion.SEVENTEEN.isEqualOrNewerThan(JavaVersion.EIGHTEEN)).isFalse();
} }
@Test @Test
void isEqualOrNewerThanWhenGreaterToSmallerShouldBeTrue() { void isEqualOrNewerThanWhenGreaterToSmallerShouldBeTrue() {
assertThat(JavaVersion.NINE.isEqualOrNewerThan(JavaVersion.EIGHT)).isTrue(); assertThat(JavaVersion.EIGHTEEN.isEqualOrNewerThan(JavaVersion.SEVENTEEN)).isTrue();
} }
@Test @Test
void isOlderThanThanWhenComparingSameShouldBeFalse() { void isOlderThanThanWhenComparingSameShouldBeFalse() {
assertThat(JavaVersion.EIGHT.isOlderThan(JavaVersion.EIGHT)).isFalse(); assertThat(JavaVersion.SEVENTEEN.isOlderThan(JavaVersion.SEVENTEEN)).isFalse();
} }
@Test @Test
void isOlderThanWhenSmallerToGreaterShouldBeTrue() { void isOlderThanWhenSmallerToGreaterShouldBeTrue() {
assertThat(JavaVersion.EIGHT.isOlderThan(JavaVersion.NINE)).isTrue(); assertThat(JavaVersion.SEVENTEEN.isOlderThan(JavaVersion.EIGHTEEN)).isTrue();
} }
@Test @Test
void isOlderThanWhenGreaterToSmallerShouldBeFalse() { void isOlderThanWhenGreaterToSmallerShouldBeFalse() {
assertThat(JavaVersion.NINE.isOlderThan(JavaVersion.EIGHT)).isFalse(); assertThat(JavaVersion.EIGHTEEN.isOlderThan(JavaVersion.SEVENTEEN)).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);
} }
@Test @Test

@ -108,7 +108,7 @@ class LoaderIntegrationTests {
} }
static JavaRuntime openJdk(JavaVersion version) { 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); DockerImageName image = DockerImageName.parse("bellsoft/liberica-openjdk-debian:" + imageVersion);
return new JavaRuntime("OpenJDK " + imageVersion, version, () -> new GenericContainer<>(image)); return new JavaRuntime("OpenJDK " + imageVersion, version, () -> new GenericContainer<>(image));
} }

Loading…
Cancel
Save