Skip to content

Commit acfd998

Browse files
committed
Add SHA256 of Maven distribution for the Maven wrapper
Closes gh-1577
1 parent 6b2774d commit acfd998

File tree

3 files changed

+84
-8
lines changed

3 files changed

+84
-8
lines changed

initializr-generator-spring/src/main/resources/maven/3/wrapper/.mvn/wrapper/maven-wrapper.properties

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
wrapperVersion=3.3.2
1818
distributionType=only-script
1919
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip
20+
distributionSha256Sum=4ec3f26fb1a692473aea0235c300bd20f0f9fe741947c82c1234cefd76ac3a3c

initializr-generator-spring/src/test/java/io/spring/initializr/generator/spring/ProjectGeneratorIntegrationTests.java

+79-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616

1717
package io.spring.initializr.generator.spring;
1818

19+
import java.io.IOException;
20+
import java.nio.file.Files;
1921
import java.nio.file.Path;
2022

23+
import io.spring.initializr.generator.buildsystem.BuildSystem;
24+
import io.spring.initializr.generator.buildsystem.gradle.GradleBuildSystem;
2125
import io.spring.initializr.generator.buildsystem.maven.MavenBuildSystem;
2226
import io.spring.initializr.generator.language.java.JavaLanguage;
2327
import io.spring.initializr.generator.project.MutableProjectDescription;
@@ -39,25 +43,32 @@
3943
* {@link ProjectGenerationConfiguration} instances.
4044
*
4145
* @author Stephane Nicoll
46+
* @author Moritz Halbritter
4247
*/
4348
class ProjectGeneratorIntegrationTests {
4449

50+
private static final String SPRING_BOOT_VERSION = "3.3.0";
51+
52+
private static final String JAVA_VERSION = "17";
53+
54+
private static final String DEPENDENCY_MANAGEMENT_PLUGIN_VERSION = "1.1.6";
55+
4556
private ProjectGeneratorTester projectTester;
4657

4758
@BeforeEach
4859
void setup(@TempDir Path directory) {
4960
this.projectTester = new ProjectGeneratorTester().withDirectory(directory)
5061
.withIndentingWriterFactory()
51-
.withBean(InitializrMetadata.class, () -> InitializrMetadataTestBuilder.withDefaults().build());
62+
.withBean(InitializrMetadata.class,
63+
() -> InitializrMetadataTestBuilder.withDefaults()
64+
.setGradleEnv(DEPENDENCY_MANAGEMENT_PLUGIN_VERSION)
65+
.build());
5266
}
5367

5468
@Test
5569
void customBaseDirectoryIsUsedWhenGeneratingProject() {
5670
MutableProjectDescription description = initProjectDescription();
5771
description.setBuildSystem(new MavenBuildSystem());
58-
description.setPlatformVersion(Version.parse("2.1.0.RELEASE"));
59-
description.setLanguage(new JavaLanguage());
60-
description.setGroupId("com.example");
6172
description.setBaseDirectory("test/demo-app");
6273
ProjectStructure project = this.projectTester.generate(description);
6374
assertThat(project).filePaths()
@@ -69,9 +80,73 @@ void customBaseDirectoryIsUsedWhenGeneratingProject() {
6980
"test/demo-app/src/test/java/com/example/demo/DemoApplicationTests.java", "test/demo-app/HELP.md");
7081
}
7182

83+
@Test
84+
void generatedMavenProjectBuilds(@TempDir Path mavenHome) throws Exception {
85+
MutableProjectDescription description = initProjectDescription();
86+
description.setBuildSystem(new MavenBuildSystem());
87+
ProjectStructure project = this.projectTester.generate(description);
88+
Path projectDirectory = project.getProjectDirectory();
89+
runBuild(mavenHome, projectDirectory, description);
90+
}
91+
92+
@Test
93+
void generatedGradleProjectBuilds(@TempDir Path gradleHome) throws Exception {
94+
MutableProjectDescription description = initProjectDescription();
95+
description.setBuildSystem(new GradleBuildSystem());
96+
ProjectStructure project = this.projectTester.generate(description);
97+
Path projectDirectory = project.getProjectDirectory();
98+
runBuild(gradleHome, projectDirectory, description);
99+
}
100+
101+
private void runBuild(Path mavenHome, Path projectDirectory, MutableProjectDescription description)
102+
throws InterruptedException, IOException {
103+
ProcessBuilder processBuilder = createProcessBuilder(projectDirectory, description.getBuildSystem(), mavenHome);
104+
Path output = projectDirectory.resolve("output.log");
105+
processBuilder.redirectError(output.toFile());
106+
processBuilder.redirectOutput(output.toFile());
107+
assertThat(processBuilder.start().waitFor()).describedAs(String.join("\n", Files.readAllLines(output)))
108+
.isEqualTo(0);
109+
}
110+
111+
private ProcessBuilder createProcessBuilder(Path directory, BuildSystem buildSystem, Path home) {
112+
String javaHome = System.getProperty("java.home");
113+
if (buildSystem.id().equals(MavenBuildSystem.ID)) {
114+
String command = (isWindows()) ? "mvnw.cmd" : "mvnw";
115+
ProcessBuilder processBuilder = new ProcessBuilder(directory.resolve(command).toAbsolutePath().toString(),
116+
"-Dmaven.repo.local=" + home.resolve("repository").toAbsolutePath(), "--batch-mode",
117+
"--no-transfer-progress", "package");
118+
if (javaHome != null) {
119+
processBuilder.environment().put("JAVA_HOME", javaHome);
120+
}
121+
processBuilder.environment().put("MAVEN_USER_HOME", home.toAbsolutePath().toString());
122+
processBuilder.directory(directory.toFile());
123+
return processBuilder;
124+
}
125+
if (buildSystem.id().equals(GradleBuildSystem.ID)) {
126+
String command = (isWindows()) ? "gradlew.bat" : "gradlew";
127+
ProcessBuilder processBuilder = new ProcessBuilder(directory.resolve(command).toAbsolutePath().toString(),
128+
"--no-daemon", "build");
129+
if (javaHome != null) {
130+
processBuilder.environment().put("JAVA_HOME", javaHome);
131+
}
132+
processBuilder.environment().put("GRADLE_USER_HOME", home.toAbsolutePath().toString());
133+
processBuilder.directory(directory.toFile());
134+
return processBuilder;
135+
}
136+
throw new IllegalStateException("Unknown build system '%s'".formatted(buildSystem.id()));
137+
}
138+
139+
private boolean isWindows() {
140+
String osName = System.getProperty("os.name");
141+
return osName != null && osName.startsWith("Windows");
142+
}
143+
72144
private MutableProjectDescription initProjectDescription() {
73145
MutableProjectDescription description = new MutableProjectDescription();
74146
description.setApplicationName("DemoApplication");
147+
description.setPlatformVersion(Version.parse(SPRING_BOOT_VERSION));
148+
description.setLanguage(new JavaLanguage(JAVA_VERSION));
149+
description.setGroupId("com.example");
75150
return description;
76151
}
77152

initializr-generator-test/src/main/java/io/spring/initializr/generator/test/project/ProjectGeneratorTester.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030

3131
/**
3232
* A tester class for {@link ProjectGenerator}. Contrary to {@link ProjectAssetTester},
33-
* standard {@link ProjectGenerationConfiguration} classes are processed
34-
* automatically.Extra beans can be added using {@linkplain #withBean(Class, Supplier)
35-
* bean registration}, a {@linkplain #withConfiguration(Class[]) configuration class} or
36-
* via the {@linkplain #withContextInitializer(Consumer) customization of the project
33+
* standard {@link ProjectGenerationConfiguration} classes are processed automatically.
34+
* Extra beans can be added using {@linkplain #withBean(Class, Supplier) bean
35+
* registration}, a {@linkplain #withConfiguration(Class[]) configuration class} or via
36+
* the {@linkplain #withContextInitializer(Consumer) customization of the project
3737
* generation context}.
3838
*
3939
* @author Stephane Nicoll

0 commit comments

Comments
 (0)