mirror of
https://gitee.com/dcren/initializr.git
synced 2025-07-16 16:50:42 +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
|
package io.spring.initializr.metadata
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore
|
||||||
import com.fasterxml.jackson.annotation.JsonInclude
|
import com.fasterxml.jackson.annotation.JsonInclude
|
||||||
import groovy.transform.AutoClone
|
import groovy.transform.AutoClone
|
||||||
import groovy.transform.AutoCloneStyle
|
import groovy.transform.AutoCloneStyle
|
||||||
@ -81,6 +82,9 @@ class Dependency extends MetadataElement {
|
|||||||
|
|
||||||
String versionRange
|
String versionRange
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
String versionRequirement
|
||||||
|
|
||||||
String bom
|
String bom
|
||||||
|
|
||||||
String repository
|
String repository
|
||||||
@ -157,7 +161,8 @@ class Dependency extends MetadataElement {
|
|||||||
}
|
}
|
||||||
if (versionRange) {
|
if (versionRange) {
|
||||||
try {
|
try {
|
||||||
VersionRange.parse(versionRange)
|
def range = VersionRange.parse(versionRange)
|
||||||
|
versionRequirement = range.toString()
|
||||||
} catch (InvalidVersionException ex) {
|
} catch (InvalidVersionException ex) {
|
||||||
throw new InvalidInitializrMetadataException("Invalid version range '$versionRange' for " +
|
throw new InvalidInitializrMetadataException("Invalid version range '$versionRange' for " +
|
||||||
"dependency with id '$id'")
|
"dependency with id '$id'")
|
||||||
@ -183,6 +188,7 @@ class Dependency extends MetadataElement {
|
|||||||
dependency.groupId = mapping.groupId ? mapping.groupId : this.groupId
|
dependency.groupId = mapping.groupId ? mapping.groupId : this.groupId
|
||||||
dependency.artifactId = mapping.artifactId ? mapping.artifactId : this.artifactId
|
dependency.artifactId = mapping.artifactId ? mapping.artifactId : this.artifactId
|
||||||
dependency.version = mapping.version ? mapping.version : this.version
|
dependency.version = mapping.version ? mapping.version : this.version
|
||||||
|
dependency.versionRequirement = mapping.range.toString()
|
||||||
dependency.mappings = null
|
dependency.mappings = null
|
||||||
return dependency
|
return dependency
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,6 @@ import org.springframework.util.Assert
|
|||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
@ToString
|
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
class VersionRange {
|
class VersionRange {
|
||||||
|
|
||||||
@ -80,6 +79,18 @@ class VersionRange {
|
|||||||
return true
|
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
|
* Parse the string representation of a {@link VersionRange}. Throws an
|
||||||
* {@link InvalidVersionException} if the range could not be parsed.
|
* {@link InvalidVersionException} if the range could not be parsed.
|
||||||
|
@ -155,6 +155,16 @@ class DependencyTests {
|
|||||||
dependency.resolve()
|
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
|
@Test
|
||||||
void resolveMatchingVersionMapping() {
|
void resolveMatchingVersionMapping() {
|
||||||
def dependency = new Dependency(id: 'web', description: 'A web dependency', version: '0.3.0.RELEASE',
|
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;
|
margin: 1em 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.version-requirement {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
.disabled .version-requirement {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
/* autocomplete */
|
/* autocomplete */
|
||||||
|
|
||||||
#autocomplete, .twitter-typeahead, .tt-hint {
|
#autocomplete, .twitter-typeahead, .tt-hint {
|
||||||
|
@ -125,12 +125,12 @@ $(function () {
|
|||||||
var refreshDependencies = function (versionRange) {
|
var refreshDependencies = function (versionRange) {
|
||||||
var versions = new Versions();
|
var versions = new Versions();
|
||||||
$("#dependencies div.checkbox").each(function (idx, item) {
|
$("#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");
|
$("input", item).removeAttr("disabled");
|
||||||
$(item).removeClass("disabled");
|
$(item).removeClass("disabled has-error");
|
||||||
} else {
|
} else {
|
||||||
$("input", item).prop('checked', false);
|
$("input", item).prop('checked', false);
|
||||||
$(item).addClass("disabled");
|
$(item).addClass("disabled has-error");
|
||||||
$("input", item).attr("disabled", true);
|
$("input", item).attr("disabled", true);
|
||||||
removeTag($("input", item).val());
|
removeTag($("input", item).val());
|
||||||
}
|
}
|
||||||
|
@ -139,11 +139,13 @@
|
|||||||
<div class="form-group col-sm-6">
|
<div class="form-group col-sm-6">
|
||||||
<h3>${it.name}</h3>
|
<h3>${it.name}</h3>
|
||||||
<% it.content.each { %>
|
<% it.content.each { %>
|
||||||
<div class="checkbox" data-range="${it.versionRange}">
|
<div class="checkbox" data-range="${it.versionRange?:''}">
|
||||||
<label>
|
<label>
|
||||||
<input tabindex="13" type="checkbox" name="style" value="${it.id}">
|
<input tabindex="13" type="checkbox" name="style" value="${it.id}">${it.name}
|
||||||
${it.name}
|
|
||||||
<p class="help-block">${it.description}</p>
|
<p class="help-block">${it.description}</p>
|
||||||
|
<% if (it.versionRequirement) { %>
|
||||||
|
<p class="help-block version-requirement">requires Spring Boot ${it.versionRequirement}</p>
|
||||||
|
<% } %>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
Loading…
Reference in New Issue
Block a user