Skip to content

Commit

Permalink
fix to gh-418
Browse files Browse the repository at this point in the history
  • Loading branch information
htztomic committed Aug 5, 2019
1 parent 5672806 commit 70fc278
Show file tree
Hide file tree
Showing 27 changed files with 139 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void contribute(Info.Builder builder) {
if (v.getMappings() != null && !v.getMappings().isEmpty()) {
Map<String, Object> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import java.util.LinkedHashMap;
import java.util.Map;

import io.spring.initializr.generator.version.Version;
import io.spring.initializr.generator.version.VersionRange;
import io.spring.initializr.generator.version.Version;
import io.spring.initializr.metadata.Dependency;
import io.spring.initializr.metadata.InitializrMetadataProvider;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import io.spring.initializr.generator.condition.ProjectGenerationCondition;
import io.spring.initializr.generator.project.ResolvedProjectDescription;
import io.spring.initializr.generator.version.VersionRange;
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;
Expand All @@ -36,9 +36,11 @@
*/
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 VersionRange 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 VersionRange 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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 VersionRange} that allows to resolve the
* minor and patch value against a configurable list of "latest versions".
* <p>
* 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
Expand Down Expand Up @@ -120,7 +120,7 @@ public Version safeParse(String text) {
* Parse the string representation of a {@link VersionRange}. 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class VersionRange {
private final boolean higherInclusive;

protected VersionRange(Version lowerVersion, boolean lowerInclusive, Version higherVersion,
boolean higherInclusive) {
boolean higherInclusive) {
this.lowerVersion = lowerVersion;
this.lowerInclusive = lowerInclusive;
this.higherVersion = higherVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,35 +114,35 @@ void matchOverAsOfCurrentVersion() {
}

@Test
void toVersionRangeWithSimpleVersion() {
void toCompatibilityRangeWithSimpleVersion() {
VersionRange 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() {
void toCompatibilityRangeWithVersionsIncluded() {
VersionRange 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() {
void toCompatibilityRangeWithLowerVersionExcluded() {
VersionRange 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() {
void toCompatibilityRangeWithHigherVersionExcluded() {
VersionRange 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() {
void toCompatibilityRangeWithVersionsExcluded() {
VersionRange 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)");
Expand All @@ -153,16 +153,16 @@ private static Condition<String> match(String range) {
}

private static Condition<String> match(String range, VersionParser parser) {
return new VersionRangeCondition(range, parser);
return new CompatibilityRangeCondition(range, parser);
}

static class VersionRangeCondition extends Condition<String> {
static class CompatibilityRangeCondition extends Condition<String> {

private final VersionRange 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.spring.initializr.generator.version.VersionRange;
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
Expand Down Expand Up @@ -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);
}
});
}
Expand Down Expand Up @@ -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.
Expand All @@ -254,12 +254,12 @@ 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();
}

Expand All @@ -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() {
Expand Down Expand Up @@ -329,7 +329,8 @@ public void setRange(VersionRange 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 + ", " : "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
Expand Down
Loading

0 comments on commit 70fc278

Please sign in to comment.