mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-17 17:41:31 +08:00
Fix version format for Gradle versions
Closes gh-777
This commit is contained in:
@@ -516,7 +516,7 @@ public class ProjectGenerator {
|
||||
|
||||
private String computeVersionProperty(ProjectRequest request,
|
||||
VersionProperty property) {
|
||||
if (isGradleBuild(request)) {
|
||||
if (isGradleBuild(request) && property.isInternal()) {
|
||||
return property.toCamelCaseFormat();
|
||||
}
|
||||
return property.toStandardFormat();
|
||||
|
||||
@@ -243,11 +243,11 @@ public class ProjectRequest extends BasicProjectRequest {
|
||||
() -> "UTF-8");
|
||||
this.buildProperties.getMaven().put("project.reporting.outputEncoding",
|
||||
() -> "UTF-8");
|
||||
this.buildProperties.getVersions().put(new VersionProperty("java.version"),
|
||||
this.buildProperties.getVersions().put(VersionProperty.of("java.version"),
|
||||
this::getJavaVersion);
|
||||
if ("kotlin".equals(getLanguage())) {
|
||||
this.buildProperties.getVersions()
|
||||
.put(new VersionProperty("kotlin.version"), kotlinVersion);
|
||||
.put(VersionProperty.of("kotlin.version"), kotlinVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ public class BillOfMaterials {
|
||||
}
|
||||
|
||||
public void setVersionProperty(String versionPropertyName) {
|
||||
setVersionProperty(new VersionProperty(versionPropertyName));
|
||||
setVersionProperty(VersionProperty.of(versionPropertyName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -246,7 +246,7 @@ public class InitializrMetadata {
|
||||
String versionProperty) {
|
||||
BillOfMaterials bom = BillOfMaterials.create("org.springframework.boot",
|
||||
"spring-boot-dependencies", bootVersion);
|
||||
bom.setVersionProperty(new VersionProperty(versionProperty));
|
||||
bom.setVersionProperty(VersionProperty.of(versionProperty));
|
||||
bom.setOrder(100);
|
||||
return bom;
|
||||
}
|
||||
|
||||
@@ -31,14 +31,46 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class VersionProperty implements Serializable, Comparable<VersionProperty> {
|
||||
public final class VersionProperty implements Serializable, Comparable<VersionProperty> {
|
||||
|
||||
private static final List<Character> SUPPORTED_CHARS = Arrays.asList('.', '-');
|
||||
|
||||
private final String property;
|
||||
|
||||
public VersionProperty(String property) {
|
||||
private final boolean internal;
|
||||
|
||||
private VersionProperty(String property, boolean internal) {
|
||||
this.property = validateFormat(property);
|
||||
this.internal = internal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a {@link VersionProperty}.
|
||||
* @param property the name of the property
|
||||
* @param internal whether the property is internal and can be tuned according to the
|
||||
* build system
|
||||
* @return a version property
|
||||
*/
|
||||
public static VersionProperty of(String property, boolean internal) {
|
||||
return new VersionProperty(property, internal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an internal {@link VersionProperty}.
|
||||
* @param property the name of the property
|
||||
* @return a version property whose format can be tuned according to the build system
|
||||
*/
|
||||
public static VersionProperty of(String property) {
|
||||
return of(property, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if the property is internally defined and can be tuned according to the
|
||||
* build system.
|
||||
* @return {@code true} if the property is defined within the scope of this project
|
||||
*/
|
||||
public boolean isInternal() {
|
||||
return this.internal;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,15 +78,10 @@ configurations {
|
||||
providedRuntime
|
||||
}
|
||||
{{/providedDependencies}}
|
||||
|
||||
{{^buildPropertiesVersions.empty}}
|
||||
ext {
|
||||
{{#buildPropertiesVersions}}
|
||||
{{key}} = '{{value}}'
|
||||
{{#buildPropertiesVersions}}
|
||||
ext['{{key}}'] = '{{value}}'
|
||||
{{/buildPropertiesVersions}}
|
||||
}
|
||||
|
||||
{{/buildPropertiesVersions.empty}}
|
||||
dependencies {
|
||||
{{#compileDependencies}}
|
||||
{{gradleCompileConfig}}('{{groupId}}:{{artifactId}}{{#version}}:{{version}}{{/version}}{{#type}}@{{type}}{{/type}}')
|
||||
|
||||
@@ -105,10 +105,10 @@ public class ProjectGeneratorBuildTests extends AbstractProjectGeneratorTests {
|
||||
@Test
|
||||
public void versionOverride() {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
request.getBuildProperties().getVersions().put(
|
||||
VersionProperty.of("spring-foo.version", false), () -> "0.1.0.RELEASE");
|
||||
request.getBuildProperties().getVersions()
|
||||
.put(new VersionProperty("spring-foo.version"), () -> "0.1.0.RELEASE");
|
||||
request.getBuildProperties().getVersions()
|
||||
.put(new VersionProperty("spring-bar.version"), () -> "0.2.0.RELEASE");
|
||||
.put(VersionProperty.of("spring-bar.version"), () -> "0.2.0.RELEASE");
|
||||
ProjectAssert project = generateProject(request);
|
||||
project.sourceCodeAssert(this.fileName).equalsTo(new ClassPathResource(
|
||||
"project/" + this.build + "/version-override-" + this.assertFileName));
|
||||
|
||||
@@ -818,7 +818,7 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
||||
public void buildPropertiesMaven() {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
request.getBuildProperties().getMaven().put("name", () -> "test");
|
||||
request.getBuildProperties().getVersions().put(new VersionProperty("foo.version"),
|
||||
request.getBuildProperties().getVersions().put(VersionProperty.of("foo.version"),
|
||||
() -> "1.2.3");
|
||||
request.getBuildProperties().getGradle().put("ignore.property", () -> "yes");
|
||||
|
||||
@@ -830,12 +830,16 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
||||
public void buildPropertiesGradle() {
|
||||
ProjectRequest request = createProjectRequest("web");
|
||||
request.getBuildProperties().getGradle().put("name", () -> "test");
|
||||
request.getBuildProperties().getVersions().put(new VersionProperty("foo.version"),
|
||||
() -> "1.2.3");
|
||||
request.getBuildProperties().getVersions()
|
||||
.put(VersionProperty.of("foo.version", false), () -> "1.2.3");
|
||||
request.getBuildProperties().getVersions()
|
||||
.put(VersionProperty.of("internal.version"), () -> "4.5.6");
|
||||
request.getBuildProperties().getMaven().put("ignore.property", () -> "yes");
|
||||
|
||||
generateGradleBuild(request).contains("name = 'test'").contains("ext {")
|
||||
.contains("fooVersion = '1.2.3'").doesNotContain("ignore.property");
|
||||
generateGradleBuild(request).contains("name = 'test'")
|
||||
.contains("ext['foo.version'] = '1.2.3'")
|
||||
.contains("ext['internalVersion'] = '4.5.6'")
|
||||
.doesNotContain("ignore.property");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -39,8 +39,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class ProjectRequestResolverTests {
|
||||
|
||||
private static final VersionProperty VERSION_PROPERTY = new VersionProperty(
|
||||
"java.version");
|
||||
private static final VersionProperty VERSION_PROPERTY = VersionProperty
|
||||
.of("java.version");
|
||||
|
||||
private InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("test", "web", "security", "data-jpa").build();
|
||||
|
||||
@@ -34,25 +34,25 @@ public class VersionPropertyTests {
|
||||
|
||||
@Test
|
||||
public void testStandardProperty() {
|
||||
assertThat(new VersionProperty("spring-boot.version").toStandardFormat())
|
||||
assertThat(VersionProperty.of("spring-boot.version").toStandardFormat())
|
||||
.isEqualTo("spring-boot.version");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCamelCaseProperty() {
|
||||
assertThat(new VersionProperty("spring-boot.version").toCamelCaseFormat())
|
||||
assertThat(VersionProperty.of("spring-boot.version").toCamelCaseFormat())
|
||||
.isEqualTo("springBootVersion");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStandardPropertyWithNoSeparator() {
|
||||
assertThat(new VersionProperty("springbootversion").toStandardFormat())
|
||||
assertThat(VersionProperty.of("springbootversion").toStandardFormat())
|
||||
.isEqualTo("springbootversion");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCamelCasePropertyWithNoSeparator() {
|
||||
assertThat(new VersionProperty("springbootversion").toCamelCaseFormat())
|
||||
assertThat(VersionProperty.of("springbootversion").toCamelCaseFormat())
|
||||
.isEqualTo("springbootversion");
|
||||
}
|
||||
|
||||
@@ -60,14 +60,14 @@ public class VersionPropertyTests {
|
||||
public void testInvalidPropertyUpperCase() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("upper case");
|
||||
new VersionProperty("Spring-boot.version");
|
||||
VersionProperty.of("Spring-boot.version");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidPropertyIllegalCharacter() {
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Unsupported character");
|
||||
new VersionProperty("spring-boot_version");
|
||||
VersionProperty.of("spring-boot_version");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,10 +24,7 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
|
||||
ext {
|
||||
fooVersion = '1.3.3'
|
||||
}
|
||||
ext['fooVersion'] = '1.3.3'
|
||||
|
||||
dependencies {
|
||||
compile('org.acme:foo')
|
||||
|
||||
@@ -24,11 +24,8 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
|
||||
ext {
|
||||
springBarVersion = '0.2.0.RELEASE'
|
||||
springFooVersion = '0.1.0.RELEASE'
|
||||
}
|
||||
ext['springBarVersion'] = '0.2.0.RELEASE'
|
||||
ext['spring-foo.version'] = '0.1.0.RELEASE'
|
||||
|
||||
dependencies {
|
||||
compile('org.springframework.boot:spring-boot-starter-web')
|
||||
|
||||
Reference in New Issue
Block a user