mirror of
https://gitee.com/dcren/initializr.git
synced 2025-07-15 23:13:30 +08:00
Show version requirements for disabled starters
This commit writes the version range information in human readable format and adds it to the starter list when starters are disabled. Closes gh-293
This commit is contained in:
parent
26dd9eb082
commit
8ee8d72e62
@ -16,6 +16,7 @@
|
||||
|
||||
package io.spring.initializr.metadata
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||
import com.fasterxml.jackson.annotation.JsonInclude
|
||||
import groovy.transform.AutoClone
|
||||
import groovy.transform.AutoCloneStyle
|
||||
@ -81,6 +82,9 @@ class Dependency extends MetadataElement {
|
||||
|
||||
String versionRange
|
||||
|
||||
@JsonIgnore
|
||||
String versionRequirement
|
||||
|
||||
String bom
|
||||
|
||||
String repository
|
||||
@ -157,7 +161,8 @@ class Dependency extends MetadataElement {
|
||||
}
|
||||
if (versionRange) {
|
||||
try {
|
||||
VersionRange.parse(versionRange)
|
||||
def range = VersionRange.parse(versionRange)
|
||||
versionRequirement = range.toString()
|
||||
} catch (InvalidVersionException ex) {
|
||||
throw new InvalidInitializrMetadataException("Invalid version range '$versionRange' for " +
|
||||
"dependency with id '$id'")
|
||||
@ -183,6 +188,7 @@ class Dependency extends MetadataElement {
|
||||
dependency.groupId = mapping.groupId ? mapping.groupId : this.groupId
|
||||
dependency.artifactId = mapping.artifactId ? mapping.artifactId : this.artifactId
|
||||
dependency.version = mapping.version ? mapping.version : this.version
|
||||
dependency.versionRequirement = mapping.range.toString()
|
||||
dependency.mappings = null
|
||||
return dependency
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ import org.springframework.util.Assert
|
||||
* @author Stephane Nicoll
|
||||
* @since 1.0
|
||||
*/
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
class VersionRange {
|
||||
|
||||
@ -80,6 +79,18 @@ class VersionRange {
|
||||
return true
|
||||
}
|
||||
|
||||
@Override
|
||||
String toString() {
|
||||
StringBuffer sb = new StringBuffer()
|
||||
if (lowerVersion) {
|
||||
sb.append("${lowerInclusive ? '>=' : '>'}${lowerVersion}")
|
||||
}
|
||||
if (higherVersion) {
|
||||
sb.append(" and ${higherInclusive ? '<=' : '<'}${higherVersion}")
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the string representation of a {@link VersionRange}. Throws an
|
||||
* {@link InvalidVersionException} if the range could not be parsed.
|
||||
|
@ -155,6 +155,16 @@ class DependencyTests {
|
||||
dependency.resolve()
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveVersionRequirement() {
|
||||
def dependency = new Dependency(id: 'web')
|
||||
dependency.mappings << new Dependency.Mapping(
|
||||
versionRange: '[1.1.0.RELEASE, 1.2.0.RELEASE)', version: '0.1.0.RELEASE')
|
||||
dependency.resolve()
|
||||
def resolved = dependency.resolve(Version.parse('1.1.5.RELEASE'))
|
||||
assertEquals ">=1.1.0.RELEASE and <1.2.0.RELEASE", resolved.versionRequirement
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveMatchingVersionMapping() {
|
||||
def dependency = new Dependency(id: 'web', description: 'A web dependency', version: '0.3.0.RELEASE',
|
||||
|
@ -69,6 +69,13 @@ input[type=text] {
|
||||
margin: 1em 0;
|
||||
}
|
||||
|
||||
.version-requirement {
|
||||
display: none;
|
||||
}
|
||||
.disabled .version-requirement {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* autocomplete */
|
||||
|
||||
#autocomplete, .twitter-typeahead, .tt-hint {
|
||||
|
@ -125,12 +125,12 @@ $(function () {
|
||||
var refreshDependencies = function (versionRange) {
|
||||
var versions = new Versions();
|
||||
$("#dependencies div.checkbox").each(function (idx, item) {
|
||||
if ($(item).attr('data-range') === 'null' || versions.matchRange($(item).attr('data-range'))(versionRange)) {
|
||||
if (!$(item).attr('data-range') || versions.matchRange($(item).attr('data-range'))(versionRange)) {
|
||||
$("input", item).removeAttr("disabled");
|
||||
$(item).removeClass("disabled");
|
||||
$(item).removeClass("disabled has-error");
|
||||
} else {
|
||||
$("input", item).prop('checked', false);
|
||||
$(item).addClass("disabled");
|
||||
$(item).addClass("disabled has-error");
|
||||
$("input", item).attr("disabled", true);
|
||||
removeTag($("input", item).val());
|
||||
}
|
||||
|
@ -139,11 +139,13 @@
|
||||
<div class="form-group col-sm-6">
|
||||
<h3>${it.name}</h3>
|
||||
<% it.content.each { %>
|
||||
<div class="checkbox" data-range="${it.versionRange}">
|
||||
<div class="checkbox" data-range="${it.versionRange?:''}">
|
||||
<label>
|
||||
<input tabindex="13" type="checkbox" name="style" value="${it.id}">
|
||||
${it.name}
|
||||
<input tabindex="13" type="checkbox" name="style" value="${it.id}">${it.name}
|
||||
<p class="help-block">${it.description}</p>
|
||||
<% if (it.versionRequirement) { %>
|
||||
<p class="help-block version-requirement">requires Spring Boot ${it.versionRequirement}</p>
|
||||
<% } %>
|
||||
</label>
|
||||
</div>
|
||||
<% } %>
|
||||
|
Loading…
Reference in New Issue
Block a user