Migrate spring-boot-gradle-plugin's tests to JUnit 5
Closes gh-16959
This commit is contained in:
parent
5e62faf720
commit
babb94c791
|
@ -36,6 +36,7 @@ jar {
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
testLogging {
|
testLogging {
|
||||||
events "passed", "skipped", "failed"
|
events "passed", "skipped", "failed"
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,8 +84,8 @@ public class SpringBootPlugin implements Plugin<Project> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyGradleVersion() {
|
private void verifyGradleVersion() {
|
||||||
if (GradleVersion.current().compareTo(GradleVersion.version("4.4")) < 0) {
|
if (GradleVersion.current().compareTo(GradleVersion.version("4.10")) < 0) {
|
||||||
throw new GradleException("Spring Boot plugin requires Gradle 4.4 or later."
|
throw new GradleException("Spring Boot plugin requires Gradle 4.10 or later."
|
||||||
+ " The current version is " + GradleVersion.current());
|
+ " The current version is " + GradleVersion.current());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -16,11 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.boot.gradle.docs;
|
package org.springframework.boot.gradle.docs;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
|
import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,16 +28,15 @@ import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Jean-Baptiste Nizet
|
* @author Jean-Baptiste Nizet
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleMultiDslSuite.class)
|
@ExtendWith(GradleMultiDslExtension.class)
|
||||||
public class GettingStartedDocumentationTests {
|
public class GettingStartedDocumentationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
// NOTE: We can't run any `apply-plugin` tests because during a release the
|
// NOTE: We can't run any `apply-plugin` tests because during a release the
|
||||||
// jar won't be there
|
// jar won't be there
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void typicalPluginsAppliesExceptedPlugins() {
|
public void typicalPluginsAppliesExceptedPlugins() {
|
||||||
this.gradleBuild.script("src/main/gradle/getting-started/typical-plugins")
|
this.gradleBuild.script("src/main/gradle/getting-started/typical-plugins")
|
||||||
.build("verify");
|
.build("verify");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -21,11 +21,10 @@ import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
|
import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -36,13 +35,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Jean-Baptiste Nizet
|
* @author Jean-Baptiste Nizet
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleMultiDslSuite.class)
|
@ExtendWith(GradleMultiDslExtension.class)
|
||||||
public class IntegratingWithActuatorDocumentationTests {
|
public class IntegratingWithActuatorDocumentationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void basicBuildInfo() throws IOException {
|
public void basicBuildInfo() throws IOException {
|
||||||
this.gradleBuild
|
this.gradleBuild
|
||||||
.script("src/main/gradle/integrating-with-actuator/build-info-basic")
|
.script("src/main/gradle/integrating-with-actuator/build-info-basic")
|
||||||
|
@ -51,7 +49,7 @@ public class IntegratingWithActuatorDocumentationTests {
|
||||||
"build/resources/main/META-INF/build-info.properties")).isFile();
|
"build/resources/main/META-INF/build-info.properties")).isFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void buildInfoCustomValues() throws IOException {
|
public void buildInfoCustomValues() throws IOException {
|
||||||
this.gradleBuild.script(
|
this.gradleBuild.script(
|
||||||
"src/main/gradle/integrating-with-actuator/build-info-custom-values")
|
"src/main/gradle/integrating-with-actuator/build-info-custom-values")
|
||||||
|
@ -66,7 +64,7 @@ public class IntegratingWithActuatorDocumentationTests {
|
||||||
assertThat(properties).containsEntry("build.name", "Example application");
|
assertThat(properties).containsEntry("build.name", "Example application");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void buildInfoAdditional() throws IOException {
|
public void buildInfoAdditional() throws IOException {
|
||||||
this.gradleBuild
|
this.gradleBuild
|
||||||
.script("src/main/gradle/integrating-with-actuator/build-info-additional")
|
.script("src/main/gradle/integrating-with-actuator/build-info-additional")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -17,11 +17,10 @@
|
||||||
package org.springframework.boot.gradle.docs;
|
package org.springframework.boot.gradle.docs;
|
||||||
|
|
||||||
import org.junit.Assume;
|
import org.junit.Assume;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
|
import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
|
||||||
import org.springframework.boot.gradle.testkit.Dsl;
|
import org.springframework.boot.gradle.testkit.Dsl;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
|
@ -33,26 +32,25 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Jean-Baptiste Nizet
|
* @author Jean-Baptiste Nizet
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleMultiDslSuite.class)
|
@ExtendWith(GradleMultiDslExtension.class)
|
||||||
public class ManagingDependenciesDocumentationTests {
|
public class ManagingDependenciesDocumentationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void dependenciesExampleEvaluatesSuccessfully() {
|
public void dependenciesExampleEvaluatesSuccessfully() {
|
||||||
this.gradleBuild.script("src/main/gradle/managing-dependencies/dependencies")
|
this.gradleBuild.script("src/main/gradle/managing-dependencies/dependencies")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void customManagedVersions() {
|
public void customManagedVersions() {
|
||||||
assertThat(this.gradleBuild
|
assertThat(this.gradleBuild
|
||||||
.script("src/main/gradle/managing-dependencies/custom-version")
|
.script("src/main/gradle/managing-dependencies/custom-version")
|
||||||
.build("slf4jVersion").getOutput()).contains("1.7.20");
|
.build("slf4jVersion").getOutput()).contains("1.7.20");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void dependencyManagementInIsolation() {
|
public void dependencyManagementInIsolation() {
|
||||||
assertThat(this.gradleBuild
|
assertThat(this.gradleBuild
|
||||||
.script("src/main/gradle/managing-dependencies/configure-bom")
|
.script("src/main/gradle/managing-dependencies/configure-bom")
|
||||||
|
@ -60,7 +58,7 @@ public class ManagingDependenciesDocumentationTests {
|
||||||
.contains("org.springframework.boot:spring-boot-starter ");
|
.contains("org.springframework.boot:spring-boot-starter ");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void dependencyManagementInIsolationWithPluginsBlock() {
|
public void dependencyManagementInIsolationWithPluginsBlock() {
|
||||||
Assume.assumeTrue(this.gradleBuild.getDsl() == Dsl.KOTLIN);
|
Assume.assumeTrue(this.gradleBuild.getDsl() == Dsl.KOTLIN);
|
||||||
assertThat(this.gradleBuild.script(
|
assertThat(this.gradleBuild.script(
|
||||||
|
|
|
@ -27,12 +27,10 @@ import java.util.jar.JarOutputStream;
|
||||||
import java.util.jar.Manifest;
|
import java.util.jar.Manifest;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
|
import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
|
||||||
import org.springframework.boot.gradle.testkit.Dsl;
|
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
import org.springframework.util.FileCopyUtils;
|
import org.springframework.util.FileCopyUtils;
|
||||||
|
|
||||||
|
@ -44,21 +42,18 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Jean-Baptiste Nizet
|
* @author Jean-Baptiste Nizet
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleMultiDslSuite.class)
|
@ExtendWith(GradleMultiDslExtension.class)
|
||||||
public class PackagingDocumentationTests {
|
public class PackagingDocumentationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
public Dsl dsl;
|
@TestTemplate
|
||||||
|
|
||||||
@Test
|
|
||||||
public void warContainerDependencyEvaluatesSuccessfully() {
|
public void warContainerDependencyEvaluatesSuccessfully() {
|
||||||
this.gradleBuild.script("src/main/gradle/packaging/war-container-dependency")
|
this.gradleBuild.script("src/main/gradle/packaging/war-container-dependency")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootJarMainClass() throws IOException {
|
public void bootJarMainClass() throws IOException {
|
||||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-main-class")
|
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-main-class")
|
||||||
.build("bootJar");
|
.build("bootJar");
|
||||||
|
@ -71,7 +66,7 @@ public class PackagingDocumentationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootJarManifestMainClass() throws IOException {
|
public void bootJarManifestMainClass() throws IOException {
|
||||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-manifest-main-class")
|
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-manifest-main-class")
|
||||||
.build("bootJar");
|
.build("bootJar");
|
||||||
|
@ -84,7 +79,7 @@ public class PackagingDocumentationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void applicationPluginMainClass() throws IOException {
|
public void applicationPluginMainClass() throws IOException {
|
||||||
this.gradleBuild.script("src/main/gradle/packaging/application-plugin-main-class")
|
this.gradleBuild.script("src/main/gradle/packaging/application-plugin-main-class")
|
||||||
.build("bootJar");
|
.build("bootJar");
|
||||||
|
@ -97,7 +92,7 @@ public class PackagingDocumentationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void springBootDslMainClass() throws IOException {
|
public void springBootDslMainClass() throws IOException {
|
||||||
this.gradleBuild.script("src/main/gradle/packaging/spring-boot-dsl-main-class")
|
this.gradleBuild.script("src/main/gradle/packaging/spring-boot-dsl-main-class")
|
||||||
.build("bootJar");
|
.build("bootJar");
|
||||||
|
@ -110,7 +105,7 @@ public class PackagingDocumentationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootWarIncludeDevtools() throws IOException {
|
public void bootWarIncludeDevtools() throws IOException {
|
||||||
jarFile(new File(this.gradleBuild.getProjectDir(),
|
jarFile(new File(this.gradleBuild.getProjectDir(),
|
||||||
"spring-boot-devtools-1.2.3.RELEASE.jar"));
|
"spring-boot-devtools-1.2.3.RELEASE.jar"));
|
||||||
|
@ -125,7 +120,7 @@ public class PackagingDocumentationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootJarRequiresUnpack() throws IOException {
|
public void bootJarRequiresUnpack() throws IOException {
|
||||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-requires-unpack")
|
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-requires-unpack")
|
||||||
.build("bootJar");
|
.build("bootJar");
|
||||||
|
@ -139,7 +134,7 @@ public class PackagingDocumentationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootJarIncludeLaunchScript() throws IOException {
|
public void bootJarIncludeLaunchScript() throws IOException {
|
||||||
this.gradleBuild
|
this.gradleBuild
|
||||||
.script("src/main/gradle/packaging/boot-jar-include-launch-script")
|
.script("src/main/gradle/packaging/boot-jar-include-launch-script")
|
||||||
|
@ -151,7 +146,7 @@ public class PackagingDocumentationTests {
|
||||||
.startsWith("#!/bin/bash");
|
.startsWith("#!/bin/bash");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootJarLaunchScriptProperties() throws IOException {
|
public void bootJarLaunchScriptProperties() throws IOException {
|
||||||
this.gradleBuild
|
this.gradleBuild
|
||||||
.script("src/main/gradle/packaging/boot-jar-launch-script-properties")
|
.script("src/main/gradle/packaging/boot-jar-launch-script-properties")
|
||||||
|
@ -163,7 +158,7 @@ public class PackagingDocumentationTests {
|
||||||
.contains("example-app.log");
|
.contains("example-app.log");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootJarCustomLaunchScript() throws IOException {
|
public void bootJarCustomLaunchScript() throws IOException {
|
||||||
File customScriptFile = new File(this.gradleBuild.getProjectDir(),
|
File customScriptFile = new File(this.gradleBuild.getProjectDir(),
|
||||||
"src/custom.script");
|
"src/custom.script");
|
||||||
|
@ -177,7 +172,7 @@ public class PackagingDocumentationTests {
|
||||||
assertThat(FileCopyUtils.copyToString(new FileReader(file))).startsWith("custom");
|
assertThat(FileCopyUtils.copyToString(new FileReader(file))).startsWith("custom");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootWarPropertiesLauncher() throws IOException {
|
public void bootWarPropertiesLauncher() throws IOException {
|
||||||
this.gradleBuild.script("src/main/gradle/packaging/boot-war-properties-launcher")
|
this.gradleBuild.script("src/main/gradle/packaging/boot-war-properties-launcher")
|
||||||
.build("bootWar");
|
.build("bootWar");
|
||||||
|
@ -190,7 +185,7 @@ public class PackagingDocumentationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootJarAndJar() {
|
public void bootJarAndJar() {
|
||||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-and-jar")
|
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-and-jar")
|
||||||
.build("assemble");
|
.build("assemble");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -18,11 +18,10 @@ package org.springframework.boot.gradle.docs;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
|
import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -33,20 +32,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Jean-Baptiste Nizet
|
* @author Jean-Baptiste Nizet
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleMultiDslSuite.class)
|
@ExtendWith(GradleMultiDslExtension.class)
|
||||||
public class PublishingDocumentationTests {
|
public class PublishingDocumentationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void mavenUpload() throws IOException {
|
public void mavenUpload() throws IOException {
|
||||||
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven")
|
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven")
|
||||||
.build("deployerRepository").getOutput())
|
.build("deployerRepository").getOutput())
|
||||||
.contains("https://repo.example.com");
|
.contains("https://repo.example.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void mavenPublish() throws IOException {
|
public void mavenPublish() throws IOException {
|
||||||
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven-publish")
|
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven-publish")
|
||||||
.build("publishingConfiguration").getOutput())
|
.build("publishingConfiguration").getOutput())
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -19,11 +19,10 @@ package org.springframework.boot.gradle.docs;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleMultiDslSuite;
|
import org.springframework.boot.gradle.junit.GradleMultiDslExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -34,20 +33,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
* @author Jean-Baptiste Nizet
|
* @author Jean-Baptiste Nizet
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleMultiDslSuite.class)
|
@ExtendWith(GradleMultiDslExtension.class)
|
||||||
public class RunningDocumentationTests {
|
public class RunningDocumentationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootRunMain() throws IOException {
|
public void bootRunMain() throws IOException {
|
||||||
assertThat(this.gradleBuild.script("src/main/gradle/running/boot-run-main")
|
assertThat(this.gradleBuild.script("src/main/gradle/running/boot-run-main")
|
||||||
.build("configuredMainClass").getOutput())
|
.build("configuredMainClass").getOutput())
|
||||||
.contains("com.example.ExampleApplication");
|
.contains("com.example.ExampleApplication");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void applicationPluginMainClassName() {
|
public void applicationPluginMainClassName() {
|
||||||
assertThat(this.gradleBuild
|
assertThat(this.gradleBuild
|
||||||
.script("src/main/gradle/running/application-plugin-main-class-name")
|
.script("src/main/gradle/running/application-plugin-main-class-name")
|
||||||
|
@ -55,7 +53,7 @@ public class RunningDocumentationTests {
|
||||||
.contains("com.example.ExampleApplication");
|
.contains("com.example.ExampleApplication");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void springBootDslMainClassName() throws IOException {
|
public void springBootDslMainClassName() throws IOException {
|
||||||
assertThat(this.gradleBuild
|
assertThat(this.gradleBuild
|
||||||
.script("src/main/gradle/running/spring-boot-dsl-main-class-name")
|
.script("src/main/gradle/running/spring-boot-dsl-main-class-name")
|
||||||
|
@ -63,7 +61,7 @@ public class RunningDocumentationTests {
|
||||||
.contains("com.example.ExampleApplication");
|
.contains("com.example.ExampleApplication");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootRunSourceResources() throws IOException {
|
public void bootRunSourceResources() throws IOException {
|
||||||
assertThat(this.gradleBuild
|
assertThat(this.gradleBuild
|
||||||
.script("src/main/gradle/running/boot-run-source-resources")
|
.script("src/main/gradle/running/boot-run-source-resources")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -22,11 +22,12 @@ import java.io.IOException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.gradle.testkit.runner.TaskOutcome;
|
import org.gradle.testkit.runner.TaskOutcome;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
|
||||||
import org.springframework.boot.gradle.tasks.buildinfo.BuildInfo;
|
import org.springframework.boot.gradle.tasks.buildinfo.BuildInfo;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
import org.springframework.boot.gradle.testkit.GradleBuildExtension;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@ -36,10 +37,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
|
@ExtendWith(GradleBuildExtension.class)
|
||||||
public class BuildInfoDslIntegrationTests {
|
public class BuildInfoDslIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
final GradleBuild gradleBuild = new GradleBuild();
|
||||||
public final GradleBuild gradleBuild = new GradleBuild();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void basicJar() throws IOException {
|
public void basicJar() throws IOException {
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2019 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
|
||||||
|
*
|
||||||
|
* https://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 org.springframework.boot.gradle.junit;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||||
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
|
|
||||||
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link BeforeEachCallback} to set a test class's {@code gradleBuild} field prior to
|
||||||
|
* test exection.
|
||||||
|
*
|
||||||
|
* @author Andy Wilkinson
|
||||||
|
*/
|
||||||
|
final class GradleBuildFieldSetter implements BeforeEachCallback {
|
||||||
|
|
||||||
|
private final GradleBuild gradleBuild;
|
||||||
|
|
||||||
|
GradleBuildFieldSetter(GradleBuild gradleBuild) {
|
||||||
|
this.gradleBuild = gradleBuild;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeEach(ExtensionContext context) throws Exception {
|
||||||
|
Field field = ReflectionUtils.findField(context.getRequiredTestClass(),
|
||||||
|
"gradleBuild");
|
||||||
|
field.setAccessible(true);
|
||||||
|
field.set(context.getRequiredTestInstance(), this.gradleBuild);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,82 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2019 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
|
||||||
|
*
|
||||||
|
* https://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 org.springframework.boot.gradle.junit;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.extension.Extension;
|
||||||
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
|
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
|
||||||
|
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
|
||||||
|
|
||||||
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
import org.springframework.boot.gradle.testkit.GradleBuildExtension;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Extension} that runs {@link TestTemplate templated tests} against multiple
|
||||||
|
* versions of Gradle. Test classes using the extension must have non-privaten and
|
||||||
|
* non-final {@link GradleBuild} field named {@code gradleBuild}.
|
||||||
|
*
|
||||||
|
* @author Andy Wilkinson
|
||||||
|
*/
|
||||||
|
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");
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(
|
||||||
|
ExtensionContext context) {
|
||||||
|
return GRADLE_VERSIONS.stream()
|
||||||
|
.map(GradleVersionTestTemplateInvocationContext::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsTestTemplate(ExtensionContext context) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class GradleVersionTestTemplateInvocationContext
|
||||||
|
implements TestTemplateInvocationContext {
|
||||||
|
|
||||||
|
private final String gradleVersion;
|
||||||
|
|
||||||
|
GradleVersionTestTemplateInvocationContext(String gradleVersion) {
|
||||||
|
this.gradleVersion = gradleVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDisplayName(int invocationIndex) {
|
||||||
|
return "Gradle " + this.gradleVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Extension> getAdditionalExtensions() {
|
||||||
|
GradleBuild gradleBuild = new GradleBuild();
|
||||||
|
if (!this.gradleVersion.equals("default")) {
|
||||||
|
gradleBuild.gradleVersion(this.gradleVersion);
|
||||||
|
}
|
||||||
|
return Arrays.asList(new GradleBuildFieldSetter(gradleBuild),
|
||||||
|
new GradleBuildExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,94 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012-2019 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
|
|
||||||
*
|
|
||||||
* https://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 org.springframework.boot.gradle.junit;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.gradle.api.Rule;
|
|
||||||
import org.junit.runner.Runner;
|
|
||||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
|
||||||
import org.junit.runners.Suite;
|
|
||||||
import org.junit.runners.model.FrameworkMethod;
|
|
||||||
import org.junit.runners.model.InitializationError;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom {@link Suite} that runs tests against multiple versions of Gradle. Test classes
|
|
||||||
* using the suite must have a public {@link GradleBuild} field named {@code gradleBuild}
|
|
||||||
* and annotated with {@link Rule}.
|
|
||||||
*
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
*/
|
|
||||||
public final class GradleCompatibilitySuite extends Suite {
|
|
||||||
|
|
||||||
private static final List<String> GRADLE_VERSIONS = Arrays.asList("default", "5.0",
|
|
||||||
"5.1.1", "5.2.1", "5.3.1", "5.4.1");
|
|
||||||
|
|
||||||
public GradleCompatibilitySuite(Class<?> clazz) throws InitializationError {
|
|
||||||
super(clazz, createRunners(clazz));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<Runner> createRunners(Class<?> clazz) throws InitializationError {
|
|
||||||
List<Runner> runners = new ArrayList<>();
|
|
||||||
for (String version : GRADLE_VERSIONS) {
|
|
||||||
runners.add(new GradleCompatibilityClassRunner(clazz, version));
|
|
||||||
}
|
|
||||||
return runners;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class GradleCompatibilityClassRunner
|
|
||||||
extends BlockJUnit4ClassRunner {
|
|
||||||
|
|
||||||
private final String gradleVersion;
|
|
||||||
|
|
||||||
private GradleCompatibilityClassRunner(Class<?> klass, String gradleVersion)
|
|
||||||
throws InitializationError {
|
|
||||||
super(klass);
|
|
||||||
this.gradleVersion = gradleVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Object createTest() throws Exception {
|
|
||||||
Object test = super.createTest();
|
|
||||||
configureTest(test);
|
|
||||||
return test;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void configureTest(Object test) throws Exception {
|
|
||||||
GradleBuild gradleBuild = new GradleBuild();
|
|
||||||
if (!"default".equals(this.gradleVersion)) {
|
|
||||||
gradleBuild = gradleBuild.gradleVersion(this.gradleVersion);
|
|
||||||
}
|
|
||||||
test.getClass().getField("gradleBuild").set(test, gradleBuild);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getName() {
|
|
||||||
return "Gradle " + this.gradleVersion;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String testName(FrameworkMethod method) {
|
|
||||||
return method.getName() + " [" + getName() + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2019 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
|
||||||
|
*
|
||||||
|
* https://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 org.springframework.boot.gradle.junit;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.extension.Extension;
|
||||||
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
|
import org.junit.jupiter.api.extension.TestTemplateInvocationContext;
|
||||||
|
import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider;
|
||||||
|
|
||||||
|
import org.springframework.boot.gradle.testkit.Dsl;
|
||||||
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
import org.springframework.boot.gradle.testkit.GradleBuildExtension;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link Extension} that runs {@link TestTemplate templated tests} against the Groovy and
|
||||||
|
* Kotlin DSLs. Test classes using the extension most have a non-private non-final
|
||||||
|
* {@link GradleBuild} field named {@code gradleBuild}.
|
||||||
|
*
|
||||||
|
* @author Andy Wilkinson
|
||||||
|
*/
|
||||||
|
public class GradleMultiDslExtension implements TestTemplateInvocationContextProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(
|
||||||
|
ExtensionContext context) {
|
||||||
|
return Stream.of(Dsl.values()).map(DslTestTemplateInvocationContext::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean supportsTestTemplate(ExtensionContext context) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final class DslTestTemplateInvocationContext
|
||||||
|
implements TestTemplateInvocationContext {
|
||||||
|
|
||||||
|
private final Dsl dsl;
|
||||||
|
|
||||||
|
DslTestTemplateInvocationContext(Dsl dsl) {
|
||||||
|
this.dsl = dsl;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Extension> getAdditionalExtensions() {
|
||||||
|
return Arrays.asList(new GradleBuildFieldSetter(new GradleBuild(this.dsl)),
|
||||||
|
new GradleBuildExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDisplayName(int invocationIndex) {
|
||||||
|
return this.dsl.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,86 +0,0 @@
|
||||||
/*
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
* https://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 org.springframework.boot.gradle.junit;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.gradle.api.Rule;
|
|
||||||
import org.junit.runner.Runner;
|
|
||||||
import org.junit.runners.BlockJUnit4ClassRunner;
|
|
||||||
import org.junit.runners.Suite;
|
|
||||||
import org.junit.runners.model.FrameworkMethod;
|
|
||||||
import org.junit.runners.model.InitializationError;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.testkit.Dsl;
|
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Custom {@link Suite} that runs tests against the Groovy and the Kotlin DSLs. Test
|
|
||||||
* classes using the suite must have a public {@link GradleBuild} field named
|
|
||||||
* {@code gradleBuild} and annotated with {@link Rule}.
|
|
||||||
*
|
|
||||||
* @author Jean-Baptiste Nizet
|
|
||||||
* @author Andy Wilkinson
|
|
||||||
*/
|
|
||||||
public final class GradleMultiDslSuite extends Suite {
|
|
||||||
|
|
||||||
public GradleMultiDslSuite(Class<?> clazz) throws InitializationError {
|
|
||||||
super(clazz, createRunners(clazz));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<Runner> createRunners(Class<?> clazz) throws InitializationError {
|
|
||||||
List<Runner> runners = new ArrayList<>();
|
|
||||||
runners.add(new GradleDslClassRunner(clazz, new GradleBuild(Dsl.GROOVY)));
|
|
||||||
runners.add(new GradleDslClassRunner(clazz, new GradleBuild(Dsl.KOTLIN)));
|
|
||||||
return runners;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class GradleDslClassRunner extends BlockJUnit4ClassRunner {
|
|
||||||
|
|
||||||
private final GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
private GradleDslClassRunner(Class<?> klass, GradleBuild gradleBuild)
|
|
||||||
throws InitializationError {
|
|
||||||
super(klass);
|
|
||||||
this.gradleBuild = gradleBuild;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Object createTest() throws Exception {
|
|
||||||
Object test = super.createTest();
|
|
||||||
configureTest(test);
|
|
||||||
return test;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void configureTest(Object test) throws Exception {
|
|
||||||
test.getClass().getField("gradleBuild").set(test, this.gradleBuild);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getName() {
|
|
||||||
return this.gradleBuild.getDsl().getName() + " DSL";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String testName(FrameworkMethod method) {
|
|
||||||
return method.getName() + " [" + getName() + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -29,11 +29,10 @@ import java.util.zip.ZipFile;
|
||||||
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
|
||||||
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
|
||||||
import org.gradle.testkit.runner.TaskOutcome;
|
import org.gradle.testkit.runner.TaskOutcome;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleCompatibilitySuite;
|
import org.springframework.boot.gradle.junit.GradleCompatibilityExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -43,38 +42,37 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleCompatibilitySuite.class)
|
@ExtendWith(GradleCompatibilityExtension.class)
|
||||||
public class ApplicationPluginActionIntegrationTests {
|
public class ApplicationPluginActionIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void noBootDistributionWithoutApplicationPluginApplied() {
|
public void noBootDistributionWithoutApplicationPluginApplied() {
|
||||||
assertThat(this.gradleBuild.build("distributionExists", "-PdistributionName=boot")
|
assertThat(this.gradleBuild.build("distributionExists", "-PdistributionName=boot")
|
||||||
.getOutput()).contains("boot exists = false");
|
.getOutput()).contains("boot exists = false");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void applyingApplicationPluginCreatesBootDistribution() {
|
public void applyingApplicationPluginCreatesBootDistribution() {
|
||||||
assertThat(this.gradleBuild.build("distributionExists", "-PdistributionName=boot",
|
assertThat(this.gradleBuild.build("distributionExists", "-PdistributionName=boot",
|
||||||
"-PapplyApplicationPlugin").getOutput()).contains("boot exists = true");
|
"-PapplyApplicationPlugin").getOutput()).contains("boot exists = true");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void noBootStartScriptsTaskWithoutApplicationPluginApplied() {
|
public void noBootStartScriptsTaskWithoutApplicationPluginApplied() {
|
||||||
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootStartScripts")
|
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootStartScripts")
|
||||||
.getOutput()).contains("bootStartScripts exists = false");
|
.getOutput()).contains("bootStartScripts exists = false");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void applyingApplicationPluginCreatesBootStartScriptsTask() {
|
public void applyingApplicationPluginCreatesBootStartScriptsTask() {
|
||||||
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootStartScripts",
|
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootStartScripts",
|
||||||
"-PapplyApplicationPlugin").getOutput())
|
"-PapplyApplicationPlugin").getOutput())
|
||||||
.contains("bootStartScripts exists = true");
|
.contains("bootStartScripts exists = true");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void createsBootStartScriptsTaskUsesApplicationPluginsDefaultJvmOpts() {
|
public void createsBootStartScriptsTaskUsesApplicationPluginsDefaultJvmOpts() {
|
||||||
assertThat(this.gradleBuild
|
assertThat(this.gradleBuild
|
||||||
.build("startScriptsDefaultJvmOpts", "-PapplyApplicationPlugin")
|
.build("startScriptsDefaultJvmOpts", "-PapplyApplicationPlugin")
|
||||||
|
@ -82,7 +80,7 @@ public class ApplicationPluginActionIntegrationTests {
|
||||||
"bootStartScripts defaultJvmOpts = [-Dcom.example.a=alpha, -Dcom.example.b=bravo]");
|
"bootStartScripts defaultJvmOpts = [-Dcom.example.a=alpha, -Dcom.example.b=bravo]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void zipDistributionForJarCanBeBuilt() throws IOException {
|
public void zipDistributionForJarCanBeBuilt() throws IOException {
|
||||||
assertThat(
|
assertThat(
|
||||||
this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
|
this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
|
||||||
|
@ -97,7 +95,7 @@ public class ApplicationPluginActionIntegrationTests {
|
||||||
name + "-boot/bin/" + name + ".bat");
|
name + "-boot/bin/" + name + ".bat");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void tarDistributionForJarCanBeBuilt() throws IOException {
|
public void tarDistributionForJarCanBeBuilt() throws IOException {
|
||||||
assertThat(
|
assertThat(
|
||||||
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
||||||
|
@ -112,7 +110,7 @@ public class ApplicationPluginActionIntegrationTests {
|
||||||
name + "-boot/bin/" + name + ".bat");
|
name + "-boot/bin/" + name + ".bat");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void zipDistributionForWarCanBeBuilt() throws IOException {
|
public void zipDistributionForWarCanBeBuilt() throws IOException {
|
||||||
assertThat(
|
assertThat(
|
||||||
this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
|
this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
|
||||||
|
@ -127,7 +125,7 @@ public class ApplicationPluginActionIntegrationTests {
|
||||||
name + "-boot/bin/" + name + ".bat");
|
name + "-boot/bin/" + name + ".bat");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void tarDistributionForWarCanBeBuilt() throws IOException {
|
public void tarDistributionForWarCanBeBuilt() throws IOException {
|
||||||
assertThat(
|
assertThat(
|
||||||
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
||||||
|
@ -142,7 +140,7 @@ public class ApplicationPluginActionIntegrationTests {
|
||||||
name + "-boot/bin/" + name + ".bat");
|
name + "-boot/bin/" + name + ".bat");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void applicationNameCanBeUsedToCustomizeDistributionName() throws IOException {
|
public void applicationNameCanBeUsedToCustomizeDistributionName() throws IOException {
|
||||||
assertThat(
|
assertThat(
|
||||||
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
||||||
|
@ -157,7 +155,7 @@ public class ApplicationPluginActionIntegrationTests {
|
||||||
"custom-boot/bin/custom.bat");
|
"custom-boot/bin/custom.bat");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void scriptsHaveCorrectPermissions() throws IOException {
|
public void scriptsHaveCorrectPermissions() throws IOException {
|
||||||
assertThat(
|
assertThat(
|
||||||
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -21,11 +21,10 @@ import java.io.IOException;
|
||||||
|
|
||||||
import org.gradle.testkit.runner.BuildResult;
|
import org.gradle.testkit.runner.BuildResult;
|
||||||
import org.gradle.testkit.runner.TaskOutcome;
|
import org.gradle.testkit.runner.TaskOutcome;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleCompatibilitySuite;
|
import org.springframework.boot.gradle.junit.GradleCompatibilityExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
import org.springframework.util.FileSystemUtils;
|
import org.springframework.util.FileSystemUtils;
|
||||||
|
|
||||||
|
@ -37,20 +36,19 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleCompatibilitySuite.class)
|
@ExtendWith(GradleCompatibilityExtension.class)
|
||||||
public class DependencyManagementPluginActionIntegrationTests {
|
public class DependencyManagementPluginActionIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void noDependencyManagementIsAppliedByDefault() {
|
public void noDependencyManagementIsAppliedByDefault() {
|
||||||
assertThat(this.gradleBuild.build("doesNotHaveDependencyManagement")
|
assertThat(this.gradleBuild.build("doesNotHaveDependencyManagement")
|
||||||
.task(":doesNotHaveDependencyManagement").getOutcome())
|
.task(":doesNotHaveDependencyManagement").getOutcome())
|
||||||
.isEqualTo(TaskOutcome.SUCCESS);
|
.isEqualTo(TaskOutcome.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bomIsImportedWhenDependencyManagementPluginIsApplied() {
|
public void bomIsImportedWhenDependencyManagementPluginIsApplied() {
|
||||||
assertThat(this.gradleBuild
|
assertThat(this.gradleBuild
|
||||||
.build("hasDependencyManagement", "-PapplyDependencyManagementPlugin")
|
.build("hasDependencyManagement", "-PapplyDependencyManagementPlugin")
|
||||||
|
@ -58,7 +56,7 @@ public class DependencyManagementPluginActionIntegrationTests {
|
||||||
.isEqualTo(TaskOutcome.SUCCESS);
|
.isEqualTo(TaskOutcome.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void helpfulErrorWhenVersionlessDependencyFailsToResolve() throws IOException {
|
public void helpfulErrorWhenVersionlessDependencyFailsToResolve() throws IOException {
|
||||||
File examplePackage = new File(this.gradleBuild.getProjectDir(),
|
File examplePackage = new File(this.gradleBuild.getProjectDir(),
|
||||||
"src/main/java/com/example");
|
"src/main/java/com/example");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -23,11 +23,10 @@ import java.util.jar.JarOutputStream;
|
||||||
|
|
||||||
import org.gradle.testkit.runner.BuildResult;
|
import org.gradle.testkit.runner.BuildResult;
|
||||||
import org.gradle.testkit.runner.TaskOutcome;
|
import org.gradle.testkit.runner.TaskOutcome;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleCompatibilitySuite;
|
import org.springframework.boot.gradle.junit.GradleCompatibilityExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -37,74 +36,73 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleCompatibilitySuite.class)
|
@ExtendWith(GradleCompatibilityExtension.class)
|
||||||
public class JavaPluginActionIntegrationTests {
|
public class JavaPluginActionIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void noBootJarTaskWithoutJavaPluginApplied() {
|
public void noBootJarTaskWithoutJavaPluginApplied() {
|
||||||
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootJar").getOutput())
|
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootJar").getOutput())
|
||||||
.contains("bootJar exists = false");
|
.contains("bootJar exists = false");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void applyingJavaPluginCreatesBootJarTask() {
|
public void applyingJavaPluginCreatesBootJarTask() {
|
||||||
assertThat(this.gradleBuild
|
assertThat(this.gradleBuild
|
||||||
.build("taskExists", "-PtaskName=bootJar", "-PapplyJavaPlugin")
|
.build("taskExists", "-PtaskName=bootJar", "-PapplyJavaPlugin")
|
||||||
.getOutput()).contains("bootJar exists = true");
|
.getOutput()).contains("bootJar exists = true");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void noBootRunTaskWithoutJavaPluginApplied() {
|
public void noBootRunTaskWithoutJavaPluginApplied() {
|
||||||
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootRun").getOutput())
|
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootRun").getOutput())
|
||||||
.contains("bootRun exists = false");
|
.contains("bootRun exists = false");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void applyingJavaPluginCreatesBootRunTask() {
|
public void applyingJavaPluginCreatesBootRunTask() {
|
||||||
assertThat(this.gradleBuild
|
assertThat(this.gradleBuild
|
||||||
.build("taskExists", "-PtaskName=bootRun", "-PapplyJavaPlugin")
|
.build("taskExists", "-PtaskName=bootRun", "-PapplyJavaPlugin")
|
||||||
.getOutput()).contains("bootRun exists = true");
|
.getOutput()).contains("bootRun exists = true");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void javaCompileTasksUseUtf8Encoding() {
|
public void javaCompileTasksUseUtf8Encoding() {
|
||||||
assertThat(this.gradleBuild.build("javaCompileEncoding", "-PapplyJavaPlugin")
|
assertThat(this.gradleBuild.build("javaCompileEncoding", "-PapplyJavaPlugin")
|
||||||
.getOutput()).contains("compileJava = UTF-8")
|
.getOutput()).contains("compileJava = UTF-8")
|
||||||
.contains("compileTestJava = UTF-8");
|
.contains("compileTestJava = UTF-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void javaCompileTasksUseParametersCompilerFlagByDefault() {
|
public void javaCompileTasksUseParametersCompilerFlagByDefault() {
|
||||||
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
|
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
|
||||||
.contains("compileJava compiler args: [-parameters]")
|
.contains("compileJava compiler args: [-parameters]")
|
||||||
.contains("compileTestJava compiler args: [-parameters]");
|
.contains("compileTestJava compiler args: [-parameters]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void javaCompileTasksUseParametersAndAdditionalCompilerFlags() {
|
public void javaCompileTasksUseParametersAndAdditionalCompilerFlags() {
|
||||||
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
|
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
|
||||||
.contains("compileJava compiler args: [-parameters, -Xlint:all]")
|
.contains("compileJava compiler args: [-parameters, -Xlint:all]")
|
||||||
.contains("compileTestJava compiler args: [-parameters, -Xlint:all]");
|
.contains("compileTestJava compiler args: [-parameters, -Xlint:all]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void javaCompileTasksCanOverrideDefaultParametersCompilerFlag() {
|
public void javaCompileTasksCanOverrideDefaultParametersCompilerFlag() {
|
||||||
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
|
assertThat(this.gradleBuild.build("javaCompileTasksCompilerArgs").getOutput())
|
||||||
.contains("compileJava compiler args: [-Xlint:all]")
|
.contains("compileJava compiler args: [-Xlint:all]")
|
||||||
.contains("compileTestJava compiler args: [-Xlint:all]");
|
.contains("compileTestJava compiler args: [-Xlint:all]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void assembleRunsBootJarAndJarIsSkipped() {
|
public void assembleRunsBootJarAndJarIsSkipped() {
|
||||||
BuildResult result = this.gradleBuild.build("assemble");
|
BuildResult result = this.gradleBuild.build("assemble");
|
||||||
assertThat(result.task(":bootJar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
assertThat(result.task(":bootJar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
assertThat(result.task(":jar").getOutcome()).isEqualTo(TaskOutcome.SKIPPED);
|
assertThat(result.task(":jar").getOutcome()).isEqualTo(TaskOutcome.SKIPPED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void errorMessageIsHelpfulWhenMainClassCannotBeResolved() {
|
public void errorMessageIsHelpfulWhenMainClassCannotBeResolved() {
|
||||||
BuildResult result = this.gradleBuild.buildAndFail("build", "-PapplyJavaPlugin");
|
BuildResult result = this.gradleBuild.buildAndFail("build", "-PapplyJavaPlugin");
|
||||||
assertThat(result.task(":bootJar").getOutcome()).isEqualTo(TaskOutcome.FAILED);
|
assertThat(result.task(":bootJar").getOutcome()).isEqualTo(TaskOutcome.FAILED);
|
||||||
|
@ -112,7 +110,7 @@ public class JavaPluginActionIntegrationTests {
|
||||||
"Main class name has not been configured and it could not be resolved");
|
"Main class name has not been configured and it could not be resolved");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void jarAndBootJarCanBothBeBuilt() {
|
public void jarAndBootJarCanBothBeBuilt() {
|
||||||
BuildResult result = this.gradleBuild.build("assemble");
|
BuildResult result = this.gradleBuild.build("assemble");
|
||||||
assertThat(result.task(":bootJar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
assertThat(result.task(":bootJar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
@ -124,7 +122,7 @@ public class JavaPluginActionIntegrationTests {
|
||||||
this.gradleBuild.getProjectDir().getName() + "-boot.jar"));
|
this.gradleBuild.getProjectDir().getName() + "-boot.jar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void additionalMetadataLocationsConfiguredWhenProcessorIsPresent()
|
public void additionalMetadataLocationsConfiguredWhenProcessorIsPresent()
|
||||||
throws IOException {
|
throws IOException {
|
||||||
createMinimalMainSource();
|
createMinimalMainSource();
|
||||||
|
@ -142,7 +140,7 @@ public class JavaPluginActionIntegrationTests {
|
||||||
.getCanonicalPath());
|
.getCanonicalPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void additionalMetadataLocationsNotConfiguredWhenProcessorIsAbsent()
|
public void additionalMetadataLocationsNotConfiguredWhenProcessorIsAbsent()
|
||||||
throws IOException {
|
throws IOException {
|
||||||
createMinimalMainSource();
|
createMinimalMainSource();
|
||||||
|
|
|
@ -16,11 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.boot.gradle.plugin;
|
package org.springframework.boot.gradle.plugin;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleCompatibilitySuite;
|
import org.springframework.boot.gradle.junit.GradleCompatibilityExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -30,33 +29,32 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleCompatibilitySuite.class)
|
@ExtendWith(GradleCompatibilityExtension.class)
|
||||||
public class KotlinPluginActionIntegrationTests {
|
public class KotlinPluginActionIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void noKotlinVersionPropertyWithoutKotlinPlugin() {
|
public void noKotlinVersionPropertyWithoutKotlinPlugin() {
|
||||||
assertThat(this.gradleBuild.build("kotlinVersion").getOutput())
|
assertThat(this.gradleBuild.build("kotlinVersion").getOutput())
|
||||||
.contains("Kotlin version: none");
|
.contains("Kotlin version: none");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void kotlinVersionPropertyIsSet() {
|
public void kotlinVersionPropertyIsSet() {
|
||||||
String output = this.gradleBuild.build("kotlinVersion", "dependencies",
|
String output = this.gradleBuild.build("kotlinVersion", "dependencies",
|
||||||
"--configuration", "compileClasspath").getOutput();
|
"--configuration", "compileClasspath").getOutput();
|
||||||
assertThat(output).containsPattern("Kotlin version: [0-9]\\.[0-9]\\.[0-9]+");
|
assertThat(output).containsPattern("Kotlin version: [0-9]\\.[0-9]\\.[0-9]+");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void kotlinCompileTasksUseJavaParametersFlagByDefault() {
|
public void kotlinCompileTasksUseJavaParametersFlagByDefault() {
|
||||||
assertThat(this.gradleBuild.build("kotlinCompileTasksJavaParameters").getOutput())
|
assertThat(this.gradleBuild.build("kotlinCompileTasksJavaParameters").getOutput())
|
||||||
.contains("compileKotlin java parameters: true")
|
.contains("compileKotlin java parameters: true")
|
||||||
.contains("compileTestKotlin java parameters: true");
|
.contains("compileTestKotlin java parameters: true");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void kotlinCompileTasksCanOverrideDefaultJavaParametersFlag() {
|
public void kotlinCompileTasksCanOverrideDefaultJavaParametersFlag() {
|
||||||
assertThat(this.gradleBuild.build("kotlinCompileTasksJavaParameters").getOutput())
|
assertThat(this.gradleBuild.build("kotlinCompileTasksJavaParameters").getOutput())
|
||||||
.contains("compileKotlin java parameters: false")
|
.contains("compileKotlin java parameters: false")
|
||||||
|
|
|
@ -16,15 +16,15 @@
|
||||||
|
|
||||||
package org.springframework.boot.gradle.plugin;
|
package org.springframework.boot.gradle.plugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.plugins.ExtraPropertiesExtension;
|
import org.gradle.api.plugins.ExtraPropertiesExtension;
|
||||||
import org.gradle.internal.impldep.org.junit.Before;
|
|
||||||
import org.gradle.internal.impldep.org.junit.Rule;
|
|
||||||
import org.gradle.internal.impldep.org.junit.Test;
|
|
||||||
import org.gradle.internal.impldep.org.junit.rules.TemporaryFolder;
|
|
||||||
import org.gradle.testfixtures.ProjectBuilder;
|
import org.gradle.testfixtures.ProjectBuilder;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
|
||||||
import org.springframework.boot.gradle.dsl.SpringBootExtension;
|
import org.springframework.boot.gradle.dsl.SpringBootExtension;
|
||||||
|
|
||||||
|
@ -32,17 +32,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
public class MainClassConventionTests {
|
public class MainClassConventionTests {
|
||||||
|
|
||||||
@Rule
|
@TempDir
|
||||||
public final TemporaryFolder temp = new TemporaryFolder();
|
File temp;
|
||||||
|
|
||||||
private Project project;
|
private Project project;
|
||||||
|
|
||||||
private MainClassConvention convention;
|
private MainClassConvention convention;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void createConvention() throws IOException {
|
public void createConvention() throws IOException {
|
||||||
this.project = ProjectBuilder.builder().withProjectDir(this.temp.newFolder())
|
this.project = ProjectBuilder.builder().withProjectDir(this.temp).build();
|
||||||
.build();
|
|
||||||
this.convention = new MainClassConvention(this.project, () -> null);
|
this.convention = new MainClassConvention(this.project, () -> null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -16,11 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.boot.gradle.plugin;
|
package org.springframework.boot.gradle.plugin;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleCompatibilitySuite;
|
import org.springframework.boot.gradle.junit.GradleCompatibilityExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -30,13 +29,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleCompatibilitySuite.class)
|
@ExtendWith(GradleCompatibilityExtension.class)
|
||||||
public class MavenPluginActionIntegrationTests {
|
public class MavenPluginActionIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void clearsConf2ScopeMappingsOfUploadBootArchivesTask() {
|
public void clearsConf2ScopeMappingsOfUploadBootArchivesTask() {
|
||||||
assertThat(this.gradleBuild.build("conf2ScopeMappings").getOutput())
|
assertThat(this.gradleBuild.build("conf2ScopeMappings").getOutput())
|
||||||
.contains("Conf2ScopeMappings = 0");
|
.contains("Conf2ScopeMappings = 0");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -16,11 +16,10 @@
|
||||||
|
|
||||||
package org.springframework.boot.gradle.plugin;
|
package org.springframework.boot.gradle.plugin;
|
||||||
|
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleCompatibilitySuite;
|
import org.springframework.boot.gradle.junit.GradleCompatibilityExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -31,13 +30,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleCompatibilitySuite.class)
|
@ExtendWith(GradleCompatibilityExtension.class)
|
||||||
public class OnlyDependencyManagementIntegrationTests {
|
public class OnlyDependencyManagementIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void dependencyManagementCanBeConfiguredUsingCoordinatesConstant() {
|
public void dependencyManagementCanBeConfiguredUsingCoordinatesConstant() {
|
||||||
assertThat(this.gradleBuild.build("dependencyManagement").getOutput())
|
assertThat(this.gradleBuild.build("dependencyManagement").getOutput())
|
||||||
.contains("org.springframework.boot:spring-boot-starter ");
|
.contains("org.springframework.boot:spring-boot-starter ");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -20,10 +20,11 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.gradle.testkit.runner.BuildResult;
|
import org.gradle.testkit.runner.BuildResult;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
import org.springframework.boot.gradle.testkit.GradleBuildExtension;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@ -32,26 +33,26 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
|
@ExtendWith(GradleBuildExtension.class)
|
||||||
public class SpringBootPluginIntegrationTests {
|
public class SpringBootPluginIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
final GradleBuild gradleBuild = new GradleBuild();
|
||||||
public final GradleBuild gradleBuild = new GradleBuild();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void failFastWithVersionOfGradleLowerThanRequired() {
|
public void failFastWithVersionOfGradleLowerThanRequired() {
|
||||||
BuildResult result = this.gradleBuild.gradleVersion("4.3").buildAndFail();
|
BuildResult result = this.gradleBuild.gradleVersion("4.9").buildAndFail();
|
||||||
assertThat(result.getOutput()).contains("Spring Boot plugin requires Gradle 4.4"
|
assertThat(result.getOutput()).contains("Spring Boot plugin requires Gradle 4.10"
|
||||||
+ " or later. The current version is Gradle 4.3");
|
+ " or later. The current version is Gradle 4.9");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void succeedWithVersionOfGradleHigherThanRequired() {
|
public void succeedWithVersionOfGradleHigherThanRequired() {
|
||||||
this.gradleBuild.gradleVersion("4.4.1").build();
|
this.gradleBuild.gradleVersion("4.10.1").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void succeedWithVersionOfGradleMatchingWhatIsRequired() {
|
public void succeedWithVersionOfGradleMatchingWhatIsRequired() {
|
||||||
this.gradleBuild.gradleVersion("4.4").build();
|
this.gradleBuild.gradleVersion("4.10").build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -20,11 +20,10 @@ import java.io.File;
|
||||||
|
|
||||||
import org.gradle.testkit.runner.BuildResult;
|
import org.gradle.testkit.runner.BuildResult;
|
||||||
import org.gradle.testkit.runner.TaskOutcome;
|
import org.gradle.testkit.runner.TaskOutcome;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleCompatibilitySuite;
|
import org.springframework.boot.gradle.junit.GradleCompatibilityExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -34,33 +33,32 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleCompatibilitySuite.class)
|
@ExtendWith(GradleCompatibilityExtension.class)
|
||||||
public class WarPluginActionIntegrationTests {
|
public class WarPluginActionIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void noBootWarTaskWithoutWarPluginApplied() {
|
public void noBootWarTaskWithoutWarPluginApplied() {
|
||||||
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootWar").getOutput())
|
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootWar").getOutput())
|
||||||
.contains("bootWar exists = false");
|
.contains("bootWar exists = false");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void applyingWarPluginCreatesBootWarTask() {
|
public void applyingWarPluginCreatesBootWarTask() {
|
||||||
assertThat(this.gradleBuild
|
assertThat(this.gradleBuild
|
||||||
.build("taskExists", "-PtaskName=bootWar", "-PapplyWarPlugin")
|
.build("taskExists", "-PtaskName=bootWar", "-PapplyWarPlugin")
|
||||||
.getOutput()).contains("bootWar exists = true");
|
.getOutput()).contains("bootWar exists = true");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void assembleRunsBootWarAndWarIsSkipped() {
|
public void assembleRunsBootWarAndWarIsSkipped() {
|
||||||
BuildResult result = this.gradleBuild.build("assemble");
|
BuildResult result = this.gradleBuild.build("assemble");
|
||||||
assertThat(result.task(":bootWar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
assertThat(result.task(":bootWar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
assertThat(result.task(":war").getOutcome()).isEqualTo(TaskOutcome.SKIPPED);
|
assertThat(result.task(":war").getOutcome()).isEqualTo(TaskOutcome.SKIPPED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void warAndBootWarCanBothBeBuilt() {
|
public void warAndBootWarCanBothBeBuilt() {
|
||||||
BuildResult result = this.gradleBuild.build("assemble");
|
BuildResult result = this.gradleBuild.build("assemble");
|
||||||
assertThat(result.task(":bootWar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
assertThat(result.task(":bootWar").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
@ -72,7 +70,7 @@ public class WarPluginActionIntegrationTests {
|
||||||
this.gradleBuild.getProjectDir().getName() + "-boot.war"));
|
this.gradleBuild.getProjectDir().getName() + "-boot.war"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void errorMessageIsHelpfulWhenMainClassCannotBeResolved() {
|
public void errorMessageIsHelpfulWhenMainClassCannotBeResolved() {
|
||||||
BuildResult result = this.gradleBuild.buildAndFail("build", "-PapplyWarPlugin");
|
BuildResult result = this.gradleBuild.buildAndFail("build", "-PapplyWarPlugin");
|
||||||
assertThat(result.task(":bootWar").getOutcome()).isEqualTo(TaskOutcome.FAILED);
|
assertThat(result.task(":bootWar").getOutcome()).isEqualTo(TaskOutcome.FAILED);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -23,11 +23,10 @@ import java.util.Properties;
|
||||||
|
|
||||||
import org.gradle.testkit.runner.BuildResult;
|
import org.gradle.testkit.runner.BuildResult;
|
||||||
import org.gradle.testkit.runner.TaskOutcome;
|
import org.gradle.testkit.runner.TaskOutcome;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleCompatibilitySuite;
|
import org.springframework.boot.gradle.junit.GradleCompatibilityExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -37,13 +36,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleCompatibilitySuite.class)
|
@ExtendWith(GradleCompatibilityExtension.class)
|
||||||
public class BuildInfoIntegrationTests {
|
public class BuildInfoIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void defaultValues() {
|
public void defaultValues() {
|
||||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
|
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
|
||||||
.isEqualTo(TaskOutcome.SUCCESS);
|
.isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
@ -56,7 +54,7 @@ public class BuildInfoIntegrationTests {
|
||||||
assertThat(buildInfoProperties).containsEntry("build.version", "unspecified");
|
assertThat(buildInfoProperties).containsEntry("build.version", "unspecified");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void basicExecution() {
|
public void basicExecution() {
|
||||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
|
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
|
||||||
.isEqualTo(TaskOutcome.SUCCESS);
|
.isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
@ -69,7 +67,7 @@ public class BuildInfoIntegrationTests {
|
||||||
assertThat(buildInfoProperties).containsEntry("build.version", "1.0");
|
assertThat(buildInfoProperties).containsEntry("build.version", "1.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void notUpToDateWhenExecutedTwiceAsTimeChanges() {
|
public void notUpToDateWhenExecutedTwiceAsTimeChanges() {
|
||||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
|
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
|
||||||
.isEqualTo(TaskOutcome.SUCCESS);
|
.isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
@ -77,7 +75,7 @@ public class BuildInfoIntegrationTests {
|
||||||
.isEqualTo(TaskOutcome.SUCCESS);
|
.isEqualTo(TaskOutcome.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void upToDateWhenExecutedTwiceWithFixedTime() {
|
public void upToDateWhenExecutedTwiceWithFixedTime() {
|
||||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
|
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
|
||||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
@ -85,7 +83,7 @@ public class BuildInfoIntegrationTests {
|
||||||
.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
|
.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void notUpToDateWhenExecutedTwiceWithFixedTimeAndChangedProjectVersion() {
|
public void notUpToDateWhenExecutedTwiceWithFixedTimeAndChangedProjectVersion() {
|
||||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
|
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
|
||||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -25,9 +25,8 @@ import java.util.Properties;
|
||||||
|
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.testfixtures.ProjectBuilder;
|
import org.gradle.testfixtures.ProjectBuilder;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@ -38,8 +37,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class BuildInfoTests {
|
public class BuildInfoTests {
|
||||||
|
|
||||||
@Rule
|
@TempDir
|
||||||
public TemporaryFolder temp = new TemporaryFolder();
|
File temp;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void basicExecution() {
|
public void basicExecution() {
|
||||||
|
@ -126,14 +125,9 @@ public class BuildInfoTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Project createProject(String projectName) {
|
private Project createProject(String projectName) {
|
||||||
try {
|
File projectDir = new File(this.temp, projectName);
|
||||||
File projectDir = this.temp.newFolder(projectName);
|
return ProjectBuilder.builder().withProjectDir(projectDir).withName(projectName)
|
||||||
return ProjectBuilder.builder().withProjectDir(projectDir)
|
.build();
|
||||||
.withName(projectName).build();
|
|
||||||
}
|
|
||||||
catch (IOException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private BuildInfo createTask(Project project) {
|
private BuildInfo createTask(Project project) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -23,11 +23,10 @@ import java.util.jar.JarFile;
|
||||||
import org.gradle.testkit.runner.InvalidRunnerConfigurationException;
|
import org.gradle.testkit.runner.InvalidRunnerConfigurationException;
|
||||||
import org.gradle.testkit.runner.TaskOutcome;
|
import org.gradle.testkit.runner.TaskOutcome;
|
||||||
import org.gradle.testkit.runner.UnexpectedBuildFailure;
|
import org.gradle.testkit.runner.UnexpectedBuildFailure;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleCompatibilitySuite;
|
import org.springframework.boot.gradle.junit.GradleCompatibilityExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
import org.springframework.boot.loader.tools.FileUtils;
|
import org.springframework.boot.loader.tools.FileUtils;
|
||||||
|
|
||||||
|
@ -38,11 +37,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleCompatibilitySuite.class)
|
@ExtendWith(GradleCompatibilityExtension.class)
|
||||||
public abstract class AbstractBootArchiveIntegrationTests {
|
public abstract class AbstractBootArchiveIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
private final String taskName;
|
private final String taskName;
|
||||||
|
|
||||||
|
@ -50,14 +48,14 @@ public abstract class AbstractBootArchiveIntegrationTests {
|
||||||
this.taskName = taskName;
|
this.taskName = taskName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void basicBuild() throws InvalidRunnerConfigurationException,
|
public void basicBuild() throws InvalidRunnerConfigurationException,
|
||||||
UnexpectedBuildFailure, IOException {
|
UnexpectedBuildFailure, IOException {
|
||||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void reproducibleArchive() throws InvalidRunnerConfigurationException,
|
public void reproducibleArchive() throws InvalidRunnerConfigurationException,
|
||||||
UnexpectedBuildFailure, IOException, InterruptedException {
|
UnexpectedBuildFailure, IOException, InterruptedException {
|
||||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||||
|
@ -72,7 +70,7 @@ public abstract class AbstractBootArchiveIntegrationTests {
|
||||||
assertThat(firstHash).isEqualTo(secondHash);
|
assertThat(firstHash).isEqualTo(secondHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void upToDateWhenBuiltTwice() throws InvalidRunnerConfigurationException,
|
public void upToDateWhenBuiltTwice() throws InvalidRunnerConfigurationException,
|
||||||
UnexpectedBuildFailure, IOException {
|
UnexpectedBuildFailure, IOException {
|
||||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||||
|
@ -81,7 +79,7 @@ public abstract class AbstractBootArchiveIntegrationTests {
|
||||||
.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
|
.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void upToDateWhenBuiltTwiceWithLaunchScriptIncluded()
|
public void upToDateWhenBuiltTwiceWithLaunchScriptIncluded()
|
||||||
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure,
|
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure,
|
||||||
IOException {
|
IOException {
|
||||||
|
@ -92,7 +90,7 @@ public abstract class AbstractBootArchiveIntegrationTests {
|
||||||
.isEqualTo(TaskOutcome.UP_TO_DATE);
|
.isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void notUpToDateWhenLaunchScriptWasNotIncludedAndThenIsIncluded() {
|
public void notUpToDateWhenLaunchScriptWasNotIncludedAndThenIsIncluded() {
|
||||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
@ -100,7 +98,7 @@ public abstract class AbstractBootArchiveIntegrationTests {
|
||||||
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void notUpToDateWhenLaunchScriptWasIncludedAndThenIsNotIncluded() {
|
public void notUpToDateWhenLaunchScriptWasIncludedAndThenIsNotIncluded() {
|
||||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
@ -108,7 +106,7 @@ public abstract class AbstractBootArchiveIntegrationTests {
|
||||||
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void notUpToDateWhenLaunchScriptPropertyChanges() {
|
public void notUpToDateWhenLaunchScriptPropertyChanges() {
|
||||||
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true",
|
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true",
|
||||||
"-PlaunchScriptProperty=foo", this.taskName).task(":" + this.taskName)
|
"-PlaunchScriptProperty=foo", this.taskName).task(":" + this.taskName)
|
||||||
|
@ -118,7 +116,7 @@ public abstract class AbstractBootArchiveIntegrationTests {
|
||||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void applicationPluginMainClassNameIsUsed() throws IOException {
|
public void applicationPluginMainClassNameIsUsed() throws IOException {
|
||||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
@ -130,7 +128,7 @@ public abstract class AbstractBootArchiveIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void springBootExtensionMainClassNameIsUsed() throws IOException {
|
public void springBootExtensionMainClassNameIsUsed() throws IOException {
|
||||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
@ -142,7 +140,7 @@ public abstract class AbstractBootArchiveIntegrationTests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void duplicatesAreHandledGracefully() throws IOException {
|
public void duplicatesAreHandledGracefully() throws IOException {
|
||||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
|
|
@ -41,10 +41,9 @@ import org.gradle.api.Project;
|
||||||
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
|
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
|
||||||
import org.gradle.api.tasks.bundling.Jar;
|
import org.gradle.api.tasks.bundling.Jar;
|
||||||
import org.gradle.testfixtures.ProjectBuilder;
|
import org.gradle.testfixtures.ProjectBuilder;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
|
|
||||||
import org.springframework.boot.loader.tools.DefaultLaunchScript;
|
import org.springframework.boot.loader.tools.DefaultLaunchScript;
|
||||||
|
|
||||||
|
@ -58,8 +57,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||||
|
|
||||||
@Rule
|
@TempDir
|
||||||
public final TemporaryFolder temp = new TemporaryFolder();
|
File temp;
|
||||||
|
|
||||||
private final Class<T> taskClass;
|
private final Class<T> taskClass;
|
||||||
|
|
||||||
|
@ -81,11 +80,12 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||||
this.classesPath = classesPath;
|
this.classesPath = classesPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void createTask() {
|
public void createTask() {
|
||||||
try {
|
try {
|
||||||
this.project = ProjectBuilder.builder().withProjectDir(this.temp.newFolder())
|
File projectDir = new File(this.temp, "project");
|
||||||
.build();
|
projectDir.mkdirs();
|
||||||
|
this.project = ProjectBuilder.builder().withProjectDir(projectDir).build();
|
||||||
this.project
|
this.project
|
||||||
.setDescription("Test project for " + this.taskClass.getSimpleName());
|
.setDescription("Test project for " + this.taskClass.getSimpleName());
|
||||||
this.task = configure(
|
this.task = configure(
|
||||||
|
@ -130,7 +130,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||||
@Test
|
@Test
|
||||||
public void classpathFoldersArePackagedBeneathClassesPath() throws IOException {
|
public void classpathFoldersArePackagedBeneathClassesPath() throws IOException {
|
||||||
this.task.setMainClassName("com.example.Main");
|
this.task.setMainClassName("com.example.Main");
|
||||||
File classpathFolder = this.temp.newFolder();
|
File classpathFolder = new File(this.temp, "classes");
|
||||||
File applicationClass = new File(classpathFolder,
|
File applicationClass = new File(classpathFolder,
|
||||||
"com/example/Application.class");
|
"com/example/Application.class");
|
||||||
applicationClass.getParentFile().mkdirs();
|
applicationClass.getParentFile().mkdirs();
|
||||||
|
@ -147,7 +147,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||||
@Test
|
@Test
|
||||||
public void moduleInfoClassIsPackagedInTheRootOfTheArchive() throws IOException {
|
public void moduleInfoClassIsPackagedInTheRootOfTheArchive() throws IOException {
|
||||||
this.task.setMainClassName("com.example.Main");
|
this.task.setMainClassName("com.example.Main");
|
||||||
File classpathFolder = this.temp.newFolder();
|
File classpathFolder = new File(this.temp, "classes");
|
||||||
File moduleInfoClass = new File(classpathFolder, "module-info.class");
|
File moduleInfoClass = new File(classpathFolder, "module-info.class");
|
||||||
moduleInfoClass.getParentFile().mkdirs();
|
moduleInfoClass.getParentFile().mkdirs();
|
||||||
moduleInfoClass.createNewFile();
|
moduleInfoClass.createNewFile();
|
||||||
|
@ -195,7 +195,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||||
@Test
|
@Test
|
||||||
public void filesOnTheClasspathThatAreNotZipFilesAreSkipped() throws IOException {
|
public void filesOnTheClasspathThatAreNotZipFilesAreSkipped() throws IOException {
|
||||||
this.task.setMainClassName("com.example.Main");
|
this.task.setMainClassName("com.example.Main");
|
||||||
this.task.classpath(this.temp.newFile("test.pom"));
|
this.task.classpath(new File("test.pom"));
|
||||||
this.task.execute();
|
this.task.execute();
|
||||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||||
assertThat(jarFile.getEntry(this.libPath + "/test.pom")).isNull();
|
assertThat(jarFile.getEntry(this.libPath + "/test.pom")).isNull();
|
||||||
|
@ -279,7 +279,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||||
@Test
|
@Test
|
||||||
public void customLaunchScriptCanBePrepended() throws IOException {
|
public void customLaunchScriptCanBePrepended() throws IOException {
|
||||||
this.task.setMainClassName("com.example.Main");
|
this.task.setMainClassName("com.example.Main");
|
||||||
File customScript = this.temp.newFile("custom.script");
|
File customScript = new File(this.temp, "custom.script");
|
||||||
Files.write(customScript.toPath(), Arrays.asList("custom script"),
|
Files.write(customScript.toPath(), Arrays.asList("custom script"),
|
||||||
StandardOpenOption.CREATE);
|
StandardOpenOption.CREATE);
|
||||||
this.task.launchScript((configuration) -> configuration.setScript(customScript));
|
this.task.launchScript((configuration) -> configuration.setScript(customScript));
|
||||||
|
@ -357,8 +357,8 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||||
@Test
|
@Test
|
||||||
public void reproducibleOrderingCanBeEnabled() throws IOException {
|
public void reproducibleOrderingCanBeEnabled() throws IOException {
|
||||||
this.task.setMainClassName("com.example.Main");
|
this.task.setMainClassName("com.example.Main");
|
||||||
this.task.from(this.temp.newFile("bravo.txt"), this.temp.newFile("alpha.txt"),
|
this.task.from(newFile("bravo.txt"), newFile("alpha.txt"),
|
||||||
this.temp.newFile("charlie.txt"));
|
newFile("charlie.txt"));
|
||||||
this.task.setReproducibleFileOrder(true);
|
this.task.setReproducibleFileOrder(true);
|
||||||
executeTask();
|
executeTask();
|
||||||
assertThat(this.task.getArchivePath()).exists();
|
assertThat(this.task.getArchivePath()).exists();
|
||||||
|
@ -378,7 +378,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||||
@Test
|
@Test
|
||||||
public void devtoolsJarIsExcludedByDefault() throws IOException {
|
public void devtoolsJarIsExcludedByDefault() throws IOException {
|
||||||
this.task.setMainClassName("com.example.Main");
|
this.task.setMainClassName("com.example.Main");
|
||||||
this.task.classpath(this.temp.newFile("spring-boot-devtools-0.1.2.jar"));
|
this.task.classpath(newFile("spring-boot-devtools-0.1.2.jar"));
|
||||||
executeTask();
|
executeTask();
|
||||||
assertThat(this.task.getArchivePath()).exists();
|
assertThat(this.task.getArchivePath()).exists();
|
||||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||||
|
@ -404,7 +404,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||||
public void allEntriesUseUnixPlatformAndUtf8NameEncoding() throws IOException {
|
public void allEntriesUseUnixPlatformAndUtf8NameEncoding() throws IOException {
|
||||||
this.task.setMainClassName("com.example.Main");
|
this.task.setMainClassName("com.example.Main");
|
||||||
this.task.setMetadataCharset("UTF-8");
|
this.task.setMetadataCharset("UTF-8");
|
||||||
File classpathFolder = this.temp.newFolder();
|
File classpathFolder = new File(this.temp, "classes");
|
||||||
File resource = new File(classpathFolder, "some-resource.xml");
|
File resource = new File(classpathFolder, "some-resource.xml");
|
||||||
resource.getParentFile().mkdirs();
|
resource.getParentFile().mkdirs();
|
||||||
resource.createNewFile();
|
resource.createNewFile();
|
||||||
|
@ -425,7 +425,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||||
public void loaderIsWrittenFirstThenApplicationClassesThenLibraries()
|
public void loaderIsWrittenFirstThenApplicationClassesThenLibraries()
|
||||||
throws IOException {
|
throws IOException {
|
||||||
this.task.setMainClassName("com.example.Main");
|
this.task.setMainClassName("com.example.Main");
|
||||||
File classpathFolder = this.temp.newFolder();
|
File classpathFolder = new File(this.temp, "classes");
|
||||||
File applicationClass = new File(classpathFolder,
|
File applicationClass = new File(classpathFolder,
|
||||||
"com/example/Application.class");
|
"com/example/Application.class");
|
||||||
applicationClass.getParentFile().mkdirs();
|
applicationClass.getParentFile().mkdirs();
|
||||||
|
@ -442,7 +442,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected File jarFile(String name) throws IOException {
|
protected File jarFile(String name) throws IOException {
|
||||||
File file = this.temp.newFile(name);
|
File file = newFile(name);
|
||||||
try (JarOutputStream jar = new JarOutputStream(new FileOutputStream(file))) {
|
try (JarOutputStream jar = new JarOutputStream(new FileOutputStream(file))) {
|
||||||
jar.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
|
jar.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
|
||||||
new Manifest().write(jar);
|
new Manifest().write(jar);
|
||||||
|
@ -454,7 +454,9 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||||
private T configure(T task) throws IOException {
|
private T configure(T task) throws IOException {
|
||||||
AbstractArchiveTask archiveTask = task;
|
AbstractArchiveTask archiveTask = task;
|
||||||
archiveTask.setBaseName("test");
|
archiveTask.setBaseName("test");
|
||||||
archiveTask.setDestinationDir(this.temp.newFolder());
|
File destination = new File(this.temp, "destination");
|
||||||
|
destination.mkdirs();
|
||||||
|
archiveTask.setDestinationDir(destination);
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,4 +477,10 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||||
return entryNames;
|
return entryNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected File newFile(String name) throws IOException {
|
||||||
|
File file = new File(this.temp, name);
|
||||||
|
file.createNewFile();
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||||
public void devtoolsJarIsExcludedByDefaultWhenItsOnTheProvidedClasspath()
|
public void devtoolsJarIsExcludedByDefaultWhenItsOnTheProvidedClasspath()
|
||||||
throws IOException {
|
throws IOException {
|
||||||
getTask().setMainClassName("com.example.Main");
|
getTask().setMainClassName("com.example.Main");
|
||||||
getTask().providedClasspath(this.temp.newFile("spring-boot-devtools-0.1.2.jar"));
|
getTask().providedClasspath(newFile("spring-boot-devtools-0.1.2.jar"));
|
||||||
executeTask();
|
executeTask();
|
||||||
assertThat(getTask().getArchivePath()).exists();
|
assertThat(getTask().getArchivePath()).exists();
|
||||||
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
|
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
|
||||||
|
@ -103,7 +103,8 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||||
@Test
|
@Test
|
||||||
public void webappResourcesInDirectoriesThatOverlapWithLoaderCanBePackaged()
|
public void webappResourcesInDirectoriesThatOverlapWithLoaderCanBePackaged()
|
||||||
throws IOException {
|
throws IOException {
|
||||||
File webappFolder = this.temp.newFolder("src", "main", "webapp");
|
File webappFolder = new File(this.temp, "src/main/webapp");
|
||||||
|
webappFolder.mkdirs();
|
||||||
File orgFolder = new File(webappFolder, "org");
|
File orgFolder = new File(webappFolder, "org");
|
||||||
orgFolder.mkdir();
|
orgFolder.mkdir();
|
||||||
new File(orgFolder, "foo.txt").createNewFile();
|
new File(orgFolder, "foo.txt").createNewFile();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2018 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -18,8 +18,8 @@ package org.springframework.boot.gradle.tasks.bundling;
|
||||||
|
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
|
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.BDDMockito.given;
|
import static org.mockito.BDDMockito.given;
|
||||||
|
@ -36,7 +36,7 @@ public class LaunchScriptConfigurationTests {
|
||||||
|
|
||||||
private final Project project = mock(Project.class);
|
private final Project project = mock(Project.class);
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
given(this.task.getProject()).willReturn(this.project);
|
given(this.task.getProject()).willReturn(this.project);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -22,11 +22,10 @@ import java.io.IOException;
|
||||||
|
|
||||||
import org.gradle.testkit.runner.BuildResult;
|
import org.gradle.testkit.runner.BuildResult;
|
||||||
import org.gradle.testkit.runner.TaskOutcome;
|
import org.gradle.testkit.runner.TaskOutcome;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleCompatibilitySuite;
|
import org.springframework.boot.gradle.junit.GradleCompatibilityExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -36,13 +35,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleCompatibilitySuite.class)
|
@ExtendWith(GradleCompatibilityExtension.class)
|
||||||
public class MavenIntegrationTests {
|
public class MavenIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootJarCanBeUploaded() throws FileNotFoundException, IOException {
|
public void bootJarCanBeUploaded() throws FileNotFoundException, IOException {
|
||||||
BuildResult result = this.gradleBuild.build("uploadBootArchives");
|
BuildResult result = this.gradleBuild.build("uploadBootArchives");
|
||||||
assertThat(result.task(":uploadBootArchives").getOutcome())
|
assertThat(result.task(":uploadBootArchives").getOutcome())
|
||||||
|
@ -53,7 +51,7 @@ public class MavenIntegrationTests {
|
||||||
.noPackaging().noDependencies());
|
.noPackaging().noDependencies());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootWarCanBeUploaded() throws IOException {
|
public void bootWarCanBeUploaded() throws IOException {
|
||||||
BuildResult result = this.gradleBuild.build("uploadBootArchives");
|
BuildResult result = this.gradleBuild.build("uploadBootArchives");
|
||||||
assertThat(result.task(":uploadBootArchives").getOutcome())
|
assertThat(result.task(":uploadBootArchives").getOutcome())
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -22,11 +22,10 @@ import java.io.IOException;
|
||||||
|
|
||||||
import org.gradle.testkit.runner.BuildResult;
|
import org.gradle.testkit.runner.BuildResult;
|
||||||
import org.gradle.testkit.runner.TaskOutcome;
|
import org.gradle.testkit.runner.TaskOutcome;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleCompatibilitySuite;
|
import org.springframework.boot.gradle.junit.GradleCompatibilityExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -37,13 +36,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleCompatibilitySuite.class)
|
@ExtendWith(GradleCompatibilityExtension.class)
|
||||||
public class MavenPublishingIntegrationTests {
|
public class MavenPublishingIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootJarCanBePublished() throws FileNotFoundException, IOException {
|
public void bootJarCanBePublished() throws FileNotFoundException, IOException {
|
||||||
BuildResult result = this.gradleBuild.build("publish");
|
BuildResult result = this.gradleBuild.build("publish");
|
||||||
assertThat(result.task(":publish").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
assertThat(result.task(":publish").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
@ -53,7 +51,7 @@ public class MavenPublishingIntegrationTests {
|
||||||
.noPackaging().noDependencies());
|
.noPackaging().noDependencies());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void bootWarCanBePublished() throws IOException {
|
public void bootWarCanBePublished() throws IOException {
|
||||||
BuildResult result = this.gradleBuild.build("publish");
|
BuildResult result = this.gradleBuild.build("publish");
|
||||||
assertThat(result.task(":publish").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
assertThat(result.task(":publish").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2017 the original author or authors.
|
* Copyright 2012-2019 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.
|
||||||
|
@ -21,11 +21,10 @@ import java.io.IOException;
|
||||||
|
|
||||||
import org.gradle.testkit.runner.BuildResult;
|
import org.gradle.testkit.runner.BuildResult;
|
||||||
import org.gradle.testkit.runner.TaskOutcome;
|
import org.gradle.testkit.runner.TaskOutcome;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.TestTemplate;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import org.springframework.boot.gradle.junit.GradleCompatibilitySuite;
|
import org.springframework.boot.gradle.junit.GradleCompatibilityExtension;
|
||||||
import org.springframework.boot.gradle.testkit.GradleBuild;
|
import org.springframework.boot.gradle.testkit.GradleBuild;
|
||||||
import org.springframework.util.FileSystemUtils;
|
import org.springframework.util.FileSystemUtils;
|
||||||
|
|
||||||
|
@ -36,13 +35,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
@RunWith(GradleCompatibilitySuite.class)
|
@ExtendWith(GradleCompatibilityExtension.class)
|
||||||
public class BootRunIntegrationTests {
|
public class BootRunIntegrationTests {
|
||||||
|
|
||||||
@Rule
|
GradleBuild gradleBuild;
|
||||||
public GradleBuild gradleBuild;
|
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void basicExecution() throws IOException {
|
public void basicExecution() throws IOException {
|
||||||
copyApplication();
|
copyApplication();
|
||||||
new File(this.gradleBuild.getProjectDir(), "src/main/resources").mkdirs();
|
new File(this.gradleBuild.getProjectDir(), "src/main/resources").mkdirs();
|
||||||
|
@ -56,7 +54,7 @@ public class BootRunIntegrationTests {
|
||||||
.doesNotContain(canonicalPathOf("src/main/resources"));
|
.doesNotContain(canonicalPathOf("src/main/resources"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void sourceResourcesCanBeUsed() throws IOException {
|
public void sourceResourcesCanBeUsed() throws IOException {
|
||||||
copyApplication();
|
copyApplication();
|
||||||
BuildResult result = this.gradleBuild.build("bootRun");
|
BuildResult result = this.gradleBuild.build("bootRun");
|
||||||
|
@ -69,7 +67,7 @@ public class BootRunIntegrationTests {
|
||||||
.doesNotContain(canonicalPathOf("build/resources/main"));
|
.doesNotContain(canonicalPathOf("build/resources/main"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void springBootExtensionMainClassNameIsUsed() throws IOException {
|
public void springBootExtensionMainClassNameIsUsed() throws IOException {
|
||||||
BuildResult result = this.gradleBuild.build("echoMainClassName");
|
BuildResult result = this.gradleBuild.build("echoMainClassName");
|
||||||
assertThat(result.task(":echoMainClassName").getOutcome())
|
assertThat(result.task(":echoMainClassName").getOutcome())
|
||||||
|
@ -78,7 +76,7 @@ public class BootRunIntegrationTests {
|
||||||
.contains("Main class name = com.example.CustomMainClass");
|
.contains("Main class name = com.example.CustomMainClass");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void applicationPluginMainClassNameIsUsed() throws IOException {
|
public void applicationPluginMainClassNameIsUsed() throws IOException {
|
||||||
BuildResult result = this.gradleBuild.build("echoMainClassName");
|
BuildResult result = this.gradleBuild.build("echoMainClassName");
|
||||||
assertThat(result.task(":echoMainClassName").getOutcome())
|
assertThat(result.task(":echoMainClassName").getOutcome())
|
||||||
|
@ -87,7 +85,7 @@ public class BootRunIntegrationTests {
|
||||||
.contains("Main class name = com.example.CustomMainClass");
|
.contains("Main class name = com.example.CustomMainClass");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void applicationPluginMainClassNameIsNotUsedWhenItIsNull() throws IOException {
|
public void applicationPluginMainClassNameIsNotUsedWhenItIsNull() throws IOException {
|
||||||
copyApplication();
|
copyApplication();
|
||||||
BuildResult result = this.gradleBuild.build("echoMainClassName");
|
BuildResult result = this.gradleBuild.build("echoMainClassName");
|
||||||
|
@ -97,7 +95,7 @@ public class BootRunIntegrationTests {
|
||||||
.contains("Main class name = com.example.BootRunApplication");
|
.contains("Main class name = com.example.BootRunApplication");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@TestTemplate
|
||||||
public void applicationPluginJvmArgumentsAreUsed() throws IOException {
|
public void applicationPluginJvmArgumentsAreUsed() throws IOException {
|
||||||
BuildResult result = this.gradleBuild.build("echoJvmArguments");
|
BuildResult result = this.gradleBuild.build("echoJvmArguments");
|
||||||
assertThat(result.task(":echoJvmArguments").getOutcome())
|
assertThat(result.task(":echoJvmArguments").getOutcome())
|
||||||
|
|
|
@ -21,11 +21,11 @@ import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import io.spring.gradle.dependencymanagement.DependencyManagementPlugin;
|
import io.spring.gradle.dependencymanagement.DependencyManagementPlugin;
|
||||||
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension;
|
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension;
|
||||||
|
@ -37,10 +37,6 @@ import org.jetbrains.kotlin.compilerRunner.KotlinLogger;
|
||||||
import org.jetbrains.kotlin.gradle.model.KotlinProject;
|
import org.jetbrains.kotlin.gradle.model.KotlinProject;
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin;
|
import org.jetbrains.kotlin.gradle.plugin.KotlinGradleSubplugin;
|
||||||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlugin;
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPlugin;
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
import org.junit.rules.TestRule;
|
|
||||||
import org.junit.runner.Description;
|
|
||||||
import org.junit.runners.model.Statement;
|
|
||||||
|
|
||||||
import org.springframework.asm.ClassVisitor;
|
import org.springframework.asm.ClassVisitor;
|
||||||
import org.springframework.boot.loader.tools.LaunchScript;
|
import org.springframework.boot.loader.tools.LaunchScript;
|
||||||
|
@ -48,16 +44,11 @@ import org.springframework.util.FileCopyUtils;
|
||||||
import org.springframework.util.FileSystemUtils;
|
import org.springframework.util.FileSystemUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link TestRule} for running a Gradle build using {@link GradleRunner}.
|
* A {@code GradleBuild} is used to run a Gradle build using {@link GradleRunner}.
|
||||||
*
|
*
|
||||||
* @author Andy Wilkinson
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
public class GradleBuild implements TestRule {
|
public class GradleBuild {
|
||||||
|
|
||||||
private static final Pattern GRADLE_VERSION_PATTERN = Pattern
|
|
||||||
.compile("\\[Gradle .+\\]");
|
|
||||||
|
|
||||||
private final TemporaryFolder temp = new TemporaryFolder();
|
|
||||||
|
|
||||||
private final Dsl dsl;
|
private final Dsl dsl;
|
||||||
|
|
||||||
|
@ -79,57 +70,13 @@ public class GradleBuild implements TestRule {
|
||||||
return this.dsl;
|
return this.dsl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
void before() throws IOException {
|
||||||
public Statement apply(Statement base, Description description) {
|
this.projectDir = Files.createTempDirectory("gradle-").toFile();
|
||||||
URL scriptUrl = findDefaultScript(description);
|
|
||||||
if (scriptUrl != null) {
|
|
||||||
script(scriptUrl.getFile());
|
|
||||||
}
|
|
||||||
return this.temp.apply(new Statement() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void evaluate() throws Throwable {
|
|
||||||
before();
|
|
||||||
try {
|
|
||||||
base.evaluate();
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
after();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}, description);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private URL findDefaultScript(Description description) {
|
void after() {
|
||||||
URL scriptUrl = getScriptForTestMethod(description);
|
|
||||||
if (scriptUrl != null) {
|
|
||||||
return scriptUrl;
|
|
||||||
}
|
|
||||||
return getScriptForTestClass(description.getTestClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
private URL getScriptForTestMethod(Description description) {
|
|
||||||
String name = description.getTestClass().getSimpleName() + "-"
|
|
||||||
+ removeGradleVersion(description.getMethodName())
|
|
||||||
+ this.dsl.getExtension();
|
|
||||||
return description.getTestClass().getResource(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String removeGradleVersion(String methodName) {
|
|
||||||
return GRADLE_VERSION_PATTERN.matcher(methodName).replaceAll("").trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
private URL getScriptForTestClass(Class<?> testClass) {
|
|
||||||
return testClass.getResource(testClass.getSimpleName() + this.dsl.getExtension());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void before() throws IOException {
|
|
||||||
this.projectDir = this.temp.newFolder();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void after() {
|
|
||||||
GradleBuild.this.script = null;
|
GradleBuild.this.script = null;
|
||||||
|
FileSystemUtils.deleteRecursively(this.projectDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<File> pluginClasspath() {
|
private List<File> pluginClasspath() {
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012-2019 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
|
||||||
|
*
|
||||||
|
* https://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 org.springframework.boot.gradle.testkit;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.extension.AfterEachCallback;
|
||||||
|
import org.junit.jupiter.api.extension.BeforeEachCallback;
|
||||||
|
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||||
|
|
||||||
|
import org.springframework.util.ReflectionUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An {@link Extension} for managing the lifecycle of a {@link GradleBuild} stored in a
|
||||||
|
* field named {@code gradleBuild}.
|
||||||
|
*
|
||||||
|
* @author Andy Wilkinson
|
||||||
|
*/
|
||||||
|
public class GradleBuildExtension implements BeforeEachCallback, AfterEachCallback {
|
||||||
|
|
||||||
|
private static final Pattern GRADLE_VERSION_PATTERN = Pattern
|
||||||
|
.compile("\\[Gradle .+\\]");
|
||||||
|
|
||||||
|
private Dsl dsl = Dsl.GROOVY;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeEach(ExtensionContext context) throws Exception {
|
||||||
|
GradleBuild gradleBuild = extractGradleBuild(context);
|
||||||
|
URL scriptUrl = findDefaultScript(context);
|
||||||
|
if (scriptUrl != null) {
|
||||||
|
gradleBuild.script(scriptUrl.getFile());
|
||||||
|
}
|
||||||
|
gradleBuild.before();
|
||||||
|
}
|
||||||
|
|
||||||
|
private GradleBuild extractGradleBuild(ExtensionContext context) throws Exception {
|
||||||
|
Object testInstance = context.getRequiredTestInstance();
|
||||||
|
Field gradleBuildField = ReflectionUtils.findField(testInstance.getClass(),
|
||||||
|
"gradleBuild");
|
||||||
|
gradleBuildField.setAccessible(true);
|
||||||
|
GradleBuild gradleBuild = (GradleBuild) gradleBuildField.get(testInstance);
|
||||||
|
return gradleBuild;
|
||||||
|
}
|
||||||
|
|
||||||
|
private URL findDefaultScript(ExtensionContext context) {
|
||||||
|
URL scriptUrl = getScriptForTestMethod(context);
|
||||||
|
if (scriptUrl != null) {
|
||||||
|
return scriptUrl;
|
||||||
|
}
|
||||||
|
return getScriptForTestClass(context.getRequiredTestClass());
|
||||||
|
}
|
||||||
|
|
||||||
|
private URL getScriptForTestMethod(ExtensionContext context) {
|
||||||
|
Class<?> testClass = context.getRequiredTestClass();
|
||||||
|
String name = testClass.getSimpleName() + "-"
|
||||||
|
+ removeGradleVersion(context.getRequiredTestMethod().getName())
|
||||||
|
+ this.dsl.getExtension();
|
||||||
|
return testClass.getResource(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String removeGradleVersion(String methodName) {
|
||||||
|
return GRADLE_VERSION_PATTERN.matcher(methodName).replaceAll("").trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private URL getScriptForTestClass(Class<?> testClass) {
|
||||||
|
return testClass.getResource(testClass.getSimpleName() + this.dsl.getExtension());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterEach(ExtensionContext context) throws Exception {
|
||||||
|
extractGradleBuild(context).after();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue