Port the build to Gradle
Closes gh-19609 Closes gh-19608
This commit is contained in:
@@ -38,7 +38,7 @@ class GettingStartedDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void typicalPluginsAppliesExceptedPlugins() {
|
||||
this.gradleBuild.script("src/main/gradle/getting-started/typical-plugins").build("verify");
|
||||
this.gradleBuild.script("src/docs/gradle/getting-started/typical-plugins").build("verify");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,14 +42,14 @@ class IntegratingWithActuatorDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void basicBuildInfo() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/integrating-with-actuator/build-info-basic").build("bootBuildInfo");
|
||||
this.gradleBuild.script("src/docs/gradle/integrating-with-actuator/build-info-basic").build("bootBuildInfo");
|
||||
assertThat(new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties"))
|
||||
.isFile();
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void buildInfoCustomValues() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/integrating-with-actuator/build-info-custom-values")
|
||||
this.gradleBuild.script("src/docs/gradle/integrating-with-actuator/build-info-custom-values")
|
||||
.build("bootBuildInfo");
|
||||
File file = new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties");
|
||||
assertThat(file).isFile();
|
||||
@@ -62,7 +62,7 @@ class IntegratingWithActuatorDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void buildInfoAdditional() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/integrating-with-actuator/build-info-additional")
|
||||
this.gradleBuild.script("src/docs/gradle/integrating-with-actuator/build-info-additional")
|
||||
.build("bootBuildInfo");
|
||||
File file = new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties");
|
||||
assertThat(file).isFile();
|
||||
|
||||
@@ -39,18 +39,18 @@ class ManagingDependenciesDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void dependenciesExampleEvaluatesSuccessfully() {
|
||||
this.gradleBuild.script("src/main/gradle/managing-dependencies/dependencies").build();
|
||||
this.gradleBuild.script("src/docs/gradle/managing-dependencies/dependencies").build();
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void customManagedVersions() {
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/managing-dependencies/custom-version").build("slf4jVersion")
|
||||
assertThat(this.gradleBuild.script("src/docs/gradle/managing-dependencies/custom-version").build("slf4jVersion")
|
||||
.getOutput()).contains("1.7.20");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void dependencyManagementInIsolation() {
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/managing-dependencies/configure-bom")
|
||||
assertThat(this.gradleBuild.script("src/docs/gradle/managing-dependencies/configure-bom")
|
||||
.build("dependencyManagement").getOutput()).contains("org.springframework.boot:spring-boot-starter ");
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class ManagingDependenciesDocumentationTests {
|
||||
void dependencyManagementInIsolationWithPluginsBlock() {
|
||||
assumingThat(this.gradleBuild.getDsl() == Dsl.KOTLIN,
|
||||
() -> assertThat(
|
||||
this.gradleBuild.script("src/main/gradle/managing-dependencies/configure-bom-with-plugins")
|
||||
this.gradleBuild.script("src/docs/gradle/managing-dependencies/configure-bom-with-plugins")
|
||||
.build("dependencyManagement").getOutput())
|
||||
.contains("org.springframework.boot:spring-boot-starter TEST-SNAPSHOT"));
|
||||
}
|
||||
|
||||
@@ -49,12 +49,12 @@ class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void warContainerDependencyEvaluatesSuccessfully() {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/war-container-dependency").build();
|
||||
this.gradleBuild.script("src/docs/gradle/packaging/war-container-dependency").build();
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void bootJarMainClass() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-main-class").build("bootJar");
|
||||
this.gradleBuild.script("src/docs/gradle/packaging/boot-jar-main-class").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -66,7 +66,7 @@ class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void bootJarManifestMainClass() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-manifest-main-class").build("bootJar");
|
||||
this.gradleBuild.script("src/docs/gradle/packaging/boot-jar-manifest-main-class").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -78,7 +78,7 @@ class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void applicationPluginMainClass() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/application-plugin-main-class").build("bootJar");
|
||||
this.gradleBuild.script("src/docs/gradle/packaging/application-plugin-main-class").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -90,7 +90,7 @@ class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void springBootDslMainClass() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/spring-boot-dsl-main-class").build("bootJar");
|
||||
this.gradleBuild.script("src/docs/gradle/packaging/spring-boot-dsl-main-class").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -103,7 +103,7 @@ class PackagingDocumentationTests {
|
||||
@TestTemplate
|
||||
void bootWarIncludeDevtools() throws IOException {
|
||||
jarFile(new File(this.gradleBuild.getProjectDir(), "spring-boot-devtools-1.2.3.RELEASE.jar"));
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-war-include-devtools").build("bootWar");
|
||||
this.gradleBuild.script("src/docs/gradle/packaging/boot-war-include-devtools").build("bootWar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".war");
|
||||
assertThat(file).isFile();
|
||||
@@ -114,7 +114,7 @@ class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void bootJarRequiresUnpack() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-requires-unpack").build("bootJar");
|
||||
this.gradleBuild.script("src/docs/gradle/packaging/boot-jar-requires-unpack").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -127,7 +127,7 @@ class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void bootJarIncludeLaunchScript() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-include-launch-script").build("bootJar");
|
||||
this.gradleBuild.script("src/docs/gradle/packaging/boot-jar-include-launch-script").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -136,7 +136,7 @@ class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void bootJarLaunchScriptProperties() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-launch-script-properties").build("bootJar");
|
||||
this.gradleBuild.script("src/docs/gradle/packaging/boot-jar-launch-script-properties").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -148,7 +148,7 @@ class PackagingDocumentationTests {
|
||||
File customScriptFile = new File(this.gradleBuild.getProjectDir(), "src/custom.script");
|
||||
customScriptFile.getParentFile().mkdirs();
|
||||
FileCopyUtils.copy("custom", new FileWriter(customScriptFile));
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-custom-launch-script").build("bootJar");
|
||||
this.gradleBuild.script("src/docs/gradle/packaging/boot-jar-custom-launch-script").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -157,7 +157,7 @@ class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void bootWarPropertiesLauncher() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-war-properties-launcher").build("bootWar");
|
||||
this.gradleBuild.script("src/docs/gradle/packaging/boot-war-properties-launcher").build("bootWar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".war");
|
||||
assertThat(file).isFile();
|
||||
@@ -169,7 +169,7 @@ class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void bootJarAndJar() {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-and-jar").build("assemble");
|
||||
this.gradleBuild.script("src/docs/gradle/packaging/boot-jar-and-jar").build("assemble");
|
||||
File jar = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(jar).isFile();
|
||||
|
||||
@@ -39,13 +39,13 @@ class PublishingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
void mavenUpload() throws IOException {
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven").build("deployerRepository").getOutput())
|
||||
assertThat(this.gradleBuild.script("src/docs/gradle/publishing/maven").build("deployerRepository").getOutput())
|
||||
.contains("https://repo.example.com");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void mavenPublish() throws IOException {
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven-publish").build("publishingConfiguration")
|
||||
assertThat(this.gradleBuild.script("src/docs/gradle/publishing/maven-publish").build("publishingConfiguration")
|
||||
.getOutput()).contains("MavenPublication").contains("https://repo.example.com");
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
import org.junit.jupiter.api.condition.DisabledOnJre;
|
||||
import org.junit.jupiter.api.condition.JRE;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
|
||||
@@ -39,32 +41,35 @@ class RunningDocumentationTests {
|
||||
GradleBuild gradleBuild;
|
||||
|
||||
@TestTemplate
|
||||
@DisabledOnJre(JRE.JAVA_13)
|
||||
void bootRunMain() throws IOException {
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/running/boot-run-main").build("configuredMainClass")
|
||||
.getOutput()).contains("com.example.ExampleApplication");
|
||||
// TODO Testing of convention mappings is flakey in 5.2+
|
||||
// https://github.com/gradle/gradle/issues/11323
|
||||
assertThat(this.gradleBuild.gradleVersion("5.1.1").script("src/docs/gradle/running/boot-run-main")
|
||||
.build("configuredMainClass").getOutput()).contains("com.example.ExampleApplication");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void applicationPluginMainClassName() {
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/running/application-plugin-main-class-name")
|
||||
assertThat(this.gradleBuild.script("src/docs/gradle/running/application-plugin-main-class-name")
|
||||
.build("configuredMainClass").getOutput()).contains("com.example.ExampleApplication");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void springBootDslMainClassName() throws IOException {
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/running/spring-boot-dsl-main-class-name")
|
||||
assertThat(this.gradleBuild.script("src/docs/gradle/running/spring-boot-dsl-main-class-name")
|
||||
.build("configuredMainClass").getOutput()).contains("com.example.ExampleApplication");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void bootRunSourceResources() throws IOException {
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/running/boot-run-source-resources")
|
||||
assertThat(this.gradleBuild.script("src/docs/gradle/running/boot-run-source-resources")
|
||||
.build("configuredClasspath").getOutput()).contains(new File("src/main/resources").getPath());
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
void bootRunDisableOptimizedLaunch() throws IOException {
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/running/boot-run-disable-optimized-launch")
|
||||
assertThat(this.gradleBuild.script("src/docs/gradle/running/boot-run-disable-optimized-launch")
|
||||
.build("optimizedLaunch").getOutput()).contains("false");
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
package org.springframework.boot.gradle.junit;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.gradle.api.JavaVersion;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
import org.junit.jupiter.api.extension.Extension;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
@@ -38,8 +40,17 @@ import org.springframework.boot.gradle.testkit.GradleBuildExtension;
|
||||
*/
|
||||
public final class GradleCompatibilityExtension implements TestTemplateInvocationContextProvider {
|
||||
|
||||
private static final List<String> GRADLE_VERSIONS = Arrays.asList("default", "5.0", "5.1.1", "5.2.1", "5.3.1",
|
||||
"5.4.1", "5.5.1", "5.6.4", "6.0.1");
|
||||
private static final List<String> GRADLE_VERSIONS;
|
||||
|
||||
static {
|
||||
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_13)) {
|
||||
GRADLE_VERSIONS = Collections.singletonList("default");
|
||||
}
|
||||
else {
|
||||
GRADLE_VERSIONS = Arrays.asList("4.10.3", "5.0", "5.1.1", "5.2.1", "5.3.1", "5.4.1", "5.5.1", "5.6.4",
|
||||
"default");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
|
||||
|
||||
@@ -99,8 +99,7 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
void basicArchiveCreation() throws IOException {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
executeTask();
|
||||
assertThat(this.task.getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class")).isEqualTo(this.launcherClass);
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class")).isEqualTo("com.example.Main");
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Classes"))
|
||||
@@ -115,7 +114,7 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.classpath(jarFile("one.jar"), jarFile("two.jar"));
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry(this.libPath + "one.jar")).isNotNull();
|
||||
assertThat(jarFile.getEntry(this.libPath + "two.jar")).isNotNull();
|
||||
}
|
||||
@@ -130,7 +129,7 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
applicationClass.createNewFile();
|
||||
this.task.classpath(classpathFolder);
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry(this.classesPath + "com/example/Application.class")).isNotNull();
|
||||
}
|
||||
}
|
||||
@@ -146,8 +145,8 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
applicationClass.getParentFile().mkdirs();
|
||||
applicationClass.createNewFile();
|
||||
this.task.classpath(classpathFolder);
|
||||
this.task.execute();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry(this.classesPath + "com/example/Application.class")).isNotNull();
|
||||
assertThat(jarFile.getEntry("com/example/Application.class")).isNull();
|
||||
assertThat(jarFile.getEntry("module-info.class")).isNotNull();
|
||||
@@ -161,7 +160,7 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.classpath(jarFile("one.jar"));
|
||||
this.task.setClasspath(this.task.getProject().files(jarFile("two.jar")));
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry(this.libPath + "one.jar")).isNull();
|
||||
assertThat(jarFile.getEntry(this.libPath + "two.jar")).isNotNull();
|
||||
}
|
||||
@@ -173,7 +172,7 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.classpath(jarFile("one.jar"));
|
||||
this.task.setClasspath(jarFile("two.jar"));
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry(this.libPath + "one.jar")).isNull();
|
||||
assertThat(jarFile.getEntry(this.libPath + "two.jar")).isNotNull();
|
||||
}
|
||||
@@ -183,8 +182,8 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
void filesOnTheClasspathThatAreNotZipFilesAreSkipped() throws IOException {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.classpath(new File("test.pom"));
|
||||
this.task.execute();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry(this.libPath + "/test.pom")).isNull();
|
||||
}
|
||||
}
|
||||
@@ -193,12 +192,13 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
void loaderIsWrittenToTheRootOfTheJarAfterManifest() throws IOException {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry("org/springframework/boot/loader/LaunchedURLClassLoader.class")).isNotNull();
|
||||
assertThat(jarFile.getEntry("org/springframework/boot/loader/")).isNotNull();
|
||||
}
|
||||
// gh-16698
|
||||
try (ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(this.task.getArchivePath()))) {
|
||||
try (ZipInputStream zipInputStream = new ZipInputStream(
|
||||
new FileInputStream(this.task.getArchiveFile().get().getAsFile()))) {
|
||||
assertThat(zipInputStream.getNextEntry().getName()).isEqualTo("META-INF/");
|
||||
assertThat(zipInputStream.getNextEntry().getName()).isEqualTo("META-INF/MANIFEST.MF");
|
||||
}
|
||||
@@ -209,7 +209,7 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
executeTask();
|
||||
this.task.getManifest().getAttributes().put("Main-Class", "org.springframework.boot.loader.PropertiesLauncher");
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry("org/springframework/boot/loader/LaunchedURLClassLoader.class")).isNotNull();
|
||||
assertThat(jarFile.getEntry("org/springframework/boot/loader/")).isNotNull();
|
||||
}
|
||||
@@ -221,7 +221,7 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.classpath(jarFile("one.jar"), jarFile("two.jar"));
|
||||
this.task.requiresUnpack("**/one.jar");
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry(this.libPath + "one.jar").getComment()).startsWith("UNPACK:");
|
||||
assertThat(jarFile.getEntry(this.libPath + "two.jar").getComment()).isNull();
|
||||
}
|
||||
@@ -233,7 +233,7 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.classpath(jarFile("one.jar"), jarFile("two.jar"));
|
||||
this.task.requiresUnpack((element) -> element.getName().endsWith("two.jar"));
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry(this.libPath + "two.jar").getComment()).startsWith("UNPACK:");
|
||||
assertThat(jarFile.getEntry(this.libPath + "one.jar").getComment()).isNull();
|
||||
}
|
||||
@@ -245,13 +245,14 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.launchScript();
|
||||
executeTask();
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put("initInfoProvides", this.task.getBaseName());
|
||||
properties.put("initInfoProvides", this.task.getArchiveBaseName().get());
|
||||
properties.put("initInfoShortDescription", this.project.getDescription());
|
||||
properties.put("initInfoDescription", this.project.getDescription());
|
||||
assertThat(Files.readAllBytes(this.task.getArchivePath().toPath()))
|
||||
assertThat(Files.readAllBytes(this.task.getArchiveFile().get().getAsFile().toPath()))
|
||||
.startsWith(new DefaultLaunchScript(null, properties).toByteArray());
|
||||
try {
|
||||
Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(this.task.getArchivePath().toPath());
|
||||
Set<PosixFilePermission> permissions = Files
|
||||
.getPosixFilePermissions(this.task.getArchiveFile().get().getAsFile().toPath());
|
||||
assertThat(permissions).contains(PosixFilePermission.OWNER_EXECUTE);
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
@@ -266,7 +267,8 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
Files.write(customScript.toPath(), Arrays.asList("custom script"), StandardOpenOption.CREATE);
|
||||
this.task.launchScript((configuration) -> configuration.setScript(customScript));
|
||||
executeTask();
|
||||
assertThat(Files.readAllBytes(this.task.getArchivePath().toPath())).startsWith("custom script".getBytes());
|
||||
assertThat(Files.readAllBytes(this.task.getArchiveFile().get().getAsFile().toPath()))
|
||||
.startsWith("custom script".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -278,7 +280,7 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
configuration.getProperties().put("initInfoDescription", "description");
|
||||
});
|
||||
executeTask();
|
||||
byte[] bytes = Files.readAllBytes(this.task.getArchivePath().toPath());
|
||||
byte[] bytes = Files.readAllBytes(this.task.getArchiveFile().get().getAsFile().toPath());
|
||||
assertThat(bytes).containsSequence("Provides: provides".getBytes());
|
||||
assertThat(bytes).containsSequence("Short-Description: short description".getBytes());
|
||||
assertThat(bytes).containsSequence("Description: description".getBytes());
|
||||
@@ -289,8 +291,8 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.getManifest().getAttributes().put("Main-Class", "com.example.CustomLauncher");
|
||||
executeTask();
|
||||
assertThat(this.task.getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(this.task.getArchiveFile().get().getAsFile()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class"))
|
||||
.isEqualTo("com.example.CustomLauncher");
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class")).isEqualTo("com.example.Main");
|
||||
@@ -303,8 +305,8 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.getManifest().getAttributes().put("Start-Class", "com.example.CustomMain");
|
||||
executeTask();
|
||||
assertThat(this.task.getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(this.task.getArchiveFile().get().getAsFile()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class")).isEqualTo(this.launcherClass);
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
|
||||
.isEqualTo("com.example.CustomMain");
|
||||
@@ -316,8 +318,8 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.setPreserveFileTimestamps(false);
|
||||
executeTask();
|
||||
assertThat(this.task.getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(this.task.getArchiveFile().get().getAsFile()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
Enumeration<JarEntry> entries = jarFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
@@ -332,9 +334,9 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.from(newFile("bravo.txt"), newFile("alpha.txt"), newFile("charlie.txt"));
|
||||
this.task.setReproducibleFileOrder(true);
|
||||
executeTask();
|
||||
assertThat(this.task.getArchivePath()).exists();
|
||||
assertThat(this.task.getArchiveFile().get().getAsFile()).exists();
|
||||
List<String> textFiles = new ArrayList<>();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
Enumeration<JarEntry> entries = jarFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
@@ -351,8 +353,8 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.classpath(newFile("spring-boot-devtools-0.1.2.jar"));
|
||||
executeTask();
|
||||
assertThat(this.task.getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(this.task.getArchiveFile().get().getAsFile()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar")).isNull();
|
||||
}
|
||||
}
|
||||
@@ -363,8 +365,8 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.classpath(jarFile("spring-boot-devtools-0.1.2.jar"));
|
||||
this.task.setExcludeDevtools(false);
|
||||
executeTask();
|
||||
assertThat(this.task.getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(this.task.getArchiveFile().get().getAsFile()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar")).isNotNull();
|
||||
}
|
||||
}
|
||||
@@ -379,7 +381,7 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
resource.createNewFile();
|
||||
this.task.classpath(classpathFolder);
|
||||
executeTask();
|
||||
File archivePath = this.task.getArchivePath();
|
||||
File archivePath = this.task.getArchiveFile().get().getAsFile();
|
||||
try (ZipFile zip = new ZipFile(archivePath)) {
|
||||
Enumeration<ZipArchiveEntry> entries = zip.getEntries();
|
||||
while (entries.hasMoreElements()) {
|
||||
@@ -401,9 +403,10 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
jarFile("third-library.jar"));
|
||||
this.task.requiresUnpack("second-library.jar");
|
||||
executeTask();
|
||||
assertThat(getEntryNames(this.task.getArchivePath())).containsSubsequence("org/springframework/boot/loader/",
|
||||
this.classesPath + "com/example/Application.class", this.libPath + "first-library.jar",
|
||||
this.libPath + "second-library.jar", this.libPath + "third-library.jar");
|
||||
assertThat(getEntryNames(this.task.getArchiveFile().get().getAsFile())).containsSubsequence(
|
||||
"org/springframework/boot/loader/", this.classesPath + "com/example/Application.class",
|
||||
this.libPath + "first-library.jar", this.libPath + "second-library.jar",
|
||||
this.libPath + "third-library.jar");
|
||||
}
|
||||
|
||||
protected File jarFile(String name) throws IOException {
|
||||
@@ -418,10 +421,10 @@ abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
private T configure(T task) throws IOException {
|
||||
AbstractArchiveTask archiveTask = task;
|
||||
archiveTask.setBaseName("test");
|
||||
archiveTask.getArchiveBaseName().set("test");
|
||||
File destination = new File(this.temp, "destination");
|
||||
destination.mkdirs();
|
||||
archiveTask.setDestinationDir(destination);
|
||||
archiveTask.getDestinationDirectory().set(destination);
|
||||
return task;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class BootJarTests extends AbstractBootArchiveTests<BootJar> {
|
||||
bootJar.setMainClassName("com.example.Application");
|
||||
bootJar.getBootInf().into("test").from(new File("build.gradle").getAbsolutePath());
|
||||
bootJar.copy();
|
||||
try (JarFile jarFile = new JarFile(bootJar.getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(bootJar.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getJarEntry("BOOT-INF/test/build.gradle")).isNotNull();
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class BootJarTests extends AbstractBootArchiveTests<BootJar> {
|
||||
bootJar.setMainClassName("com.example.Application");
|
||||
bootJar.bootInf((copySpec) -> copySpec.into("test").from(new File("build.gradle").getAbsolutePath()));
|
||||
bootJar.copy();
|
||||
try (JarFile jarFile = new JarFile(bootJar.getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(bootJar.getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getJarEntry("BOOT-INF/test/build.gradle")).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
getTask().setMainClassName("com.example.Main");
|
||||
getTask().providedClasspath(jarFile("one.jar"), jarFile("two.jar"));
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry("WEB-INF/lib-provided/one.jar")).isNotNull();
|
||||
assertThat(jarFile.getEntry("WEB-INF/lib-provided/two.jar")).isNotNull();
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
getTask().providedClasspath(jarFile("one.jar"));
|
||||
getTask().setProvidedClasspath(getTask().getProject().files(jarFile("two.jar")));
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry("WEB-INF/lib-provided/one.jar")).isNull();
|
||||
assertThat(jarFile.getEntry("WEB-INF/lib-provided/two.jar")).isNotNull();
|
||||
}
|
||||
@@ -64,7 +64,7 @@ class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
getTask().providedClasspath(jarFile("one.jar"));
|
||||
getTask().setProvidedClasspath(jarFile("two.jar"));
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry("WEB-INF/lib-provided/one.jar")).isNull();
|
||||
assertThat(jarFile.getEntry("WEB-INF/lib-provided/two.jar")).isNotNull();
|
||||
}
|
||||
@@ -75,8 +75,7 @@ class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
getTask().setMainClassName("com.example.Main");
|
||||
getTask().providedClasspath(newFile("spring-boot-devtools-0.1.2.jar"));
|
||||
executeTask();
|
||||
assertThat(getTask().getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry("WEB-INF/lib-provided/spring-boot-devtools-0.1.2.jar")).isNull();
|
||||
}
|
||||
}
|
||||
@@ -87,8 +86,7 @@ class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
getTask().providedClasspath(jarFile("spring-boot-devtools-0.1.2.jar"));
|
||||
getTask().setExcludeDevtools(false);
|
||||
executeTask();
|
||||
assertThat(getTask().getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry("WEB-INF/lib-provided/spring-boot-devtools-0.1.2.jar")).isNotNull();
|
||||
}
|
||||
}
|
||||
@@ -103,8 +101,7 @@ class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
getTask().from(webappFolder);
|
||||
getTask().setMainClassName("com.example.Main");
|
||||
executeTask();
|
||||
assertThat(getTask().getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchiveFile().get().getAsFile())) {
|
||||
assertThat(jarFile.getEntry("org/")).isNotNull();
|
||||
assertThat(jarFile.getEntry("org/foo.txt")).isNotNull();
|
||||
}
|
||||
@@ -116,8 +113,8 @@ class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
getTask().classpath(jarFile("library.jar"));
|
||||
getTask().providedClasspath(jarFile("provided-library.jar"));
|
||||
executeTask();
|
||||
assertThat(getEntryNames(getTask().getArchivePath())).containsSubsequence("WEB-INF/lib/library.jar",
|
||||
"WEB-INF/lib-provided/provided-library.jar");
|
||||
assertThat(getEntryNames(getTask().getArchiveFile().get().getAsFile()))
|
||||
.containsSubsequence("WEB-INF/lib/library.jar", "WEB-INF/lib-provided/provided-library.jar");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.boot.gradle.tasks.bundling;
|
||||
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.provider.Property;
|
||||
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -43,7 +44,8 @@ class LaunchScriptConfigurationTests {
|
||||
|
||||
@Test
|
||||
void initInfoProvidesUsesArchiveBaseNameByDefault() {
|
||||
given(this.task.getBaseName()).willReturn("base-name");
|
||||
Property<String> baseName = stringProperty("base-name");
|
||||
given(this.task.getArchiveBaseName()).willReturn(baseName);
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoProvides",
|
||||
"base-name");
|
||||
}
|
||||
@@ -57,7 +59,8 @@ class LaunchScriptConfigurationTests {
|
||||
|
||||
@Test
|
||||
void initInfoShortDescriptionUsesArchiveBaseNameWhenDescriptionIsNull() {
|
||||
given(this.task.getBaseName()).willReturn("base-name");
|
||||
Property<String> baseName = stringProperty("base-name");
|
||||
given(this.task.getArchiveBaseName()).willReturn(baseName);
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoShortDescription",
|
||||
"base-name");
|
||||
}
|
||||
@@ -71,7 +74,8 @@ class LaunchScriptConfigurationTests {
|
||||
|
||||
@Test
|
||||
void initInfoDescriptionUsesArchiveBaseNameWhenDescriptionIsNull() {
|
||||
given(this.task.getBaseName()).willReturn("base-name");
|
||||
Property<String> baseName = stringProperty("base-name");
|
||||
given(this.task.getArchiveBaseName()).willReturn(baseName);
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoDescription",
|
||||
"base-name");
|
||||
}
|
||||
@@ -90,4 +94,11 @@ class LaunchScriptConfigurationTests {
|
||||
"The\n# project\n# description");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Property<String> stringProperty(String value) {
|
||||
Property<String> property = mock(Property.class);
|
||||
given(property.get()).willReturn(value);
|
||||
return property;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.springframework.boot.gradle.tasks.run;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.gradle.api.JavaVersion;
|
||||
import org.gradle.testkit.runner.BuildResult;
|
||||
import org.gradle.testkit.runner.TaskOutcome;
|
||||
import org.junit.jupiter.api.TestTemplate;
|
||||
@@ -88,7 +89,12 @@ class BootRunIntegrationTests {
|
||||
copyJvmArgsApplication();
|
||||
BuildResult result = this.gradleBuild.build("bootRun");
|
||||
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).contains("1. -Xverify:none").contains("2. -XX:TieredStopAtLevel=1");
|
||||
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_13)) {
|
||||
assertThat(result.getOutput()).contains("1. -XX:TieredStopAtLevel=1");
|
||||
}
|
||||
else {
|
||||
assertThat(result.getOutput()).contains("1. -Xverify:none").contains("2. -XX:TieredStopAtLevel=1");
|
||||
}
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
@@ -104,8 +110,14 @@ class BootRunIntegrationTests {
|
||||
copyJvmArgsApplication();
|
||||
BuildResult result = this.gradleBuild.build("bootRun");
|
||||
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).contains("1. -Dcom.bar=baz").contains("2. -Dcom.foo=bar")
|
||||
.contains("3. -Xverify:none").contains("4. -XX:TieredStopAtLevel=1");
|
||||
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_13)) {
|
||||
assertThat(result.getOutput()).contains("1. -Dcom.bar=baz").contains("2. -Dcom.foo=bar")
|
||||
.contains("3. -XX:TieredStopAtLevel=1");
|
||||
}
|
||||
else {
|
||||
assertThat(result.getOutput()).contains("1. -Dcom.bar=baz").contains("2. -Dcom.foo=bar")
|
||||
.contains("3. -Xverify:none").contains("4. -XX:TieredStopAtLevel=1");
|
||||
}
|
||||
}
|
||||
|
||||
private void copyClasspathApplication() throws IOException {
|
||||
|
||||
Reference in New Issue
Block a user