diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/configuration/CompatibilityVerifierProperties.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/configuration/CompatibilityVerifierProperties.java index 98e70e1e..21d0fb75 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/configuration/CompatibilityVerifierProperties.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/configuration/CompatibilityVerifierProperties.java @@ -37,7 +37,7 @@ public class CompatibilityVerifierProperties { * the patch version if you don't want to specify a concrete value. Example: * {@code 3.4.x} */ - private List compatibleBootVersions = Arrays.asList("2.4.x"); + private List compatibleBootVersions = Arrays.asList("2.4.x", "2.5.x"); public boolean isEnabled() { return this.enabled; diff --git a/spring-cloud-commons/src/main/java/org/springframework/cloud/configuration/SpringBootVersionVerifier.java b/spring-cloud-commons/src/main/java/org/springframework/cloud/configuration/SpringBootVersionVerifier.java index a4daadb7..c4a78f65 100644 --- a/spring-cloud-commons/src/main/java/org/springframework/cloud/configuration/SpringBootVersionVerifier.java +++ b/spring-cloud-commons/src/main/java/org/springframework/cloud/configuration/SpringBootVersionVerifier.java @@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.boot.SpringBootVersion; -import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.util.StringUtils; /** @@ -36,12 +35,8 @@ class SpringBootVersionVerifier implements CompatibilityVerifier { final Map ACCEPTED_VERSIONS = new HashMap() { { - this.put("1.5", is1_5()); - this.put("2.0", is2_0()); - this.put("2.1", is2_1()); - this.put("2.2", is2_2()); - this.put("2.3", is2_3()); this.put("2.4", is2_4()); + this.put("2.5", is2_5()); } }; @@ -60,28 +55,6 @@ class SpringBootVersionVerifier implements CompatibilityVerifier { return VerificationResult.notCompatible(errorDescription(), action()); } - CompatibilityPredicate is1_5() { - return new CompatibilityPredicate() { - - @Override - public String toString() { - return "Predicate for Boot 1.5"; - } - - @Override - public boolean isCompatible() { - try { - // deprecated 1.5 - Class.forName("org.springframework.boot.context.config.ResourceNotFoundException"); - return true; - } - catch (ClassNotFoundException e) { - return false; - } - } - }; - } - private Boolean bootVersionFromManifest(String s) { String version = getVersionFromManifest(); if (log.isDebugEnabled()) { @@ -98,98 +71,6 @@ class SpringBootVersionVerifier implements CompatibilityVerifier { return SpringBootVersion.getVersion(); } - CompatibilityPredicate is2_0() { - return new CompatibilityPredicate() { - @Override - public String toString() { - return "Predicate for Boot 2.0"; - } - - @Override - public boolean isCompatible() { - - try { - // present in 2.0, 1.5 missing in 2.1 - SpringApplicationBuilder.class.getMethod("web", boolean.class); - return !is1_5().isCompatible(); - } - catch (NoSuchMethodException e) { - return false; - } - } - }; - } - - CompatibilityPredicate is2_1() { - return new CompatibilityPredicate() { - - @Override - public String toString() { - return "Predicate for Boot 2.1"; - } - - @Override - public boolean isCompatible() { - try { - // since 2.1 - Class.forName("org.springframework.boot.task.TaskExecutorCustomizer"); - return true; - } - catch (ClassNotFoundException e) { - return false; - } - - } - }; - } - - CompatibilityPredicate is2_2() { - return new CompatibilityPredicate() { - - @Override - public String toString() { - return "Predicate for Boot 2.2"; - } - - @Override - public boolean isCompatible() { - try { - // since 2.1 - Class.forName( - "org.springframework.boot.autoconfigure.flyway.FlywayMigrationScriptMissingException"); - return true; - } - catch (ClassNotFoundException e) { - return false; - } - - } - }; - } - - CompatibilityPredicate is2_3() { - return new CompatibilityPredicate() { - - @Override - public String toString() { - return "Predicate for Boot 2.3"; - } - - @Override - public boolean isCompatible() { - try { - // since 2.3 - Class.forName("org.springframework.boot.context.propertie.BoundConfigurationProperties"); - return true; - } - catch (ClassNotFoundException e) { - return false; - } - - } - }; - } - CompatibilityPredicate is2_4() { return new CompatibilityPredicate() { @@ -213,6 +94,29 @@ class SpringBootVersionVerifier implements CompatibilityVerifier { }; } + CompatibilityPredicate is2_5() { + return new CompatibilityPredicate() { + + @Override + public String toString() { + return "Predicate for Boot 2.5"; + } + + @Override + public boolean isCompatible() { + try { + // since 2.4 + Class.forName("org.springframework.boot.context.properties.bind.Bindable.BindRestriction"); + return true; + } + catch (ClassNotFoundException e) { + return false; + } + + } + }; + } + private String errorDescription() { String versionFromManifest = getVersionFromManifest(); if (StringUtils.hasText(versionFromManifest)) { diff --git a/spring-cloud-commons/src/test/java/org/springframework/cloud/configuration/SpringBootDependencyTests.java b/spring-cloud-commons/src/test/java/org/springframework/cloud/configuration/SpringBootDependencyTests.java index ab6a5e22..3a5b545d 100644 --- a/spring-cloud-commons/src/test/java/org/springframework/cloud/configuration/SpringBootDependencyTests.java +++ b/spring-cloud-commons/src/test/java/org/springframework/cloud/configuration/SpringBootDependencyTests.java @@ -136,8 +136,7 @@ public class SpringBootDependencyTests { @Test public void should_not_match_when_manifest_has_version_and_not_compatible() { List acceptedVersions = Collections.singletonList("2.5"); - SpringBootVersionVerifier versionVerifier = new SpringBootVersionVerifier( - acceptedVersions) { + SpringBootVersionVerifier versionVerifier = new SpringBootVersionVerifier(acceptedVersions) { @Override String getVersionFromManifest() { return "2.1"; @@ -145,8 +144,7 @@ public class SpringBootDependencyTests { }; versionVerifier.ACCEPTED_VERSIONS.clear(); AtomicBoolean verifierRun = new AtomicBoolean(false); - versionVerifier.ACCEPTED_VERSIONS.put("2.5", - () -> verifierRun.compareAndSet(false, true)); + versionVerifier.ACCEPTED_VERSIONS.put("2.5", () -> verifierRun.compareAndSet(false, true)); VerificationResult verificationResult = versionVerifier.verify(); @@ -158,8 +156,7 @@ public class SpringBootDependencyTests { @Test public void should_match_when_manifest_has_version_and_compatible_list() { List acceptedVersions = Arrays.asList("2.0", "2.1"); - SpringBootVersionVerifier versionVerifier = new SpringBootVersionVerifier( - acceptedVersions) { + SpringBootVersionVerifier versionVerifier = new SpringBootVersionVerifier(acceptedVersions) { @Override String getVersionFromManifest() { return "2.1"; @@ -167,8 +164,7 @@ public class SpringBootDependencyTests { }; versionVerifier.ACCEPTED_VERSIONS.clear(); AtomicBoolean verifierRun = new AtomicBoolean(false); - versionVerifier.ACCEPTED_VERSIONS.put("2.5", - () -> verifierRun.compareAndSet(false, true)); + versionVerifier.ACCEPTED_VERSIONS.put("2.5", () -> verifierRun.compareAndSet(false, true)); VerificationResult verificationResult = versionVerifier.verify(); @@ -177,7 +173,7 @@ public class SpringBootDependencyTests { then(verificationResult.action).isEmpty(); } - //@Ignore // FIXME: https://github.com/spring-cloud/spring-cloud-commons/issues/717 + // @Ignore // FIXME: https://github.com/spring-cloud/spring-cloud-commons/issues/717 @Test public void should_match_against_current_manifest() { verifyCurrentVersionFromManifest("2.4"); @@ -197,7 +193,7 @@ public class SpringBootDependencyTests { @Test public void should_match_against_current_predicate() { - List acceptedVersions = Collections.singletonList("2.1"); + List acceptedVersions = Collections.singletonList("2.4"); SpringBootVersionVerifier versionVerifier = new SpringBootVersionVerifier(acceptedVersions) { @Override String getVersionFromManifest() { @@ -205,7 +201,7 @@ public class SpringBootDependencyTests { } }; versionVerifier.ACCEPTED_VERSIONS.clear(); - versionVerifier.ACCEPTED_VERSIONS.put("2.1", versionVerifier.is2_1()); + versionVerifier.ACCEPTED_VERSIONS.put("2.4", versionVerifier.is2_4()); VerificationResult verificationResult = versionVerifier.verify(); @@ -215,7 +211,7 @@ public class SpringBootDependencyTests { @Test public void should_match_against_current_predicate_with_version_ending_with_x() { - List acceptedVersions = Collections.singletonList("2.1.x"); + List acceptedVersions = Collections.singletonList("2.4.x"); SpringBootVersionVerifier versionVerifier = new SpringBootVersionVerifier(acceptedVersions) { @Override String getVersionFromManifest() { @@ -223,7 +219,7 @@ public class SpringBootDependencyTests { } }; versionVerifier.ACCEPTED_VERSIONS.clear(); - versionVerifier.ACCEPTED_VERSIONS.put("2.1", versionVerifier.is2_1()); + versionVerifier.ACCEPTED_VERSIONS.put("2.4", versionVerifier.is2_4()); VerificationResult verificationResult = versionVerifier.verify();