From 305ed5d3eb1947498c76d87e7ec36b76e80f3d08 Mon Sep 17 00:00:00 2001 From: HaiTao Zhang Date: Tue, 30 Jul 2019 14:07:53 -0700 Subject: [PATCH] fix to gh-418 --- .../info/BomRangesInfoContributor.java | 2 +- .../info/DependencyRangesInfoContributor.java | 12 +- .../DependencyRangesInfoContributorTests.java | 2 +- .../gradle/OnGradleVersionCondition.java | 10 +- ...sionRange.java => CompatibilityRange.java} | 8 +- .../generator/version/VersionParser.java | 14 +- ...ests.java => CompatibilityRangeTests.java} | 32 +-- .../resources/application-test-default.yml | 12 +- .../initializr/metadata/BillOfMaterials.java | 33 +-- .../metadata/DependenciesCapability.java | 8 +- .../initializr/metadata/Dependency.java | 58 ++--- .../initializr/metadata/DependencyGroup.java | 16 +- .../metadata/InitializrConfiguration.java | 41 ++-- .../metadata/InitializrMetadata.java | 6 +- .../metadata/BillOfMaterialsTests.java | 4 +- .../metadata/DependenciesCapabilityTests.java | 10 +- .../initializr/metadata/DependencyTests.java | 16 +- .../InitializrConfigurationTests.java | 4 +- .../metadata/InitializrMetadataTests.java | 10 +- .../MetadataBuildItemResolverTests.java | 4 +- .../resources/application-test-default.yml | 12 +- .../InitializrMetadataV21JsonMapper.java | 4 +- .../InitializrMetadataV22JsonMapper.java | 44 ++++ .../InitializrMetadataV2JsonMapper.java | 4 +- .../web/mapper/InitializrMetadataVersion.java | 7 +- .../web/project/MainController.java | 10 +- .../MainControllerIntegrationTests.java | 10 + ...ectRequestToDescriptionConverterTests.java | 4 +- .../CommandLineHelpGeneratorTests.java | 6 +- ...efaultDependencyMetadataProviderTests.java | 4 +- .../metadata/config/test-default.json | 12 +- .../metadata/test-default-2.2.0-ssl.json | 232 ++++++++++++++++++ .../metadata/test-default-2.2.0.json | 232 ++++++++++++++++++ pom.xml | 8 +- 34 files changed, 718 insertions(+), 173 deletions(-) rename initializr-generator/src/main/java/io/spring/initializr/generator/version/{VersionRange.java => CompatibilityRange.java} (95%) rename initializr-generator/src/test/java/io/spring/initializr/generator/version/{VersionRangeTests.java => CompatibilityRangeTests.java} (78%) create mode 100644 initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataV22JsonMapper.java create mode 100644 initializr-web/src/test/resources/metadata/test-default-2.2.0-ssl.json create mode 100644 initializr-web/src/test/resources/metadata/test-default-2.2.0.json diff --git a/initializr-actuator/src/main/java/io/spring/initializr/actuate/info/BomRangesInfoContributor.java b/initializr-actuator/src/main/java/io/spring/initializr/actuate/info/BomRangesInfoContributor.java index 752d96d71e..8c266dc843 100644 --- a/initializr-actuator/src/main/java/io/spring/initializr/actuate/info/BomRangesInfoContributor.java +++ b/initializr-actuator/src/main/java/io/spring/initializr/actuate/info/BomRangesInfoContributor.java @@ -45,7 +45,7 @@ public void contribute(Info.Builder builder) { if (v.getMappings() != null && !v.getMappings().isEmpty()) { Map bom = new LinkedHashMap<>(); v.getMappings().forEach((it) -> { - String requirement = "Spring Boot " + it.determineVersionRangeRequirement(); + String requirement = "Spring Boot " + it.determineCompatibilityRangeRequirement(); bom.put(it.getVersion(), requirement); }); details.put(k, bom); diff --git a/initializr-actuator/src/main/java/io/spring/initializr/actuate/info/DependencyRangesInfoContributor.java b/initializr-actuator/src/main/java/io/spring/initializr/actuate/info/DependencyRangesInfoContributor.java index a047ca3ee3..73721ecb34 100644 --- a/initializr-actuator/src/main/java/io/spring/initializr/actuate/info/DependencyRangesInfoContributor.java +++ b/initializr-actuator/src/main/java/io/spring/initializr/actuate/info/DependencyRangesInfoContributor.java @@ -19,8 +19,8 @@ import java.util.LinkedHashMap; import java.util.Map; +import io.spring.initializr.generator.version.CompatibilityRange; import io.spring.initializr.generator.version.Version; -import io.spring.initializr.generator.version.VersionRange; import io.spring.initializr.metadata.Dependency; import io.spring.initializr.metadata.InitializrMetadataProvider; @@ -57,7 +57,7 @@ public void contribute(Info.Builder builder) { private void contribute(Map details, Dependency dependency) { if (!ObjectUtils.isEmpty(dependency.getMappings())) { - Map dep = new LinkedHashMap<>(); + Map dep = new LinkedHashMap<>(); dependency.getMappings().forEach((it) -> { if (it.getRange() != null && it.getVersion() != null) { dep.put(it.getVersion(), it.getRange()); @@ -68,7 +68,7 @@ private void contribute(Map details, Dependency dependency) { boolean openRange = dep.values().stream().anyMatch((v) -> v.getHigherVersion() == null); if (!openRange) { Version higher = getHigher(dep); - dep.put("managed", new VersionRange(higher)); + dep.put("managed", new CompatibilityRange(higher)); } } Map depInfo = new LinkedHashMap<>(); @@ -84,10 +84,10 @@ else if (dependency.getVersion() != null && dependency.getRange() != null) { } } - private Version getHigher(Map dep) { + private Version getHigher(Map dep) { Version higher = null; - for (VersionRange versionRange : dep.values()) { - Version candidate = versionRange.getHigherVersion(); + for (CompatibilityRange compatibilityRange : dep.values()) { + Version candidate = compatibilityRange.getHigherVersion(); if (higher == null) { higher = candidate; } diff --git a/initializr-actuator/src/test/java/io/spring/initializr/actuate/info/DependencyRangesInfoContributorTests.java b/initializr-actuator/src/test/java/io/spring/initializr/actuate/info/DependencyRangesInfoContributorTests.java index 0dbee57415..f39f7e7777 100755 --- a/initializr-actuator/src/test/java/io/spring/initializr/actuate/info/DependencyRangesInfoContributorTests.java +++ b/initializr-actuator/src/test/java/io/spring/initializr/actuate/info/DependencyRangesInfoContributorTests.java @@ -80,7 +80,7 @@ void dependencyWithRangeAndBom() { @Test void dependencyNoMappingSimpleRange() { Dependency dependency = Dependency.withId("foo", "com.example", "foo", "1.2.3.RELEASE"); - dependency.setVersionRange("[1.1.0.RELEASE, 1.5.0.RELEASE)"); + dependency.setCompatibilityRange("[1.1.0.RELEASE, 1.5.0.RELEASE)"); InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("foo", dependency) .build(); Info info = getInfo(metadata); diff --git a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/OnGradleVersionCondition.java b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/OnGradleVersionCondition.java index d5fea53f31..b3c76c6f65 100644 --- a/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/OnGradleVersionCondition.java +++ b/initializr-generator-spring/src/main/java/io/spring/initializr/generator/spring/build/gradle/OnGradleVersionCondition.java @@ -20,9 +20,9 @@ import io.spring.initializr.generator.condition.ProjectGenerationCondition; import io.spring.initializr.generator.project.ResolvedProjectDescription; +import io.spring.initializr.generator.version.CompatibilityRange; import io.spring.initializr.generator.version.Version; import io.spring.initializr.generator.version.VersionParser; -import io.spring.initializr.generator.version.VersionRange; import org.springframework.context.annotation.ConditionContext; import org.springframework.core.type.AnnotatedTypeMetadata; @@ -36,11 +36,13 @@ */ public class OnGradleVersionCondition extends ProjectGenerationCondition { - private static final VersionRange GRADLE_3_VERSION_RANGE = VersionParser.DEFAULT.parseRange("[1.5.0.M1,2.0.0.M1)"); + private static final CompatibilityRange GRADLE_3_VERSION_RANGE = VersionParser.DEFAULT + .parseRange("[1.5.0.M1,2.0.0.M1)"); - private static final VersionRange GRADLE_4_VERSION_RANGE = VersionParser.DEFAULT.parseRange("[2.0.0.M1, 2.1.0.M1)"); + private static final CompatibilityRange GRADLE_4_VERSION_RANGE = VersionParser.DEFAULT + .parseRange("[2.0.0.M1, 2.1.0.M1)"); - private static final VersionRange GRADLE_5_VERSION_RANGE = VersionParser.DEFAULT.parseRange("2.1.0.M1"); + private static final CompatibilityRange GRADLE_5_VERSION_RANGE = VersionParser.DEFAULT.parseRange("2.1.0.M1"); @Override protected boolean matches(ResolvedProjectDescription projectDescription, ConditionContext context, diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/version/VersionRange.java b/initializr-generator/src/main/java/io/spring/initializr/generator/version/CompatibilityRange.java similarity index 95% rename from initializr-generator/src/main/java/io/spring/initializr/generator/version/VersionRange.java rename to initializr-generator/src/main/java/io/spring/initializr/generator/version/CompatibilityRange.java index 8b1d11faf5..aebe65cd65 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/version/VersionRange.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/version/CompatibilityRange.java @@ -34,7 +34,7 @@ * * @author Stephane Nicoll */ -public class VersionRange { +public class CompatibilityRange { private final Version lowerVersion; @@ -44,7 +44,7 @@ public class VersionRange { private final boolean higherInclusive; - protected VersionRange(Version lowerVersion, boolean lowerInclusive, Version higherVersion, + protected CompatibilityRange(Version lowerVersion, boolean lowerInclusive, Version higherVersion, boolean higherInclusive) { this.lowerVersion = lowerVersion; this.lowerInclusive = lowerInclusive; @@ -52,7 +52,7 @@ protected VersionRange(Version lowerVersion, boolean lowerInclusive, Version hig this.higherInclusive = higherInclusive; } - public VersionRange(Version startingVersion) { + public CompatibilityRange(Version startingVersion) { this(startingVersion, true, null, false); } @@ -125,7 +125,7 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) { return false; } - VersionRange other = (VersionRange) obj; + CompatibilityRange other = (CompatibilityRange) obj; if (this.higherInclusive != other.higherInclusive) { return false; } diff --git a/initializr-generator/src/main/java/io/spring/initializr/generator/version/VersionParser.java b/initializr-generator/src/main/java/io/spring/initializr/generator/version/VersionParser.java index 3567ea2535..c63a881876 100644 --- a/initializr-generator/src/main/java/io/spring/initializr/generator/version/VersionParser.java +++ b/initializr-generator/src/main/java/io/spring/initializr/generator/version/VersionParser.java @@ -28,8 +28,8 @@ import org.springframework.util.StringUtils; /** - * Parser for {@link Version} and {@link VersionRange} that allows to resolve the minor - * and patch value against a configurable list of "latest versions". + * Parser for {@link Version} and {@link CompatibilityRange} that allows to resolve the + * minor and patch value against a configurable list of "latest versions". *

* For example a parser that is configured with {@code 1.3.7.RELEASE} and * {@code 1.4.2.RELEASE} as latest versions can parse {@code 1.3.x.RELEASE} to @@ -117,25 +117,25 @@ public Version safeParse(String text) { } /** - * Parse the string representation of a {@link VersionRange}. Throws an + * Parse the string representation of a {@link CompatibilityRange}. Throws an * {@link InvalidVersionException} if the range could not be parsed. * @param text the range text - * @return a VersionRange instance for the specified range text + * @return a CompatibilityRange instance for the specified range text * @throws InvalidVersionException if the range text could not be parsed */ - public VersionRange parseRange(String text) { + public CompatibilityRange parseRange(String text) { Assert.notNull(text, "Text must not be null"); Matcher matcher = RANGE_REGEX.matcher(text.trim()); if (!matcher.matches()) { // Try to read it as simple string Version version = parse(text); - return new VersionRange(version, true, null, true); + return new CompatibilityRange(version, true, null, true); } boolean lowerInclusive = matcher.group(1).equals("["); Version lowerVersion = parse(matcher.group(2)); Version higherVersion = parse(matcher.group(3)); boolean higherInclusive = matcher.group(4).equals("]"); - return new VersionRange(lowerVersion, lowerInclusive, higherVersion, higherInclusive); + return new CompatibilityRange(lowerVersion, lowerInclusive, higherVersion, higherInclusive); } private Version findLatestVersion(Integer major, Integer minor, Version.Qualifier qualifier) { diff --git a/initializr-generator/src/test/java/io/spring/initializr/generator/version/VersionRangeTests.java b/initializr-generator/src/test/java/io/spring/initializr/generator/version/CompatibilityRangeTests.java similarity index 78% rename from initializr-generator/src/test/java/io/spring/initializr/generator/version/VersionRangeTests.java rename to initializr-generator/src/test/java/io/spring/initializr/generator/version/CompatibilityRangeTests.java index 1d68de4876..f287df2b14 100755 --- a/initializr-generator/src/test/java/io/spring/initializr/generator/version/VersionRangeTests.java +++ b/initializr-generator/src/test/java/io/spring/initializr/generator/version/CompatibilityRangeTests.java @@ -27,11 +27,11 @@ /** * @author Stephane Nicoll */ -class VersionRangeTests { +class CompatibilityRangeTests { @Test void simpleStartingRange() { - assertThat(new VersionRange(Version.parse("1.3.0.RELEASE")).toString()).isEqualTo(">=1.3.0.RELEASE"); + assertThat(new CompatibilityRange(Version.parse("1.3.0.RELEASE")).toString()).isEqualTo(">=1.3.0.RELEASE"); } @Test @@ -114,36 +114,36 @@ void matchOverAsOfCurrentVersion() { } @Test - void toVersionRangeWithSimpleVersion() { - VersionRange range = new VersionParser(Collections.singletonList(Version.parse("1.5.6.RELEASE"))) + void toCompatibilityRangeWithSimpleVersion() { + CompatibilityRange range = new VersionParser(Collections.singletonList(Version.parse("1.5.6.RELEASE"))) .parseRange("1.3.5.RELEASE"); assertThat(range.toRangeString()).isEqualTo("1.3.5.RELEASE"); } @Test - void toVersionRangeWithVersionsIncluded() { - VersionRange range = new VersionParser(Collections.singletonList(Version.parse("1.5.6.RELEASE"))) + void toCompatibilityRangeWithVersionsIncluded() { + CompatibilityRange range = new VersionParser(Collections.singletonList(Version.parse("1.5.6.RELEASE"))) .parseRange("[1.3.5.RELEASE,1.5.5.RELEASE]"); assertThat(range.toRangeString()).isEqualTo("[1.3.5.RELEASE,1.5.5.RELEASE]"); } @Test - void toVersionRangeWithLowerVersionExcluded() { - VersionRange range = new VersionParser(Collections.singletonList(Version.parse("1.5.6.RELEASE"))) + void toCompatibilityRangeWithLowerVersionExcluded() { + CompatibilityRange range = new VersionParser(Collections.singletonList(Version.parse("1.5.6.RELEASE"))) .parseRange("(1.3.5.RELEASE,1.5.5.RELEASE]"); assertThat(range.toRangeString()).isEqualTo("(1.3.5.RELEASE,1.5.5.RELEASE]"); } @Test - void toVersionRangeWithHigherVersionExcluded() { - VersionRange range = new VersionParser(Collections.singletonList(Version.parse("1.5.6.RELEASE"))) + void toCompatibilityRangeWithHigherVersionExcluded() { + CompatibilityRange range = new VersionParser(Collections.singletonList(Version.parse("1.5.6.RELEASE"))) .parseRange("[1.3.5.RELEASE,1.5.5.RELEASE)"); assertThat(range.toRangeString()).isEqualTo("[1.3.5.RELEASE,1.5.5.RELEASE)"); } @Test - void toVersionRangeWithVersionsExcluded() { - VersionRange range = new VersionParser(Collections.singletonList(Version.parse("1.5.6.RELEASE"))) + void toCompatibilityRangeWithVersionsExcluded() { + CompatibilityRange range = new VersionParser(Collections.singletonList(Version.parse("1.5.6.RELEASE"))) .parseRange("(1.3.5.RELEASE,1.5.5.RELEASE)"); assertThat(range.toRangeString()).isEqualTo("(1.3.5.RELEASE,1.5.5.RELEASE)"); } @@ -153,16 +153,16 @@ private static Condition match(String range) { } private static Condition match(String range, VersionParser parser) { - return new VersionRangeCondition(range, parser); + return new CompatibilityRangeCondition(range, parser); } - static class VersionRangeCondition extends Condition { + static class CompatibilityRangeCondition extends Condition { - private final VersionRange range; + private final CompatibilityRange range; private final VersionParser parser; - VersionRangeCondition(String text, VersionParser parser) { + CompatibilityRangeCondition(String text, VersionParser parser) { this.parser = parser; this.range = parser.parseRange(text); as(this.range.toString()); diff --git a/initializr-generator/src/test/resources/application-test-default.yml b/initializr-generator/src/test/resources/application-test-default.yml index 6e573506f9..b8707f951a 100644 --- a/initializr-generator/src/test/resources/application-test-default.yml +++ b/initializr-generator/src/test/resources/application-test-default.yml @@ -11,10 +11,10 @@ initializr: versionProperty: my-api.version additionalBoms: ['my-api-dependencies-bom'] mappings: - - versionRange: "[2.0.0.RELEASE,2.1.6.RELEASE)" + - compatibilityRange: "[2.0.0.RELEASE,2.1.6.RELEASE)" version: 1.0.0.RELEASE repositories: my-api-repo-1 - - versionRange: "2.2.1.RELEASE" + - compatibilityRange: "2.2.1.RELEASE" version: 2.0.0.RELEASE repositories: my-api-repo-2 my-api-dependencies-bom: @@ -25,9 +25,9 @@ initializr: kotlin: defaultVersion: 1.2 mappings: - - versionRange: "[1.5.0.RELEASE,2.0.0.M1)" + - compatibilityRange: "[1.5.0.RELEASE,2.0.0.M1)" version: 1.0 - - versionRange: "[2.0.0.M1,2.1.0.M1)" + - compatibilityRange: "[2.0.0.M1,2.1.0.M1)" version: 1.1 repositories: my-api-repo-1: @@ -85,12 +85,12 @@ initializr: artifactId: biz scope: runtime version: 1.3.5 - versionRange: 2.2.0.BUILD-SNAPSHOT + compatibilityRange: 2.2.0.BUILD-SNAPSHOT - name: Bur id: org.acme:bur version: 2.1.0 scope: test - versionRange: "[2.1.4.RELEASE,2.2.0.BUILD-SNAPSHOT)" + compatibilityRange: "[2.1.4.RELEASE,2.2.0.BUILD-SNAPSHOT)" - name: My API id : my-api groupId: org.acme diff --git a/initializr-metadata/src/main/java/io/spring/initializr/metadata/BillOfMaterials.java b/initializr-metadata/src/main/java/io/spring/initializr/metadata/BillOfMaterials.java index b7f71913e9..e228782324 100644 --- a/initializr-metadata/src/main/java/io/spring/initializr/metadata/BillOfMaterials.java +++ b/initializr-metadata/src/main/java/io/spring/initializr/metadata/BillOfMaterials.java @@ -22,11 +22,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; +import io.spring.initializr.generator.version.CompatibilityRange; import io.spring.initializr.generator.version.InvalidVersionException; import io.spring.initializr.generator.version.Version; import io.spring.initializr.generator.version.VersionParser; import io.spring.initializr.generator.version.VersionProperty; -import io.spring.initializr.generator.version.VersionRange; /** * Define a Bill Of Materials to be represented in the generated project if a dependency @@ -160,17 +160,17 @@ public void validate() { if (this.version == null && this.mappings.isEmpty()) { throw new InvalidInitializrMetadataException("No version available for " + this); } - updateVersionRange(VersionParser.DEFAULT); + updateCompatibilityRange(VersionParser.DEFAULT); } - public void updateVersionRange(VersionParser versionParser) { + public void updateCompatibilityRange(VersionParser versionParser) { this.mappings.forEach((it) -> { try { - it.range = versionParser.parseRange(it.versionRange); + it.range = versionParser.parseRange(it.compatibilityRange); } catch (InvalidVersionException ex) { throw new InvalidInitializrMetadataException( - "Invalid version range " + it.versionRange + " for " + this, ex); + "Invalid compatibility range " + it.compatibilityRange + " for " + this, ex); } }); } @@ -229,7 +229,7 @@ public static BillOfMaterials create(String groupId, String artifactId, String v @JsonInclude(JsonInclude.Include.NON_EMPTY) public static class Mapping { - private String versionRange; + private String compatibilityRange; /** * The groupId to use for this mapping or {@code null} to use the default. @@ -248,18 +248,18 @@ public static class Mapping { private List additionalBoms = new ArrayList<>(); @JsonIgnore - private VersionRange range; + private CompatibilityRange range; public Mapping() { } private Mapping(String range, String version, String... repositories) { - this.versionRange = range; + this.compatibilityRange = range; this.version = version; this.repositories.addAll(Arrays.asList(repositories)); } - public String determineVersionRangeRequirement() { + public String determineCompatibilityRangeRequirement() { return this.range.toString(); } @@ -271,12 +271,12 @@ public static Mapping create(String range, String version, String... repositorie return new Mapping(range, version, repositories); } - public String getVersionRange() { - return this.versionRange; + public String getCompatibilityRange() { + return this.compatibilityRange; } - public void setVersionRange(String versionRange) { - this.versionRange = versionRange; + public void setCompatibilityRange(String compatibilityRange) { + this.compatibilityRange = compatibilityRange; } public String getGroupId() { @@ -311,7 +311,7 @@ public List getAdditionalBoms() { return this.additionalBoms; } - public VersionRange getRange() { + public CompatibilityRange getRange() { return this.range; } @@ -323,13 +323,14 @@ public void setAdditionalBoms(List additionalBoms) { this.additionalBoms = additionalBoms; } - public void setRange(VersionRange range) { + public void setRange(CompatibilityRange range) { this.range = range; } @Override public String toString() { - return "Mapping [" + ((this.versionRange != null) ? "versionRange=" + this.versionRange + ", " : "") + return "Mapping [" + + ((this.compatibilityRange != null) ? "compatibilityRange=" + this.compatibilityRange + ", " : "") + ((this.groupId != null) ? "groupId=" + this.groupId + ", " : "") + ((this.artifactId != null) ? "artifactId=" + this.artifactId + ", " : "") + ((this.version != null) ? "version=" + this.version + ", " : "") diff --git a/initializr-metadata/src/main/java/io/spring/initializr/metadata/DependenciesCapability.java b/initializr-metadata/src/main/java/io/spring/initializr/metadata/DependenciesCapability.java index b18edf6e8a..180ff51015 100644 --- a/initializr-metadata/src/main/java/io/spring/initializr/metadata/DependenciesCapability.java +++ b/initializr-metadata/src/main/java/io/spring/initializr/metadata/DependenciesCapability.java @@ -73,8 +73,8 @@ public void validate() { index(); } - public void updateVersionRange(VersionParser versionParser) { - this.indexedDependencies.values().forEach((it) -> it.updateVersionRanges(versionParser)); + public void updateCompatibilityRange(VersionParser versionParser) { + this.indexedDependencies.values().forEach((it) -> it.updateCompatibilityRange(versionParser)); } @Override @@ -92,8 +92,8 @@ private void index() { this.indexedDependencies.clear(); this.content.forEach((group) -> group.content.forEach((dependency) -> { // Apply defaults - if (dependency.getVersionRange() == null && group.getVersionRange() != null) { - dependency.setVersionRange(group.getVersionRange()); + if (dependency.getCompatibilityRange() == null && group.getCompatibilityRange() != null) { + dependency.setCompatibilityRange(group.getCompatibilityRange()); } if (dependency.getBom() == null && group.getBom() != null) { dependency.setBom(group.getBom()); diff --git a/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java b/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java index cb65ae73f9..31051ca2fe 100644 --- a/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java +++ b/initializr-metadata/src/main/java/io/spring/initializr/metadata/Dependency.java @@ -24,10 +24,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; +import io.spring.initializr.generator.version.CompatibilityRange; import io.spring.initializr.generator.version.InvalidVersionException; import io.spring.initializr.generator.version.Version; import io.spring.initializr.generator.version.VersionParser; -import io.spring.initializr.generator.version.VersionRange; import org.springframework.util.StringUtils; @@ -94,13 +94,13 @@ public class Dependency extends MetadataElement implements Describable { private String description; - private String versionRange; + private String compatibilityRange; @JsonIgnore private String versionRequirement; @JsonIgnore - private VersionRange range; + private CompatibilityRange range; private String bom; @@ -133,7 +133,7 @@ public Dependency(Dependency dependency) { this.mappings.addAll(dependency.mappings); this.scope = dependency.scope; this.description = dependency.description; - this.versionRange = dependency.versionRange; + this.compatibilityRange = dependency.compatibilityRange; this.versionRequirement = dependency.versionRequirement; this.range = dependency.range; this.bom = dependency.bom; @@ -151,8 +151,8 @@ public void setScope(String scope) { this.scope = scope; } - public void setVersionRange(String versionRange) { - this.versionRange = (StringUtils.hasText(versionRange) ? versionRange.trim() : null); + public void setCompatibilityRange(String compatibilityRange) { + this.compatibilityRange = (StringUtils.hasText(compatibilityRange) ? compatibilityRange.trim() : null); } /** @@ -209,28 +209,28 @@ else if (st.countTokens() == 2 || st.countTokens() == 3) { } } this.links.forEach(Link::resolve); - updateVersionRanges(VersionParser.DEFAULT); + updateCompatibilityRange(VersionParser.DEFAULT); } - public void updateVersionRanges(VersionParser versionParser) { - if (this.versionRange != null) { + public void updateCompatibilityRange(VersionParser versionParser) { + if (this.compatibilityRange != null) { try { - this.range = versionParser.parseRange(this.versionRange); - this.versionRange = this.range.toRangeString(); + this.range = versionParser.parseRange(this.compatibilityRange); + this.compatibilityRange = this.range.toRangeString(); this.versionRequirement = this.range.toString(); } catch (InvalidVersionException ex) { - throw new InvalidInitializrMetadataException("Invalid version range '" + this.versionRange + " for " - + "dependency with id '" + getId() + "'", ex); + throw new InvalidInitializrMetadataException("Invalid compatibility range '" + this.compatibilityRange + + " for " + "dependency with id '" + getId() + "'", ex); } } this.mappings.forEach((it) -> { try { - it.range = versionParser.parseRange(it.versionRange); + it.range = versionParser.parseRange(it.compatibilityRange); } catch (InvalidVersionException ex) { throw new InvalidInitializrMetadataException( - "Invalid version range " + it.versionRange + " for " + this, ex); + "Invalid compatibility range " + it.compatibilityRange + " for " + this, ex); } }); } @@ -371,11 +371,11 @@ public void setVersionRequirement(String versionRequirement) { this.versionRequirement = versionRequirement; } - public VersionRange getRange() { + public CompatibilityRange getRange() { return this.range; } - public void setRange(VersionRange range) { + public void setRange(CompatibilityRange range) { this.range = range; } @@ -431,8 +431,8 @@ public String getScope() { return this.scope; } - public String getVersionRange() { - return this.versionRange; + public String getCompatibilityRange() { + return this.compatibilityRange; } @Override @@ -476,14 +476,14 @@ public static Dependency withId(String id) { } /** - * Map several attribute of the dependency for a given version range. + * Map several attribute of the dependency for a given compatibility range. */ public static class Mapping { /** - * The version range of this mapping. + * The compatibility range of this mapping. */ - private String versionRange; + private String compatibilityRange; /** * The version to use for this mapping or {@code null} to use the default. @@ -506,7 +506,7 @@ public static class Mapping { private Boolean starter; @JsonIgnore - private VersionRange range; + private CompatibilityRange range; public String getGroupId() { return this.groupId; @@ -540,21 +540,21 @@ public void setStarter(Boolean starter) { this.starter = starter; } - public VersionRange getRange() { + public CompatibilityRange getRange() { return this.range; } - public String getVersionRange() { - return this.versionRange; + public String getCompatibilityRange() { + return this.compatibilityRange; } - public void setVersionRange(String versionRange) { - this.versionRange = versionRange; + public void setCompatibilityRange(String compatibilityRange) { + this.compatibilityRange = compatibilityRange; } public static Mapping create(String range, String groupId, String artifactId, String version, Boolean starter) { Mapping mapping = new Mapping(); - mapping.versionRange = range; + mapping.compatibilityRange = range; mapping.groupId = groupId; mapping.artifactId = artifactId; mapping.version = version; diff --git a/initializr-metadata/src/main/java/io/spring/initializr/metadata/DependencyGroup.java b/initializr-metadata/src/main/java/io/spring/initializr/metadata/DependencyGroup.java index 34b3a28665..08b27a9196 100644 --- a/initializr-metadata/src/main/java/io/spring/initializr/metadata/DependencyGroup.java +++ b/initializr-metadata/src/main/java/io/spring/initializr/metadata/DependencyGroup.java @@ -31,7 +31,7 @@ public class DependencyGroup { private String name; @JsonIgnore - private String versionRange; + private String compatibilityRange; @JsonIgnore private String bom; @@ -54,16 +54,16 @@ public void setName(String name) { } /** - * Return the default version range to apply to all dependencies of this group unless - * specified otherwise. - * @return the version range + * Return the default compatibility range to apply to all dependencies of this group + * unless specified otherwise. + * @return the compatibility range */ - public String getVersionRange() { - return this.versionRange; + public String getCompatibilityRange() { + return this.compatibilityRange; } - public void setVersionRange(String versionRange) { - this.versionRange = versionRange; + public void setCompatibilityRange(String compatibilityRange) { + this.compatibilityRange = compatibilityRange; } /** diff --git a/initializr-metadata/src/main/java/io/spring/initializr/metadata/InitializrConfiguration.java b/initializr-metadata/src/main/java/io/spring/initializr/metadata/InitializrConfiguration.java index a6fea68211..bc87686ac9 100644 --- a/initializr-metadata/src/main/java/io/spring/initializr/metadata/InitializrConfiguration.java +++ b/initializr-metadata/src/main/java/io/spring/initializr/metadata/InitializrConfiguration.java @@ -26,10 +26,10 @@ import java.util.Map; import com.fasterxml.jackson.annotation.JsonIgnore; +import io.spring.initializr.generator.version.CompatibilityRange; import io.spring.initializr.generator.version.InvalidVersionException; import io.spring.initializr.generator.version.Version; import io.spring.initializr.generator.version.VersionParser; -import io.spring.initializr.generator.version.VersionRange; import org.springframework.boot.context.properties.NestedConfigurationProperty; import org.springframework.util.StringUtils; @@ -413,11 +413,11 @@ public List getMappings() { public void validate() { VersionParser simpleParser = new VersionParser(Collections.emptyList()); this.mappings.forEach((m) -> { - if (m.versionRange == null) { + if (m.compatibilityRange == null) { throw new InvalidInitializrMetadataException( - "VersionRange is mandatory, invalid version mapping for " + this); + "CompatibilityRange is mandatory, invalid version mapping for " + this); } - m.range = simpleParser.parseRange(m.versionRange); + m.range = simpleParser.parseRange(m.compatibilityRange); if (m.version == null) { throw new InvalidInitializrMetadataException( "Version is mandatory, invalid version mapping for " + this); @@ -425,14 +425,14 @@ public void validate() { }); } - public void updateVersionRange(VersionParser versionParser) { + public void updateCompatibilityRange(VersionParser versionParser) { this.mappings.forEach((it) -> { try { - it.range = versionParser.parseRange(it.versionRange); + it.range = versionParser.parseRange(it.compatibilityRange); } catch (InvalidVersionException ex) { throw new InvalidInitializrMetadataException( - "Invalid version range " + it.versionRange + " for " + this, ex); + "Invalid compatibility range " + it.compatibilityRange + " for " + this, ex); } }); } @@ -444,14 +444,16 @@ private void merge(Kotlin other) { } /** - * Map several attribute of the dependency for a given version range. + * Map several attribute of the dependency for a given compatibility range. */ public static class Mapping { /** - * The version range of this mapping. + * The compatibility range of this mapping. */ - private String versionRange; + // private String versionRange; + + private String compatibilityRange; /** * The kotlin version for this mapping. @@ -459,15 +461,24 @@ public static class Mapping { private String version; @JsonIgnore - private VersionRange range; + private CompatibilityRange range; + + // @Deprecated + // public String getCompatibilityRange() { + // return this.versionRange; + // } - public String getVersionRange() { - return this.versionRange; + public String getCompatibilityRange() { + return this.compatibilityRange; } - public void setVersionRange(String versionRange) { - this.versionRange = versionRange; + public void setCompatibilityRange(String compatibilityRange) { + this.compatibilityRange = compatibilityRange; } + // @Deprecated + // public void setCompatibilityRange(String versionRange) { + // this.versionRange = versionRange; + // } public String getVersion() { return this.version; diff --git a/initializr-metadata/src/main/java/io/spring/initializr/metadata/InitializrMetadata.java b/initializr-metadata/src/main/java/io/spring/initializr/metadata/InitializrMetadata.java index 345370eecf..3c94b80120 100644 --- a/initializr-metadata/src/main/java/io/spring/initializr/metadata/InitializrMetadata.java +++ b/initializr-metadata/src/main/java/io/spring/initializr/metadata/InitializrMetadata.java @@ -205,9 +205,9 @@ public void updateSpringBootVersions(List versionsMetada List bootVersions = this.bootVersions.getContent().stream().map((it) -> Version.parse(it.getId())) .collect(Collectors.toList()); VersionParser parser = new VersionParser(bootVersions); - this.dependencies.updateVersionRange(parser); - this.configuration.getEnv().getBoms().values().forEach((it) -> it.updateVersionRange(parser)); - this.configuration.getEnv().getKotlin().updateVersionRange(parser); + this.dependencies.updateCompatibilityRange(parser); + this.configuration.getEnv().getBoms().values().forEach((it) -> it.updateCompatibilityRange(parser)); + this.configuration.getEnv().getKotlin().updateCompatibilityRange(parser); } /** diff --git a/initializr-metadata/src/test/java/io/spring/initializr/metadata/BillOfMaterialsTests.java b/initializr-metadata/src/test/java/io/spring/initializr/metadata/BillOfMaterialsTests.java index 7303446026..659eb9ea13 100755 --- a/initializr-metadata/src/test/java/io/spring/initializr/metadata/BillOfMaterialsTests.java +++ b/initializr-metadata/src/test/java/io/spring/initializr/metadata/BillOfMaterialsTests.java @@ -130,12 +130,12 @@ void resolveRangeWithVariablePatch() { bom.getMappings().add(BillOfMaterials.Mapping.create("[1.3.x.BUILD-SNAPSHOT,1.4.0.RELEASE)", "1.1.1-SNAPSHOT")); bom.validate(); - bom.updateVersionRange(new VersionParser( + bom.updateCompatibilityRange(new VersionParser( Arrays.asList(Version.parse("1.3.8.RELEASE"), Version.parse("1.3.9.BUILD-SNAPSHOT")))); assertThat(bom.resolve(Version.parse("1.3.8.RELEASE")).getVersion()).isEqualTo("1.1.0"); assertThat(bom.resolve(Version.parse("1.3.9.RELEASE")).getVersion()).isEqualTo("1.1.1-SNAPSHOT"); - bom.updateVersionRange(new VersionParser( + bom.updateCompatibilityRange(new VersionParser( Arrays.asList(Version.parse("1.3.9.RELEASE"), Version.parse("1.3.10.BUILD-SNAPSHOT")))); assertThat(bom.resolve(Version.parse("1.3.8.RELEASE")).getVersion()).isEqualTo("1.1.0"); assertThat(bom.resolve(Version.parse("1.3.9.RELEASE")).getVersion()).isEqualTo("1.1.0"); diff --git a/initializr-metadata/src/test/java/io/spring/initializr/metadata/DependenciesCapabilityTests.java b/initializr-metadata/src/test/java/io/spring/initializr/metadata/DependenciesCapabilityTests.java index e3009f1ca6..7c52e3107c 100755 --- a/initializr-metadata/src/test/java/io/spring/initializr/metadata/DependenciesCapabilityTests.java +++ b/initializr-metadata/src/test/java/io/spring/initializr/metadata/DependenciesCapabilityTests.java @@ -90,19 +90,19 @@ void mergeAddEntry() { } @Test - void addDefaultVersionRange() { + void addDefaultCompatibilityRange() { Dependency first = Dependency.withId("first"); Dependency second = Dependency.withId("second"); - second.setVersionRange("1.2.3.RELEASE"); + second.setCompatibilityRange("1.2.3.RELEASE"); DependencyGroup group = createDependencyGroup("test", first, second); - group.setVersionRange("1.2.0.RELEASE"); + group.setCompatibilityRange("1.2.0.RELEASE"); DependenciesCapability capability = new DependenciesCapability(); capability.getContent().add(group); capability.validate(); - assertThat(capability.get("first").getVersionRange()).isEqualTo("1.2.0.RELEASE"); - assertThat(capability.get("second").getVersionRange()).isEqualTo("1.2.3.RELEASE"); + assertThat(capability.get("first").getCompatibilityRange()).isEqualTo("1.2.0.RELEASE"); + assertThat(capability.get("second").getCompatibilityRange()).isEqualTo("1.2.3.RELEASE"); } @Test diff --git a/initializr-metadata/src/test/java/io/spring/initializr/metadata/DependencyTests.java b/initializr-metadata/src/test/java/io/spring/initializr/metadata/DependencyTests.java index 5f468cba2c..dd56a496b9 100755 --- a/initializr-metadata/src/test/java/io/spring/initializr/metadata/DependencyTests.java +++ b/initializr-metadata/src/test/java/io/spring/initializr/metadata/DependencyTests.java @@ -107,7 +107,7 @@ void invalidDependencyScope() { @Test void invalidSpringBootRange() { Dependency dependency = Dependency.withId("web"); - dependency.setVersionRange("A.B.C"); + dependency.setCompatibilityRange("A.B.C"); assertThatExceptionOfType(InvalidInitializrMetadataException.class).isThrownBy(dependency::resolve) .withMessageContaining("A.B.C"); } @@ -219,7 +219,7 @@ void resolveMatchingVersionWithVariablePatch() { Dependency.Mapping.create("[1.1.x.BUILD-SNAPSHOT, 1.2.0.RELEASE)", null, null, "0.2.0.RELEASE", null)); dependency.resolve(); - dependency.updateVersionRanges(new VersionParser( + dependency.updateCompatibilityRange(new VersionParser( Arrays.asList(Version.parse("1.1.5.RELEASE"), Version.parse("1.1.6.BUILD-SNAPSHOT")))); validateResolvedWebDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "org.springframework.boot", "spring-boot-starter-web", "0.1.0.RELEASE", true); @@ -228,7 +228,7 @@ void resolveMatchingVersionWithVariablePatch() { validateResolvedWebDependency(dependency.resolve(Version.parse("2.1.3.M1")), "org.springframework.boot", "spring-boot-starter-web", "0.3.0.RELEASE", true); // default - dependency.updateVersionRanges(new VersionParser( + dependency.updateCompatibilityRange(new VersionParser( Arrays.asList(Version.parse("1.1.6.RELEASE"), Version.parse("1.1.7.BUILD-SNAPSHOT")))); validateResolvedWebDependency(dependency.resolve(Version.parse("1.1.5.RELEASE")), "org.springframework.boot", "spring-boot-starter-web", "0.1.0.RELEASE", true); @@ -278,17 +278,17 @@ void resolveMatchingWithMappingThatEnablesStarter() { @Test void resolveVersionWithX() { Dependency dependency1 = Dependency.withId("foo1", "com.acme", "foo1", "0.3.0.RELEASE"); - dependency1.setVersionRange("1.2.x.RELEASE"); + dependency1.setCompatibilityRange("1.2.x.RELEASE"); dependency1.resolve(); - assertThat(dependency1.getVersionRange()).isEqualTo("1.2.999.RELEASE"); + assertThat(dependency1.getCompatibilityRange()).isEqualTo("1.2.999.RELEASE"); } @Test - void resolveVersionRangeWithX() { + void resolveCompatibilityRangeWithX() { Dependency dependency = Dependency.withId("foo1", "com.acme", "foo1", "0.3.0.RELEASE"); - dependency.setVersionRange("[1.1.0.RELEASE, 1.2.x.RELEASE)"); + dependency.setCompatibilityRange("[1.1.0.RELEASE, 1.2.x.RELEASE)"); dependency.resolve(); - assertThat(dependency.getVersionRange()).isEqualTo("[1.1.0.RELEASE,1.2.999.RELEASE)"); + assertThat(dependency.getCompatibilityRange()).isEqualTo("[1.1.0.RELEASE,1.2.999.RELEASE)"); } private static void validateResolvedWebDependency(Dependency dependency, String expectedGroupId, diff --git a/initializr-metadata/src/test/java/io/spring/initializr/metadata/InitializrConfigurationTests.java b/initializr-metadata/src/test/java/io/spring/initializr/metadata/InitializrConfigurationTests.java index 47081cc9ea..523e0e0202 100755 --- a/initializr-metadata/src/test/java/io/spring/initializr/metadata/InitializrConfigurationTests.java +++ b/initializr-metadata/src/test/java/io/spring/initializr/metadata/InitializrConfigurationTests.java @@ -196,9 +196,9 @@ void resolveKotlinVersionUsingDefault() { assertThat(kotlin.resolveKotlinVersion(Version.parse("1.3.2.RELEASE"))).isEqualTo("1.2.3"); } - private Kotlin.Mapping createKotlinVersionMapping(String versionRange, String kotlinVersion) { + private Kotlin.Mapping createKotlinVersionMapping(String compatibilityRange, String kotlinVersion) { Kotlin.Mapping mapping = new Kotlin.Mapping(); - mapping.setVersionRange(versionRange); + mapping.setCompatibilityRange(compatibilityRange); mapping.setVersion(kotlinVersion); return mapping; } diff --git a/initializr-metadata/src/test/java/io/spring/initializr/metadata/InitializrMetadataTests.java b/initializr-metadata/src/test/java/io/spring/initializr/metadata/InitializrMetadataTests.java index 9b0b2062a0..0184f2282b 100755 --- a/initializr-metadata/src/test/java/io/spring/initializr/metadata/InitializrMetadataTests.java +++ b/initializr-metadata/src/test/java/io/spring/initializr/metadata/InitializrMetadataTests.java @@ -92,7 +92,7 @@ void invalidBomUnknownAdditionalBom() { } @Test - void invalidBomVersionRangeMapping() { + void invalidBomCompatibilityRangeMapping() { InitializrMetadata metadata = initializeMetadata(); BillOfMaterials bom = BillOfMaterials.create("org.acme", "foo-bom"); bom.getMappings().add(Mapping.create("[1.2.0.RELEASE,1.3.0.M1)", "1.0.0")); @@ -103,7 +103,7 @@ void invalidBomVersionRangeMapping() { } @Test - void invalidBomVersionRangeMappingUnknownRepo() { + void invalidBomCompatibilityRangeMappingUnknownRepo() { InitializrMetadata metadata = initializeMetadata(); BillOfMaterials bom = BillOfMaterials.create("org.acme", "foo-bom"); bom.getMappings().add(Mapping.create("[1.0.0.RELEASE,1.3.0.M1)", "1.0.0")); @@ -117,7 +117,7 @@ void invalidBomVersionRangeMappingUnknownRepo() { } @Test - void invalidBomVersionRangeMappingUnknownAdditionalBom() { + void invalidBomCompatibilityRangeMappingUnknownAdditionalBom() { InitializrMetadata metadata = initializeMetadata(); BillOfMaterials bom = BillOfMaterials.create("org.acme", "foo-bom"); bom.getMappings().add(Mapping.create("[1.0.0.RELEASE,1.3.0.M1)", "1.0.0")); @@ -201,9 +201,9 @@ private void addTestDependencyGroup(InitializrMetadata metadata, Dependency... d metadata.getDependencies().getContent().add(group); } - private Kotlin.Mapping createKotlinVersionMapping(String versionRange, String kotlinVersion) { + private Kotlin.Mapping createKotlinVersionMapping(String compatibilityRange, String kotlinVersion) { Kotlin.Mapping mapping = new Kotlin.Mapping(); - mapping.setVersionRange(versionRange); + mapping.setCompatibilityRange(compatibilityRange); mapping.setVersion(kotlinVersion); return mapping; } diff --git a/initializr-metadata/src/test/java/io/spring/initializr/metadata/support/MetadataBuildItemResolverTests.java b/initializr-metadata/src/test/java/io/spring/initializr/metadata/support/MetadataBuildItemResolverTests.java index 6e48bce6c5..2b36dfebd0 100644 --- a/initializr-metadata/src/test/java/io/spring/initializr/metadata/support/MetadataBuildItemResolverTests.java +++ b/initializr-metadata/src/test/java/io/spring/initializr/metadata/support/MetadataBuildItemResolverTests.java @@ -57,7 +57,7 @@ void resoleDependencyWithMatchingEntry() { } @Test - void resoleDependencyWithMatchingEntryAndVersionRange() { + void resoleDependencyWithMatchingEntryAndCompatibilityRange() { InitializrMetadata metadata = new InitializrMetadata(); DependencyGroup group = DependencyGroup.create("test"); Dependency dependency = Dependency.withId("test-dep", "com.example", "test"); @@ -102,7 +102,7 @@ void resoleBomWithMatchingEntry() { } @Test - void resoleBomWithMatchingEntryAndVersionRange() throws MalformedURLException { + void resoleBomWithMatchingEntryAndCompatibilityRange() throws MalformedURLException { InitializrMetadata metadata = new InitializrMetadata(); BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "0.0.1"); bom.getMappings().add(BillOfMaterials.Mapping.create("[1.0.0.RELEASE, 2.0.0.RELEASE)", "1.0.0")); diff --git a/initializr-metadata/src/test/resources/application-test-default.yml b/initializr-metadata/src/test/resources/application-test-default.yml index 6e573506f9..b8707f951a 100644 --- a/initializr-metadata/src/test/resources/application-test-default.yml +++ b/initializr-metadata/src/test/resources/application-test-default.yml @@ -11,10 +11,10 @@ initializr: versionProperty: my-api.version additionalBoms: ['my-api-dependencies-bom'] mappings: - - versionRange: "[2.0.0.RELEASE,2.1.6.RELEASE)" + - compatibilityRange: "[2.0.0.RELEASE,2.1.6.RELEASE)" version: 1.0.0.RELEASE repositories: my-api-repo-1 - - versionRange: "2.2.1.RELEASE" + - compatibilityRange: "2.2.1.RELEASE" version: 2.0.0.RELEASE repositories: my-api-repo-2 my-api-dependencies-bom: @@ -25,9 +25,9 @@ initializr: kotlin: defaultVersion: 1.2 mappings: - - versionRange: "[1.5.0.RELEASE,2.0.0.M1)" + - compatibilityRange: "[1.5.0.RELEASE,2.0.0.M1)" version: 1.0 - - versionRange: "[2.0.0.M1,2.1.0.M1)" + - compatibilityRange: "[2.0.0.M1,2.1.0.M1)" version: 1.1 repositories: my-api-repo-1: @@ -85,12 +85,12 @@ initializr: artifactId: biz scope: runtime version: 1.3.5 - versionRange: 2.2.0.BUILD-SNAPSHOT + compatibilityRange: 2.2.0.BUILD-SNAPSHOT - name: Bur id: org.acme:bur version: 2.1.0 scope: test - versionRange: "[2.1.4.RELEASE,2.2.0.BUILD-SNAPSHOT)" + compatibilityRange: "[2.1.4.RELEASE,2.2.0.BUILD-SNAPSHOT)" - name: My API id : my-api groupId: org.acme diff --git a/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataV21JsonMapper.java b/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataV21JsonMapper.java index 2cd778899c..2b81f72342 100644 --- a/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataV21JsonMapper.java +++ b/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataV21JsonMapper.java @@ -55,8 +55,8 @@ protected ObjectNode links(ObjectNode parent, List types, String appUrl) { @Override protected ObjectNode mapDependency(Dependency dependency) { ObjectNode content = mapValue(dependency); - if (dependency.getVersionRange() != null) { - content.put("versionRange", dependency.getVersionRange()); + if (dependency.getCompatibilityRange() != null) { + content.put("versionRange", dependency.getCompatibilityRange()); } if (dependency.getLinks() != null && !dependency.getLinks().isEmpty()) { content.set("_links", LinkMapper.mapLinks(dependency.getLinks())); diff --git a/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataV22JsonMapper.java b/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataV22JsonMapper.java new file mode 100644 index 0000000000..779edaefc8 --- /dev/null +++ b/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataV22JsonMapper.java @@ -0,0 +1,44 @@ +/* + * Copyright 2012-2019 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. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.initializr.web.mapper; + +import com.fasterxml.jackson.databind.node.ObjectNode; +import io.spring.initializr.metadata.Dependency; + +/** + * A {@link InitializrMetadataJsonMapper} handling the metadata format for v2.2 + *

+ * Version 2.2 updates the "versionRange" to "compatibilityRange" for better + * clarification. + * + * @author HaiTao Zhang + */ +public class InitializrMetadataV22JsonMapper extends InitializrMetadataV21JsonMapper { + + @Override + protected ObjectNode mapDependency(Dependency dependency) { + ObjectNode content = mapValue(dependency); + if (dependency.getCompatibilityRange() != null) { + content.put("compatibilityRange", dependency.getCompatibilityRange()); + } + if (dependency.getLinks() != null && !dependency.getLinks().isEmpty()) { + content.set("_links", LinkMapper.mapLinks(dependency.getLinks())); + } + return content; + } + +} diff --git a/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataV2JsonMapper.java b/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataV2JsonMapper.java index cedd44c1d2..a45bc58966 100644 --- a/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataV2JsonMapper.java +++ b/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataV2JsonMapper.java @@ -173,8 +173,8 @@ protected ObjectNode mapDependencyGroup(DependencyGroup group) { } protected ObjectNode mapDependency(Dependency dependency) { - if (dependency.getVersionRange() == null) { - // only map the dependency if no versionRange is set + if (dependency.getCompatibilityRange() == null) { + // only map the dependency if no compatibilityRange is set return mapValue(dependency); } return null; diff --git a/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataVersion.java b/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataVersion.java index c03bd7cd49..e2dbf9d3d7 100644 --- a/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataVersion.java +++ b/initializr-web/src/main/java/io/spring/initializr/web/mapper/InitializrMetadataVersion.java @@ -35,7 +35,12 @@ public enum InitializrMetadataVersion { * versions are compatible with it. Also provide a separate "dependencies" endpoint to * query dependencies metadata. */ - V2_1("application/vnd.initializr.v2.1+json"); + V2_1("application/vnd.initializr.v2.1+json"), + + /** + * Renamed "versionRange" attribute to "compatibilityRange" for better clarification. + */ + V2_2("application/vnd.initializr.v2.2+json"); private final MediaType mediaType; diff --git a/initializr-web/src/main/java/io/spring/initializr/web/project/MainController.java b/initializr-web/src/main/java/io/spring/initializr/web/project/MainController.java index 8603d02af9..5e3c2f0ca1 100644 --- a/initializr-web/src/main/java/io/spring/initializr/web/project/MainController.java +++ b/initializr-web/src/main/java/io/spring/initializr/web/project/MainController.java @@ -42,6 +42,7 @@ import io.spring.initializr.web.mapper.DependencyMetadataV21JsonMapper; import io.spring.initializr.web.mapper.InitializrMetadataJsonMapper; import io.spring.initializr.web.mapper.InitializrMetadataV21JsonMapper; +import io.spring.initializr.web.mapper.InitializrMetadataV22JsonMapper; import io.spring.initializr.web.mapper.InitializrMetadataV2JsonMapper; import io.spring.initializr.web.mapper.InitializrMetadataVersion; import io.spring.initializr.web.support.Agent; @@ -150,6 +151,11 @@ public ResponseEntity serviceCapabilitiesHal() { return serviceCapabilitiesFor(InitializrMetadataVersion.V2_1, HAL_JSON_CONTENT_TYPE); } + @RequestMapping(path = { "/", "/metadata/client" }, produces = { "application/vnd.initializr.v2.2+json" }) + public ResponseEntity serviceCapabilitiesV22() { + return serviceCapabilitiesFor(InitializrMetadataVersion.V2_2); + } + @RequestMapping(path = { "/", "/metadata/client" }, produces = { "application/vnd.initializr.v2.1+json", "application/json" }) public ResponseEntity serviceCapabilitiesV21() { @@ -176,8 +182,10 @@ private static InitializrMetadataJsonMapper getJsonMapper(InitializrMetadataVers switch (version) { case V2: return new InitializrMetadataV2JsonMapper(); - default: + case V2_1: return new InitializrMetadataV21JsonMapper(); + default: + return new InitializrMetadataV22JsonMapper(); } } diff --git a/initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerIntegrationTests.java b/initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerIntegrationTests.java index a730f7f02f..603c8df225 100755 --- a/initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerIntegrationTests.java +++ b/initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerIntegrationTests.java @@ -191,6 +191,16 @@ void metadataWithCurrentAcceptHeader() { validateCurrentMetadata(response.getBody()); } + @Test + void metadataWithV22AcceptHeader() { + getRequests().setFields("_links.maven-project", "dependencies.values[0]", "type.values[0]", + "javaVersion.values[0]", "packaging.values[0]", "bootVersion.values[0]", "language.values[0]"); + ResponseEntity response = invokeHome(null, "application/vnd.initializr.v2.2+json"); + assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull(); + validateContentType(response, InitializrMetadataVersion.V2_2.getMediaType()); + validateMetadata(response, InitializrMetadataVersion.V2_2.getMediaType(), "2.2.0", JSONCompareMode.STRICT); + } + @Test void metadataWithSeveralAcceptHeader() { ResponseEntity response = invokeHome(null, "application/vnd.initializr.v2.1+json", diff --git a/initializr-web/src/test/java/io/spring/initializr/web/project/ProjectRequestToDescriptionConverterTests.java b/initializr-web/src/test/java/io/spring/initializr/web/project/ProjectRequestToDescriptionConverterTests.java index 1b61260024..d97fc6cdfa 100644 --- a/initializr-web/src/test/java/io/spring/initializr/web/project/ProjectRequestToDescriptionConverterTests.java +++ b/initializr-web/src/test/java/io/spring/initializr/web/project/ProjectRequestToDescriptionConverterTests.java @@ -21,8 +21,8 @@ import io.spring.initializr.generator.buildsystem.gradle.GradleBuildSystem; import io.spring.initializr.generator.project.ProjectDescription; import io.spring.initializr.generator.spring.test.InitializrMetadataTestBuilder; +import io.spring.initializr.generator.version.CompatibilityRange; import io.spring.initializr.generator.version.Version; -import io.spring.initializr.generator.version.VersionRange; import io.spring.initializr.metadata.Dependency; import io.spring.initializr.metadata.InitializrMetadata; import io.spring.initializr.metadata.Type; @@ -104,7 +104,7 @@ void convertWhenDependencyNotPresentShouldThrowException() { @Test void convertWhenDependencyOutOfRangeShouldThrowException() { Dependency dependency = Dependency.withId("foo"); - dependency.setRange(new VersionRange(Version.parse("2.2.0.M1"))); + dependency.setRange(new CompatibilityRange(Version.parse("2.2.0.M1"))); InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults().addDependencyGroup("foo", dependency) .build(); ProjectRequest request = createProjectRequest(); diff --git a/initializr-web/src/test/java/io/spring/initializr/web/support/CommandLineHelpGeneratorTests.java b/initializr-web/src/test/java/io/spring/initializr/web/support/CommandLineHelpGeneratorTests.java index 6fc094fa77..ea06676d98 100755 --- a/initializr-web/src/test/java/io/spring/initializr/web/support/CommandLineHelpGeneratorTests.java +++ b/initializr-web/src/test/java/io/spring/initializr/web/support/CommandLineHelpGeneratorTests.java @@ -127,13 +127,13 @@ void generateSpringBootCliCapabilities() throws IOException { } @Test - void generateCapabilitiesWithVersionRange() throws IOException { + void generateCapabilitiesWithCompatibilityRange() throws IOException { Dependency first = Dependency.withId("first"); first.setDescription("first desc"); - first.setVersionRange("1.2.0.RELEASE"); + first.setCompatibilityRange("1.2.0.RELEASE"); Dependency second = Dependency.withId("second"); second.setDescription("second desc"); - second.setVersionRange(" [1.2.0.RELEASE,1.3.0.M1) "); + second.setCompatibilityRange(" [1.2.0.RELEASE,1.3.0.M1) "); InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() .addDependencyGroup("test", first, second).build(); String content = this.generator.generateSpringBootCliCapabilities(metadata, "https://fake-service"); diff --git a/initializr-web/src/test/java/io/spring/initializr/web/support/DefaultDependencyMetadataProviderTests.java b/initializr-web/src/test/java/io/spring/initializr/web/support/DefaultDependencyMetadataProviderTests.java index d2e17c3cba..50cf48533a 100755 --- a/initializr-web/src/test/java/io/spring/initializr/web/support/DefaultDependencyMetadataProviderTests.java +++ b/initializr-web/src/test/java/io/spring/initializr/web/support/DefaultDependencyMetadataProviderTests.java @@ -37,10 +37,10 @@ class DefaultDependencyMetadataProviderTests { @Test void filterDependencies() { Dependency first = Dependency.withId("first", "org.foo", "first"); - first.setVersionRange("2.1.4.RELEASE"); + first.setCompatibilityRange("2.1.4.RELEASE"); Dependency second = Dependency.withId("second", "org.foo", "second"); Dependency third = Dependency.withId("third", "org.foo", "third"); - third.setVersionRange("2.1.8.RELEASE"); + third.setCompatibilityRange("2.1.8.RELEASE"); InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults() .addDependencyGroup("test", first, second, third).build(); DependencyMetadata dependencyMetadata = this.provider.get(metadata, Version.parse("2.1.5.RELEASE")); diff --git a/initializr-web/src/test/resources/metadata/config/test-default.json b/initializr-web/src/test/resources/metadata/config/test-default.json index 1a6a0b4fd5..1b4d3953b5 100644 --- a/initializr-web/src/test/resources/metadata/config/test-default.json +++ b/initializr-web/src/test/resources/metadata/config/test-default.json @@ -40,11 +40,11 @@ "defaultVersion": "1.2", "mappings": [ { - "versionRange": "[1.5.0.RELEASE,2.0.0.M1)", + "compatibilityRange": "[1.5.0.RELEASE,2.0.0.M1)", "version": "1.0" }, { - "versionRange": "[2.0.0.M1,2.1.0.M1)", + "compatibilityRange": "[2.0.0.M1,2.1.0.M1)", "version": "1.1" } ] @@ -102,14 +102,14 @@ ], "mappings": [ { - "versionRange": "[2.0.0.RELEASE,2.1.6.RELEASE)", + "compatibilityRange": "[2.0.0.RELEASE,2.1.6.RELEASE)", "repositories": [ "my-api-repo-1" ], "version": "1.0.0.RELEASE" }, { - "versionRange": "2.2.1.RELEASE", + "compatibilityRange": "2.2.1.RELEASE", "repositories": [ "my-api-repo-2" ], @@ -219,7 +219,7 @@ "name": "Biz", "scope": "runtime", "version": "1.3.5", - "versionRange": "2.2.0.BUILD-SNAPSHOT" + "compatibilityRange": "2.2.0.BUILD-SNAPSHOT" }, { "starter": true, @@ -229,7 +229,7 @@ "name": "Bur", "scope": "test", "version": "2.1.0", - "versionRange": "[2.1.4.RELEASE,2.2.0.BUILD-SNAPSHOT)" + "compatibilityRange": "[2.1.4.RELEASE,2.2.0.BUILD-SNAPSHOT)" }, { "starter": true, diff --git a/initializr-web/src/test/resources/metadata/test-default-2.2.0-ssl.json b/initializr-web/src/test/resources/metadata/test-default-2.2.0-ssl.json new file mode 100644 index 0000000000..d4cfc89f1f --- /dev/null +++ b/initializr-web/src/test/resources/metadata/test-default-2.2.0-ssl.json @@ -0,0 +1,232 @@ +{ + "_links": { + "dependencies": { + "href": "https://@host@/dependencies{?bootVersion}", + "templated": true + }, + "maven-build": { + "href": "https://@host@/pom.xml?type=maven-build{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}", + "templated": true + }, + "maven-project": { + "href": "https://@host@/starter.zip?type=maven-project{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}", + "templated": true + }, + "gradle-build": { + "href": "https://@host@/build.gradle?type=gradle-build{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}", + "templated": true + }, + "gradle-project": { + "href": "https://@host@/starter.zip?type=gradle-project{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}", + "templated": true + } + }, + "dependencies": { + "type": "hierarchical-multi-select", + "values": [ + { + "name": "Core", + "values": [ + { + "id": "web", + "name": "Web", + "description": "Web dependency description", + "_links": { + "guide": { + "href": "https://example.com/guide", + "title": "Building a RESTful Web Service" + }, + "reference": { + "href": "https://example.com/doc" + } + } + }, + { + "id": "security", + "name": "Security" + }, + { + "id": "data-jpa", + "name": "Data JPA" + } + ] + }, + { + "name": "Other", + "values": [ + { + "id": "org.acme:foo", + "name": "Foo", + "_links": { + "guide": [ + { + "href": "https://example.com/guide1" + }, + { + "href": "https://example.com/guide2", + "title": "Some guide for foo" + } + ], + "reference": { + "href": "https://example.com/{bootVersion}/doc", + "templated": true + } + } + }, + { + "id": "org.acme:bar", + "name": "Bar" + }, + { + "id": "org.acme:biz", + "name": "Biz", + "compatibilityRange": "2.2.0.BUILD-SNAPSHOT" + }, + { + "id": "org.acme:bur", + "name": "Bur", + "compatibilityRange": "[2.1.4.RELEASE,2.2.0.BUILD-SNAPSHOT)" + }, + { + "id": "my-api", + "name": "My API" + } + ] + } + ] + }, + "type": { + "type": "action", + "default": "maven-project", + "values": [ + { + "id": "maven-build", + "name": "Maven POM", + "action": "/pom.xml", + "tags": { + "build": "maven", + "format": "build" + } + }, + { + "id": "maven-project", + "name": "Maven Project", + "action": "/starter.zip", + "tags": { + "build": "maven", + "format": "project" + } + }, + { + "id": "gradle-build", + "name": "Gradle Config", + "action": "/build.gradle", + "tags": { + "build": "gradle", + "format": "build" + } + }, + { + "id": "gradle-project", + "name": "Gradle Project", + "action": "/starter.zip", + "tags": { + "build": "gradle", + "format": "project" + } + } + ] + }, + "packaging": { + "type": "single-select", + "default": "jar", + "values": [ + { + "id": "jar", + "name": "Jar" + }, + { + "id": "war", + "name": "War" + } + ] + }, + "javaVersion": { + "type": "single-select", + "default": "1.8", + "values": [ + { + "id": "1.6", + "name": "1.6" + }, + { + "id": "1.7", + "name": "1.7" + }, + { + "id": "1.8", + "name": "1.8" + } + ] + }, + "language": { + "type": "single-select", + "default": "java", + "values": [ + { + "id": "groovy", + "name": "Groovy" + }, + { + "id": "java", + "name": "Java" + }, + { + "id": "kotlin", + "name": "Kotlin" + } + ] + }, + "bootVersion": { + "type": "single-select", + "default": "2.1.4.RELEASE", + "values": [ + { + "id": "2.2.0.BUILD-SNAPSHOT", + "name": "Latest SNAPSHOT" + }, + { + "id": "2.1.4.RELEASE", + "name": "2.1.4" + }, + { + "id": "1.5.17.RELEASE", + "name": "1.5.17" + } + ] + }, + "groupId": { + "type": "text", + "default": "com.example" + }, + "artifactId": { + "type": "text", + "default": "demo" + }, + "version": { + "type": "text", + "default": "0.0.1-SNAPSHOT" + }, + "name": { + "type": "text", + "default": "demo" + }, + "description": { + "type": "text", + "default": "Demo project for Spring Boot" + }, + "packageName": { + "type": "text", + "default": "com.example.demo" + } +} \ No newline at end of file diff --git a/initializr-web/src/test/resources/metadata/test-default-2.2.0.json b/initializr-web/src/test/resources/metadata/test-default-2.2.0.json new file mode 100644 index 0000000000..2902985df5 --- /dev/null +++ b/initializr-web/src/test/resources/metadata/test-default-2.2.0.json @@ -0,0 +1,232 @@ +{ + "_links": { + "dependencies": { + "href": "http://@host@/dependencies{?bootVersion}", + "templated": true + }, + "maven-build": { + "href": "http://@host@/pom.xml?type=maven-build{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}", + "templated": true + }, + "maven-project": { + "href": "http://@host@/starter.zip?type=maven-project{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}", + "templated": true + }, + "gradle-build": { + "href": "http://@host@/build.gradle?type=gradle-build{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}", + "templated": true + }, + "gradle-project": { + "href": "http://@host@/starter.zip?type=gradle-project{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}", + "templated": true + } + }, + "dependencies": { + "type": "hierarchical-multi-select", + "values": [ + { + "name": "Core", + "values": [ + { + "id": "web", + "name": "Web", + "description": "Web dependency description", + "_links": { + "guide": { + "href": "https://example.com/guide", + "title": "Building a RESTful Web Service" + }, + "reference": { + "href": "https://example.com/doc" + } + } + }, + { + "id": "security", + "name": "Security" + }, + { + "id": "data-jpa", + "name": "Data JPA" + } + ] + }, + { + "name": "Other", + "values": [ + { + "id": "org.acme:foo", + "name": "Foo", + "_links": { + "guide": [ + { + "href": "https://example.com/guide1" + }, + { + "href": "https://example.com/guide2", + "title": "Some guide for foo" + } + ], + "reference": { + "href": "https://example.com/{bootVersion}/doc", + "templated": true + } + } + }, + { + "id": "org.acme:bar", + "name": "Bar" + }, + { + "id": "org.acme:biz", + "name": "Biz", + "compatibilityRange": "2.2.0.BUILD-SNAPSHOT" + }, + { + "id": "org.acme:bur", + "name": "Bur", + "compatibilityRange": "[2.1.4.RELEASE,2.2.0.BUILD-SNAPSHOT)" + }, + { + "id": "my-api", + "name": "My API" + } + ] + } + ] + }, + "type": { + "type": "action", + "default": "maven-project", + "values": [ + { + "id": "maven-build", + "name": "Maven POM", + "action": "/pom.xml", + "tags": { + "build": "maven", + "format": "build" + } + }, + { + "id": "maven-project", + "name": "Maven Project", + "action": "/starter.zip", + "tags": { + "build": "maven", + "format": "project" + } + }, + { + "id": "gradle-build", + "name": "Gradle Config", + "action": "/build.gradle", + "tags": { + "build": "gradle", + "format": "build" + } + }, + { + "id": "gradle-project", + "name": "Gradle Project", + "action": "/starter.zip", + "tags": { + "build": "gradle", + "format": "project" + } + } + ] + }, + "packaging": { + "type": "single-select", + "default": "jar", + "values": [ + { + "id": "jar", + "name": "Jar" + }, + { + "id": "war", + "name": "War" + } + ] + }, + "javaVersion": { + "type": "single-select", + "default": "1.8", + "values": [ + { + "id": "1.6", + "name": "1.6" + }, + { + "id": "1.7", + "name": "1.7" + }, + { + "id": "1.8", + "name": "1.8" + } + ] + }, + "language": { + "type": "single-select", + "default": "java", + "values": [ + { + "id": "groovy", + "name": "Groovy" + }, + { + "id": "java", + "name": "Java" + }, + { + "id": "kotlin", + "name": "Kotlin" + } + ] + }, + "bootVersion": { + "type": "single-select", + "default": "2.1.4.RELEASE", + "values": [ + { + "id": "2.2.0.BUILD-SNAPSHOT", + "name": "Latest SNAPSHOT" + }, + { + "id": "2.1.4.RELEASE", + "name": "2.1.4" + }, + { + "id": "1.5.17.RELEASE", + "name": "1.5.17" + } + ] + }, + "groupId": { + "type": "text", + "default": "com.example" + }, + "artifactId": { + "type": "text", + "default": "demo" + }, + "version": { + "type": "text", + "default": "0.0.1-SNAPSHOT" + }, + "name": { + "type": "text", + "default": "demo" + }, + "description": { + "type": "text", + "default": "Demo project for Spring Boot" + }, + "packageName": { + "type": "text", + "default": "com.example.demo" + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 96f81a6608..1211bc476d 100644 --- a/pom.xml +++ b/pom.xml @@ -361,9 +361,9 @@ maven-checkstyle-plugin - + [3.0.0,) - + check @@ -380,9 +380,9 @@ flatten-maven-plugin - + [1.0.0,) - + flatten