Adds support for boot 2.5.
Adds version in CompatibilityVerifierProperties and reflection check in SpringBootVersionVerifier Also removes all reflection checks prior to 2.4 since they no longer apply. Fixes gh-896
This commit is contained in:
@@ -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<String> compatibleBootVersions = Arrays.asList("2.4.x");
|
||||
private List<String> compatibleBootVersions = Arrays.asList("2.4.x", "2.5.x");
|
||||
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
|
||||
@@ -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<String, CompatibilityPredicate> ACCEPTED_VERSIONS = new HashMap<String, CompatibilityPredicate>() {
|
||||
{
|
||||
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)) {
|
||||
|
||||
@@ -136,8 +136,7 @@ public class SpringBootDependencyTests {
|
||||
@Test
|
||||
public void should_not_match_when_manifest_has_version_and_not_compatible() {
|
||||
List<String> 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<String> 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<String> acceptedVersions = Collections.singletonList("2.1");
|
||||
List<String> 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<String> acceptedVersions = Collections.singletonList("2.1.x");
|
||||
List<String> 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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user