mirror of
https://gitee.com/dcren/initializr.git
synced 2026-09-19 22:37:40 +08:00
Merge pull request #643 from cjvogel1972:settings-gradle
* pr/643: Polish "Create a settings.gradle file for Gradle projects" Create a settings.gradle file for Gradle projects
This commit is contained in:
+7
@@ -59,6 +59,7 @@ import org.springframework.util.StreamUtils;
|
|||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
|
* @author Chris Vogel
|
||||||
*/
|
*/
|
||||||
public class ProjectGenerator {
|
public class ProjectGenerator {
|
||||||
|
|
||||||
@@ -219,6 +220,8 @@ public class ProjectGenerator {
|
|||||||
if (isGradleBuild(request)) {
|
if (isGradleBuild(request)) {
|
||||||
String gradle = new String(doGenerateGradleBuild(model));
|
String gradle = new String(doGenerateGradleBuild(model));
|
||||||
writeText(new File(dir, "build.gradle"), gradle);
|
writeText(new File(dir, "build.gradle"), gradle);
|
||||||
|
String settings = new String(doGenerateGradleSettings(model));
|
||||||
|
writeText(new File(dir, "settings.gradle"), settings);
|
||||||
writeGradleWrapper(dir, Version.safeParse(request.getBootVersion()));
|
writeGradleWrapper(dir, Version.safeParse(request.getBootVersion()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -600,6 +603,10 @@ public class ProjectGenerator {
|
|||||||
return templateRenderer.process("starter-build.gradle", model).getBytes();
|
return templateRenderer.process("starter-build.gradle", model).getBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private byte[] doGenerateGradleSettings(Map<String, Object> model) {
|
||||||
|
return templateRenderer.process("starter-settings.gradle", model).getBytes();
|
||||||
|
}
|
||||||
|
|
||||||
private void writeGradleWrapper(File dir, Version bootVersion) {
|
private void writeGradleWrapper(File dir, Version bootVersion) {
|
||||||
String gradlePrefix = isGradle4Available(bootVersion) ? "gradle4" :
|
String gradlePrefix = isGradle4Available(bootVersion) ? "gradle4" :
|
||||||
isGradle3Available(bootVersion) ? "gradle3" : "gradle";
|
isGradle3Available(bootVersion) ? "gradle3" : "gradle";
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
rootProject.name = '{{artifactId}}'
|
||||||
+22
@@ -70,6 +70,18 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
|||||||
verifyProjectSuccessfulEventFor(request);
|
verifyProjectSuccessfulEventFor(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void defaultProjectWithGradle() {
|
||||||
|
ProjectRequest request = createProjectRequest("web");
|
||||||
|
request.setType("gradle-build");
|
||||||
|
ProjectAssert gradleProject = generateProject(request).isGradleProject();
|
||||||
|
gradleProject.gradleBuildAssert()
|
||||||
|
.contains("compile('org.springframework.boot:spring-boot-starter-web')")
|
||||||
|
.contains("testCompile('org.springframework.boot:spring-boot-starter-test')");
|
||||||
|
gradleProject.gradleSettingsAssert().hasProjectName("demo");
|
||||||
|
verifyProjectSuccessfulEventFor(request);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noDependencyAddsRootStarter() {
|
public void noDependencyAddsRootStarter() {
|
||||||
ProjectRequest request = createProjectRequest();
|
ProjectRequest request = createProjectRequest();
|
||||||
@@ -230,6 +242,16 @@ public class ProjectGeneratorTests extends AbstractProjectGeneratorTests {
|
|||||||
.contains("package org.acme.foo145;");
|
.contains("package org.acme.foo145;");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void gradleProjectWithCustomArtifactId() {
|
||||||
|
ProjectRequest request = createProjectRequest();
|
||||||
|
request.setType("gradle-build");
|
||||||
|
request.setArtifactId("my-application");
|
||||||
|
generateProject(request).isGradleProject().gradleSettingsAssert()
|
||||||
|
.hasProjectName("my-application");
|
||||||
|
verifyProjectSuccessfulEventFor(request);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void springBoot11UseEnableAutoConfigurationJava() {
|
public void springBoot11UseEnableAutoConfigurationJava() {
|
||||||
ProjectRequest request = createProjectRequest("web");
|
ProjectRequest request = createProjectRequest("web");
|
||||||
|
|||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2012-2018 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.spring.initializr.test.generator;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Very simple assertions for the gradle settings.
|
||||||
|
*
|
||||||
|
* @author Stephane Nicoll
|
||||||
|
*/
|
||||||
|
public class GradleSettingsAssert {
|
||||||
|
|
||||||
|
private final String content;
|
||||||
|
|
||||||
|
public GradleSettingsAssert(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GradleSettingsAssert hasProjectName(String name) {
|
||||||
|
return contains(String.format("rootProject.name = '%s'", name));
|
||||||
|
}
|
||||||
|
|
||||||
|
public GradleSettingsAssert contains(String expression) {
|
||||||
|
assertThat(this.content).contains(expression);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+14
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -104,6 +104,19 @@ public class ProjectAssert {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a {@link GradleSettingsAssert} for this project.
|
||||||
|
*/
|
||||||
|
public GradleSettingsAssert gradleSettingsAssert() {
|
||||||
|
try {
|
||||||
|
return new GradleSettingsAssert(StreamUtils.copyToString(
|
||||||
|
new FileInputStream(file("settings.gradle")), Charset.forName("UTF-8")));
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
throw new IllegalArgumentException("Cannot resolve settings.gradle", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a {@link SourceCodeAssert} for the specified source code.
|
* Return a {@link SourceCodeAssert} for the specified source code.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user