Add platform compatibility range support

This commit adds a new `platformCompatibilityRange` in the metadata that
can be used to restrict the valid platform versions. If a project is
requested or metadata needs to be resolved against a version that does
not match the range, an exception is thrown.

Closes gh-1048
This commit is contained in:
Stephane Nicoll
2020-01-03 14:08:37 +01:00
parent e25fb74d23
commit eef529aa7c
9 changed files with 119 additions and 20 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@@ -210,6 +210,16 @@ public class InitializrConfiguration {
*/
private boolean forceSsl;
/**
* Compatibility range of supported platform versions. Requesting metadata or
* project generation with a platform version that does not match this range is
* not supported.
*/
private String platformCompatibilityRange;
@JsonIgnore
private VersionRange compatibilityRange;
/**
* The "BillOfMaterials" that are referenced in this instance, identified by an
* arbitrary identifier that can be used in the dependencies definition.
@@ -300,6 +310,14 @@ public class InitializrConfiguration {
this.forceSsl = forceSsl;
}
public String getPlatformCompatibilityRange() {
return this.platformCompatibilityRange;
}
public void setPlatformCompatibilityRange(String platformCompatibilityRange) {
this.platformCompatibilityRange = platformCompatibilityRange;
}
public String getArtifactRepository() {
return this.artifactRepository;
}
@@ -335,6 +353,14 @@ public class InitializrConfiguration {
this.maven.parent.validate();
this.boms.forEach((k, v) -> v.validate());
this.kotlin.validate();
updateCompatibilityRange(VersionParser.DEFAULT);
}
public void updateCompatibilityRange(VersionParser versionParser) {
this.getBoms().values().forEach((it) -> it.updateCompatibilityRange(versionParser));
this.getKotlin().updateCompatibilityRange(versionParser);
this.compatibilityRange = (this.platformCompatibilityRange != null)
? versionParser.parseRange(this.platformCompatibilityRange) : null;
}
public void merge(Env other) {
@@ -344,6 +370,8 @@ public class InitializrConfiguration {
this.fallbackApplicationName = other.fallbackApplicationName;
this.invalidApplicationNames = other.invalidApplicationNames;
this.forceSsl = other.forceSsl;
this.platformCompatibilityRange = other.platformCompatibilityRange;
this.compatibilityRange = other.compatibilityRange;
this.gradle.merge(other.gradle);
this.kotlin.merge(other.kotlin);
this.maven.merge(other.maven);
@@ -351,6 +379,20 @@ public class InitializrConfiguration {
other.repositories.forEach(this.repositories::putIfAbsent);
}
/**
* Specify whether the specified {@linkplain Version platform version} is
* supported.
* @param platformVersion the platform version to check
* @return {@code true} if this version is supported, {@code false} otherwise
*/
public boolean isCompatiblePlatformVersion(Version platformVersion) {
return (this.compatibilityRange == null || this.compatibilityRange.match(platformVersion));
}
public String determinePlatformCompatibilityRangeRequirement() {
return this.compatibilityRange.toString();
}
/**
* Gradle details.
*/
@@ -421,18 +463,17 @@ public class InitializrConfiguration {
}
public void validate() {
VersionParser simpleParser = new VersionParser(Collections.emptyList());
this.mappings.forEach((m) -> {
if (m.compatibilityRange == null) {
throw new InvalidInitializrMetadataException(
"CompatibilityRange is mandatory, invalid version mapping for " + this);
}
m.range = simpleParser.parseRange(m.compatibilityRange);
if (m.version == null) {
throw new InvalidInitializrMetadataException(
"Version is mandatory, invalid version mapping for " + this);
}
});
updateCompatibilityRange(VersionParser.DEFAULT);
}
public void updateCompatibilityRange(VersionParser versionParser) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@@ -206,8 +206,7 @@ public class InitializrMetadata {
.collect(Collectors.toList());
VersionParser parser = new VersionParser(bootVersions);
this.dependencies.updateCompatibilityRange(parser);
this.configuration.getEnv().getBoms().values().forEach((it) -> it.updateCompatibilityRange(parser));
this.configuration.getEnv().getKotlin().updateCompatibilityRange(parser);
this.configuration.getEnv().updateCompatibilityRange(parser);
}
/**