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 Jul 30, 2019
1 parent 74e0bcc commit 305ed5d
Show file tree
Hide file tree
Showing 34 changed files with 718 additions and 173 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.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;

Expand Down Expand Up @@ -57,7 +57,7 @@ public void contribute(Info.Builder builder) {

private void contribute(Map<String, Object> details, Dependency dependency) {
if (!ObjectUtils.isEmpty(dependency.getMappings())) {
Map<String, VersionRange> dep = new LinkedHashMap<>();
Map<String, CompatibilityRange> dep = new LinkedHashMap<>();
dependency.getMappings().forEach((it) -> {
if (it.getRange() != null && it.getVersion() != null) {
dep.put(it.getVersion(), it.getRange());
Expand All @@ -68,7 +68,7 @@ private void contribute(Map<String, Object> 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<String, Object> depInfo = new LinkedHashMap<>();
Expand All @@ -84,10 +84,10 @@ else if (dependency.getVersion() != null && dependency.getRange() != null) {
}
}

private Version getHigher(Map<String, VersionRange> dep) {
private Version getHigher(Map<String, CompatibilityRange> 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;
}
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.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;
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* @author Stephane Nicoll
*/
public class VersionRange {
public class CompatibilityRange {

private final Version lowerVersion;

Expand All @@ -44,15 +44,15 @@ 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;
this.higherVersion = higherVersion;
this.higherInclusive = higherInclusive;
}

public VersionRange(Version startingVersion) {
public CompatibilityRange(Version startingVersion) {
this(startingVersion, true, null, false);
}

Expand Down Expand Up @@ -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;
}
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 CompatibilityRange} 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 @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)");
}
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 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());
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.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
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 @@ -248,18 +248,18 @@ public static class Mapping {
private List<String> 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();
}

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 @@ -311,7 +311,7 @@ public List<String> getAdditionalBoms() {
return this.additionalBoms;
}

public VersionRange getRange() {
public CompatibilityRange getRange() {
return this.range;
}

Expand All @@ -323,13 +323,14 @@ public void setAdditionalBoms(List<String> 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 + ", " : "")
Expand Down
Loading

0 comments on commit 305ed5d

Please sign in to comment.