Merge branch '2.1.x'
Closes gh-17079
This commit is contained in:
@@ -32,8 +32,7 @@ public class BootRunClasspathApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int i = 1;
|
||||
for (String entry : ManagementFactory.getRuntimeMXBean().getClassPath()
|
||||
.split(File.pathSeparator)) {
|
||||
for (String entry : ManagementFactory.getRuntimeMXBean().getClassPath().split(File.pathSeparator)) {
|
||||
System.out.println(i++ + ". " + entry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,8 +38,7 @@ public class GettingStartedDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void typicalPluginsAppliesExceptedPlugins() {
|
||||
this.gradleBuild.script("src/main/gradle/getting-started/typical-plugins")
|
||||
.build("verify");
|
||||
this.gradleBuild.script("src/main/gradle/getting-started/typical-plugins").build("verify");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,20 +42,16 @@ public class IntegratingWithActuatorDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void basicBuildInfo() throws IOException {
|
||||
this.gradleBuild
|
||||
.script("src/main/gradle/integrating-with-actuator/build-info-basic")
|
||||
.build("bootBuildInfo");
|
||||
assertThat(new File(this.gradleBuild.getProjectDir(),
|
||||
"build/resources/main/META-INF/build-info.properties")).isFile();
|
||||
this.gradleBuild.script("src/main/gradle/integrating-with-actuator/build-info-basic").build("bootBuildInfo");
|
||||
assertThat(new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties"))
|
||||
.isFile();
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void buildInfoCustomValues() throws IOException {
|
||||
this.gradleBuild.script(
|
||||
"src/main/gradle/integrating-with-actuator/build-info-custom-values")
|
||||
this.gradleBuild.script("src/main/gradle/integrating-with-actuator/build-info-custom-values")
|
||||
.build("bootBuildInfo");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/resources/main/META-INF/build-info.properties");
|
||||
File file = new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties");
|
||||
assertThat(file).isFile();
|
||||
Properties properties = buildInfoProperties(file);
|
||||
assertThat(properties).containsEntry("build.artifact", "example-app");
|
||||
@@ -66,11 +62,9 @@ public class IntegratingWithActuatorDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void buildInfoAdditional() throws IOException {
|
||||
this.gradleBuild
|
||||
.script("src/main/gradle/integrating-with-actuator/build-info-additional")
|
||||
this.gradleBuild.script("src/main/gradle/integrating-with-actuator/build-info-additional")
|
||||
.build("bootBuildInfo");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/resources/main/META-INF/build-info.properties");
|
||||
File file = new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties");
|
||||
assertThat(file).isFile();
|
||||
Properties properties = buildInfoProperties(file);
|
||||
assertThat(properties).containsEntry("build.a", "alpha");
|
||||
|
||||
@@ -39,32 +39,27 @@ public class ManagingDependenciesDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void dependenciesExampleEvaluatesSuccessfully() {
|
||||
this.gradleBuild.script("src/main/gradle/managing-dependencies/dependencies")
|
||||
.build();
|
||||
this.gradleBuild.script("src/main/gradle/managing-dependencies/dependencies").build();
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void customManagedVersions() {
|
||||
assertThat(this.gradleBuild
|
||||
.script("src/main/gradle/managing-dependencies/custom-version")
|
||||
.build("slf4jVersion").getOutput()).contains("1.7.20");
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/managing-dependencies/custom-version").build("slf4jVersion")
|
||||
.getOutput()).contains("1.7.20");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void dependencyManagementInIsolation() {
|
||||
assertThat(this.gradleBuild
|
||||
.script("src/main/gradle/managing-dependencies/configure-bom")
|
||||
.build("dependencyManagement").getOutput())
|
||||
.contains("org.springframework.boot:spring-boot-starter ");
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/managing-dependencies/configure-bom")
|
||||
.build("dependencyManagement").getOutput()).contains("org.springframework.boot:spring-boot-starter ");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void dependencyManagementInIsolationWithPluginsBlock() {
|
||||
Assume.assumeTrue(this.gradleBuild.getDsl() == Dsl.KOTLIN);
|
||||
assertThat(this.gradleBuild.script(
|
||||
"src/main/gradle/managing-dependencies/configure-bom-with-plugins")
|
||||
.build("dependencyManagement").getOutput()).contains(
|
||||
"org.springframework.boot:spring-boot-starter TEST-SNAPSHOT");
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/managing-dependencies/configure-bom-with-plugins")
|
||||
.build("dependencyManagement").getOutput())
|
||||
.contains("org.springframework.boot:spring-boot-starter TEST-SNAPSHOT");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,14 +49,12 @@ public class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void warContainerDependencyEvaluatesSuccessfully() {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/war-container-dependency")
|
||||
.build();
|
||||
this.gradleBuild.script("src/main/gradle/packaging/war-container-dependency").build();
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void bootJarMainClass() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-main-class")
|
||||
.build("bootJar");
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-main-class").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -68,8 +66,7 @@ public class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void bootJarManifestMainClass() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-manifest-main-class")
|
||||
.build("bootJar");
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-manifest-main-class").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -81,8 +78,7 @@ public class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void applicationPluginMainClass() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/application-plugin-main-class")
|
||||
.build("bootJar");
|
||||
this.gradleBuild.script("src/main/gradle/packaging/application-plugin-main-class").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -94,8 +90,7 @@ public class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void springBootDslMainClass() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/spring-boot-dsl-main-class")
|
||||
.build("bootJar");
|
||||
this.gradleBuild.script("src/main/gradle/packaging/spring-boot-dsl-main-class").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -107,23 +102,19 @@ public class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void bootWarIncludeDevtools() throws IOException {
|
||||
jarFile(new File(this.gradleBuild.getProjectDir(),
|
||||
"spring-boot-devtools-1.2.3.RELEASE.jar"));
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-war-include-devtools")
|
||||
.build("bootWar");
|
||||
jarFile(new File(this.gradleBuild.getProjectDir(), "spring-boot-devtools-1.2.3.RELEASE.jar"));
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-war-include-devtools").build("bootWar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".war");
|
||||
assertThat(file).isFile();
|
||||
try (JarFile jar = new JarFile(file)) {
|
||||
assertThat(jar.getEntry("WEB-INF/lib/spring-boot-devtools-1.2.3.RELEASE.jar"))
|
||||
.isNotNull();
|
||||
assertThat(jar.getEntry("WEB-INF/lib/spring-boot-devtools-1.2.3.RELEASE.jar")).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void bootJarRequiresUnpack() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-requires-unpack")
|
||||
.build("bootJar");
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-requires-unpack").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -136,36 +127,28 @@ public class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void bootJarIncludeLaunchScript() throws IOException {
|
||||
this.gradleBuild
|
||||
.script("src/main/gradle/packaging/boot-jar-include-launch-script")
|
||||
.build("bootJar");
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-include-launch-script").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
assertThat(FileCopyUtils.copyToString(new FileReader(file)))
|
||||
.startsWith("#!/bin/bash");
|
||||
assertThat(FileCopyUtils.copyToString(new FileReader(file))).startsWith("#!/bin/bash");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void bootJarLaunchScriptProperties() throws IOException {
|
||||
this.gradleBuild
|
||||
.script("src/main/gradle/packaging/boot-jar-launch-script-properties")
|
||||
.build("bootJar");
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-launch-script-properties").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
assertThat(FileCopyUtils.copyToString(new FileReader(file)))
|
||||
.contains("example-app.log");
|
||||
assertThat(FileCopyUtils.copyToString(new FileReader(file))).contains("example-app.log");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void bootJarCustomLaunchScript() throws IOException {
|
||||
File customScriptFile = new File(this.gradleBuild.getProjectDir(),
|
||||
"src/custom.script");
|
||||
File customScriptFile = new File(this.gradleBuild.getProjectDir(), "src/custom.script");
|
||||
customScriptFile.getParentFile().mkdirs();
|
||||
FileCopyUtils.copy("custom", new FileWriter(customScriptFile));
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-custom-launch-script")
|
||||
.build("bootJar");
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-custom-launch-script").build("bootJar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(file).isFile();
|
||||
@@ -174,8 +157,7 @@ public class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void bootWarPropertiesLauncher() throws IOException {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-war-properties-launcher")
|
||||
.build("bootWar");
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-war-properties-launcher").build("bootWar");
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".war");
|
||||
assertThat(file).isFile();
|
||||
@@ -187,8 +169,7 @@ public class PackagingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void bootJarAndJar() {
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-and-jar")
|
||||
.build("assemble");
|
||||
this.gradleBuild.script("src/main/gradle/packaging/boot-jar-and-jar").build("assemble");
|
||||
File jar = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/libs/" + this.gradleBuild.getProjectDir().getName() + ".jar");
|
||||
assertThat(jar).isFile();
|
||||
|
||||
@@ -39,17 +39,14 @@ public class PublishingDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void mavenUpload() throws IOException {
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven")
|
||||
.build("deployerRepository").getOutput())
|
||||
.contains("https://repo.example.com");
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven").build("deployerRepository").getOutput())
|
||||
.contains("https://repo.example.com");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void mavenPublish() throws IOException {
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven-publish")
|
||||
.build("publishingConfiguration").getOutput())
|
||||
.contains("MavenPublication")
|
||||
.contains("https://repo.example.com");
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/publishing/maven-publish").build("publishingConfiguration")
|
||||
.getOutput()).contains("MavenPublication").contains("https://repo.example.com");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,39 +40,31 @@ public class RunningDocumentationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void bootRunMain() throws IOException {
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/running/boot-run-main")
|
||||
.build("configuredMainClass").getOutput())
|
||||
.contains("com.example.ExampleApplication");
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/running/boot-run-main").build("configuredMainClass")
|
||||
.getOutput()).contains("com.example.ExampleApplication");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void applicationPluginMainClassName() {
|
||||
assertThat(this.gradleBuild
|
||||
.script("src/main/gradle/running/application-plugin-main-class-name")
|
||||
.build("configuredMainClass").getOutput())
|
||||
.contains("com.example.ExampleApplication");
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/running/application-plugin-main-class-name")
|
||||
.build("configuredMainClass").getOutput()).contains("com.example.ExampleApplication");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void springBootDslMainClassName() throws IOException {
|
||||
assertThat(this.gradleBuild
|
||||
.script("src/main/gradle/running/spring-boot-dsl-main-class-name")
|
||||
.build("configuredMainClass").getOutput())
|
||||
.contains("com.example.ExampleApplication");
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/running/spring-boot-dsl-main-class-name")
|
||||
.build("configuredMainClass").getOutput()).contains("com.example.ExampleApplication");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void bootRunSourceResources() throws IOException {
|
||||
assertThat(this.gradleBuild
|
||||
.script("src/main/gradle/running/boot-run-source-resources")
|
||||
.build("configuredClasspath").getOutput())
|
||||
.contains(new File("src/main/resources").getPath());
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/running/boot-run-source-resources")
|
||||
.build("configuredClasspath").getOutput()).contains(new File("src/main/resources").getPath());
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void bootRunDisableOptimizedLaunch() throws IOException {
|
||||
assertThat(this.gradleBuild
|
||||
.script("src/main/gradle/running/boot-run-disable-optimized-launch")
|
||||
assertThat(this.gradleBuild.script("src/main/gradle/running/boot-run-disable-optimized-launch")
|
||||
.build("optimizedLaunch").getOutput()).contains("false");
|
||||
}
|
||||
|
||||
|
||||
@@ -44,24 +44,21 @@ public class BuildInfoDslIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void basicJar() throws IOException {
|
||||
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace")
|
||||
.task(":bootBuildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
Properties properties = buildInfoProperties();
|
||||
assertThat(properties).containsEntry("build.name",
|
||||
this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.artifact",
|
||||
this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.name", this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.artifact", this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.group", "com.example");
|
||||
assertThat(properties).containsEntry("build.version", "1.0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarWithCustomName() throws IOException {
|
||||
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace")
|
||||
.task(":bootBuildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
Properties properties = buildInfoProperties();
|
||||
assertThat(properties).containsEntry("build.name",
|
||||
this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.name", this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.artifact", "foo");
|
||||
assertThat(properties).containsEntry("build.group", "com.example");
|
||||
assertThat(properties).containsEntry("build.version", "1.0");
|
||||
@@ -69,24 +66,21 @@ public class BuildInfoDslIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void basicWar() throws IOException {
|
||||
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace")
|
||||
.task(":bootBuildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
Properties properties = buildInfoProperties();
|
||||
assertThat(properties).containsEntry("build.name",
|
||||
this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.artifact",
|
||||
this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.name", this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.artifact", this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.group", "com.example");
|
||||
assertThat(properties).containsEntry("build.version", "1.0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void warWithCustomName() throws IOException {
|
||||
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace")
|
||||
.task(":bootBuildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
Properties properties = buildInfoProperties();
|
||||
assertThat(properties).containsEntry("build.name",
|
||||
this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.name", this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.artifact", "foo");
|
||||
assertThat(properties).containsEntry("build.group", "com.example");
|
||||
assertThat(properties).containsEntry("build.version", "1.0");
|
||||
@@ -94,13 +88,11 @@ public class BuildInfoDslIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void additionalProperties() throws IOException {
|
||||
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace")
|
||||
.task(":bootBuildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("bootBuildInfo", "--stacktrace").task(":bootBuildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
Properties properties = buildInfoProperties();
|
||||
assertThat(properties).containsEntry("build.name",
|
||||
this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.artifact",
|
||||
this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.name", this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.artifact", this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(properties).containsEntry("build.group", "com.example");
|
||||
assertThat(properties).containsEntry("build.version", "1.0");
|
||||
assertThat(properties).containsEntry("build.a", "alpha");
|
||||
@@ -109,13 +101,12 @@ public class BuildInfoDslIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void classesDependency() throws IOException {
|
||||
assertThat(this.gradleBuild.build("classes", "--stacktrace")
|
||||
.task(":bootBuildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("classes", "--stacktrace").task(":bootBuildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
private Properties buildInfoProperties() {
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/resources/main/META-INF/build-info.properties");
|
||||
File file = new File(this.gradleBuild.getProjectDir(), "build/resources/main/META-INF/build-info.properties");
|
||||
assertThat(file).isFile();
|
||||
Properties properties = new Properties();
|
||||
try (FileReader reader = new FileReader(file)) {
|
||||
|
||||
@@ -40,8 +40,7 @@ final class GradleBuildFieldSetter implements BeforeEachCallback {
|
||||
|
||||
@Override
|
||||
public void beforeEach(ExtensionContext context) throws Exception {
|
||||
Field field = ReflectionUtils.findField(context.getRequiredTestClass(),
|
||||
"gradleBuild");
|
||||
Field field = ReflectionUtils.findField(context.getRequiredTestClass(), "gradleBuild");
|
||||
field.setAccessible(true);
|
||||
field.set(context.getRequiredTestInstance(), this.gradleBuild);
|
||||
|
||||
|
||||
@@ -35,17 +35,14 @@ import org.springframework.boot.gradle.testkit.GradleBuildExtension;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public final class GradleCompatibilityExtension
|
||||
implements TestTemplateInvocationContextProvider {
|
||||
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");
|
||||
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);
|
||||
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
|
||||
return GRADLE_VERSIONS.stream().map(GradleVersionTestTemplateInvocationContext::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,8 +50,7 @@ public final class GradleCompatibilityExtension
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final class GradleVersionTestTemplateInvocationContext
|
||||
implements TestTemplateInvocationContext {
|
||||
private static final class GradleVersionTestTemplateInvocationContext implements TestTemplateInvocationContext {
|
||||
|
||||
private final String gradleVersion;
|
||||
|
||||
@@ -73,8 +69,7 @@ public final class GradleCompatibilityExtension
|
||||
if (!this.gradleVersion.equals("default")) {
|
||||
gradleBuild.gradleVersion(this.gradleVersion);
|
||||
}
|
||||
return Arrays.asList(new GradleBuildFieldSetter(gradleBuild),
|
||||
new GradleBuildExtension());
|
||||
return Arrays.asList(new GradleBuildFieldSetter(gradleBuild), new GradleBuildExtension());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,8 +39,7 @@ import org.springframework.boot.gradle.testkit.GradleBuildExtension;
|
||||
public class GradleMultiDslExtension implements TestTemplateInvocationContextProvider {
|
||||
|
||||
@Override
|
||||
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(
|
||||
ExtensionContext context) {
|
||||
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
|
||||
return Stream.of(Dsl.values()).map(DslTestTemplateInvocationContext::new);
|
||||
}
|
||||
|
||||
@@ -49,8 +48,7 @@ public class GradleMultiDslExtension implements TestTemplateInvocationContextPro
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final class DslTestTemplateInvocationContext
|
||||
implements TestTemplateInvocationContext {
|
||||
private static final class DslTestTemplateInvocationContext implements TestTemplateInvocationContext {
|
||||
|
||||
private final Dsl dsl;
|
||||
|
||||
@@ -60,8 +58,7 @@ public class GradleMultiDslExtension implements TestTemplateInvocationContextPro
|
||||
|
||||
@Override
|
||||
public List<Extension> getAdditionalExtensions() {
|
||||
return Arrays.asList(new GradleBuildFieldSetter(new GradleBuild(this.dsl)),
|
||||
new GradleBuildExtension());
|
||||
return Arrays.asList(new GradleBuildFieldSetter(new GradleBuild(this.dsl)), new GradleBuildExtension());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -49,120 +49,100 @@ public class ApplicationPluginActionIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void noBootDistributionWithoutApplicationPluginApplied() {
|
||||
assertThat(this.gradleBuild.build("distributionExists", "-PdistributionName=boot")
|
||||
.getOutput()).contains("boot exists = false");
|
||||
assertThat(this.gradleBuild.build("distributionExists", "-PdistributionName=boot").getOutput())
|
||||
.contains("boot exists = false");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void applyingApplicationPluginCreatesBootDistribution() {
|
||||
assertThat(this.gradleBuild.build("distributionExists", "-PdistributionName=boot",
|
||||
"-PapplyApplicationPlugin").getOutput()).contains("boot exists = true");
|
||||
assertThat(this.gradleBuild.build("distributionExists", "-PdistributionName=boot", "-PapplyApplicationPlugin")
|
||||
.getOutput()).contains("boot exists = true");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void noBootStartScriptsTaskWithoutApplicationPluginApplied() {
|
||||
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootStartScripts")
|
||||
.getOutput()).contains("bootStartScripts exists = false");
|
||||
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootStartScripts").getOutput())
|
||||
.contains("bootStartScripts exists = false");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void applyingApplicationPluginCreatesBootStartScriptsTask() {
|
||||
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootStartScripts",
|
||||
"-PapplyApplicationPlugin").getOutput())
|
||||
.contains("bootStartScripts exists = true");
|
||||
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootStartScripts", "-PapplyApplicationPlugin")
|
||||
.getOutput()).contains("bootStartScripts exists = true");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void createsBootStartScriptsTaskUsesApplicationPluginsDefaultJvmOpts() {
|
||||
assertThat(this.gradleBuild
|
||||
.build("startScriptsDefaultJvmOpts", "-PapplyApplicationPlugin")
|
||||
.getOutput()).contains(
|
||||
"bootStartScripts defaultJvmOpts = [-Dcom.example.a=alpha, -Dcom.example.b=bravo]");
|
||||
assertThat(this.gradleBuild.build("startScriptsDefaultJvmOpts", "-PapplyApplicationPlugin").getOutput())
|
||||
.contains("bootStartScripts defaultJvmOpts = [-Dcom.example.a=alpha, -Dcom.example.b=bravo]");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void zipDistributionForJarCanBeBuilt() throws IOException {
|
||||
assertThat(
|
||||
this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
String name = this.gradleBuild.getProjectDir().getName();
|
||||
File distribution = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/distributions/" + name + "-boot.zip");
|
||||
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.zip");
|
||||
assertThat(distribution).isFile();
|
||||
assertThat(zipEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/",
|
||||
name + "-boot/lib/", name + "-boot/lib/" + name + ".jar",
|
||||
name + "-boot/bin/", name + "-boot/bin/" + name,
|
||||
assertThat(zipEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/", name + "-boot/lib/",
|
||||
name + "-boot/lib/" + name + ".jar", name + "-boot/bin/", name + "-boot/bin/" + name,
|
||||
name + "-boot/bin/" + name + ".bat");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void tarDistributionForJarCanBeBuilt() throws IOException {
|
||||
assertThat(
|
||||
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
String name = this.gradleBuild.getProjectDir().getName();
|
||||
File distribution = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/distributions/" + name + "-boot.tar");
|
||||
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.tar");
|
||||
assertThat(distribution).isFile();
|
||||
assertThat(tarEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/",
|
||||
name + "-boot/lib/", name + "-boot/lib/" + name + ".jar",
|
||||
name + "-boot/bin/", name + "-boot/bin/" + name,
|
||||
assertThat(tarEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/", name + "-boot/lib/",
|
||||
name + "-boot/lib/" + name + ".jar", name + "-boot/bin/", name + "-boot/bin/" + name,
|
||||
name + "-boot/bin/" + name + ".bat");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void zipDistributionForWarCanBeBuilt() throws IOException {
|
||||
assertThat(
|
||||
this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("bootDistZip").task(":bootDistZip").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
String name = this.gradleBuild.getProjectDir().getName();
|
||||
File distribution = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/distributions/" + name + "-boot.zip");
|
||||
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.zip");
|
||||
assertThat(distribution).isFile();
|
||||
assertThat(zipEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/",
|
||||
name + "-boot/lib/", name + "-boot/lib/" + name + ".war",
|
||||
name + "-boot/bin/", name + "-boot/bin/" + name,
|
||||
assertThat(zipEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/", name + "-boot/lib/",
|
||||
name + "-boot/lib/" + name + ".war", name + "-boot/bin/", name + "-boot/bin/" + name,
|
||||
name + "-boot/bin/" + name + ".bat");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void tarDistributionForWarCanBeBuilt() throws IOException {
|
||||
assertThat(
|
||||
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
String name = this.gradleBuild.getProjectDir().getName();
|
||||
File distribution = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/distributions/" + name + "-boot.tar");
|
||||
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.tar");
|
||||
assertThat(distribution).isFile();
|
||||
assertThat(tarEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/",
|
||||
name + "-boot/lib/", name + "-boot/lib/" + name + ".war",
|
||||
name + "-boot/bin/", name + "-boot/bin/" + name,
|
||||
assertThat(tarEntryNames(distribution)).containsExactlyInAnyOrder(name + "-boot/", name + "-boot/lib/",
|
||||
name + "-boot/lib/" + name + ".war", name + "-boot/bin/", name + "-boot/bin/" + name,
|
||||
name + "-boot/bin/" + name + ".bat");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void applicationNameCanBeUsedToCustomizeDistributionName() throws IOException {
|
||||
assertThat(
|
||||
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
File distribution = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/distributions/custom-boot.tar");
|
||||
assertThat(this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/custom-boot.tar");
|
||||
assertThat(distribution).isFile();
|
||||
String name = this.gradleBuild.getProjectDir().getName();
|
||||
assertThat(tarEntryNames(distribution)).containsExactlyInAnyOrder("custom-boot/",
|
||||
"custom-boot/lib/", "custom-boot/lib/" + name + ".jar",
|
||||
"custom-boot/bin/", "custom-boot/bin/custom",
|
||||
assertThat(tarEntryNames(distribution)).containsExactlyInAnyOrder("custom-boot/", "custom-boot/lib/",
|
||||
"custom-boot/lib/" + name + ".jar", "custom-boot/bin/", "custom-boot/bin/custom",
|
||||
"custom-boot/bin/custom.bat");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void scriptsHaveCorrectPermissions() throws IOException {
|
||||
assertThat(
|
||||
this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("bootDistTar").task(":bootDistTar").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
String name = this.gradleBuild.getProjectDir().getName();
|
||||
File distribution = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/distributions/" + name + "-boot.tar");
|
||||
File distribution = new File(this.gradleBuild.getProjectDir(), "build/distributions/" + name + "-boot.tar");
|
||||
assertThat(distribution).isFile();
|
||||
tarEntries(distribution, (entry) -> {
|
||||
int filePermissions = entry.getMode() & 0777;
|
||||
@@ -188,8 +168,7 @@ public class ApplicationPluginActionIntegrationTests {
|
||||
|
||||
private List<String> tarEntryNames(File distribution) throws IOException {
|
||||
List<String> entryNames = new ArrayList<>();
|
||||
try (TarArchiveInputStream input = new TarArchiveInputStream(
|
||||
new FileInputStream(distribution))) {
|
||||
try (TarArchiveInputStream input = new TarArchiveInputStream(new FileInputStream(distribution))) {
|
||||
TarArchiveEntry entry;
|
||||
while ((entry = input.getNextTarEntry()) != null) {
|
||||
entryNames.add(entry.getName());
|
||||
@@ -198,10 +177,8 @@ public class ApplicationPluginActionIntegrationTests {
|
||||
return entryNames;
|
||||
}
|
||||
|
||||
private void tarEntries(File distribution, Consumer<TarArchiveEntry> consumer)
|
||||
throws IOException {
|
||||
try (TarArchiveInputStream input = new TarArchiveInputStream(
|
||||
new FileInputStream(distribution))) {
|
||||
private void tarEntries(File distribution, Consumer<TarArchiveEntry> consumer) throws IOException {
|
||||
try (TarArchiveInputStream input = new TarArchiveInputStream(new FileInputStream(distribution))) {
|
||||
TarArchiveEntry entry;
|
||||
while ((entry = input.getNextTarEntry()) != null) {
|
||||
consumer.accept(entry);
|
||||
|
||||
@@ -43,35 +43,28 @@ public class DependencyManagementPluginActionIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void noDependencyManagementIsAppliedByDefault() {
|
||||
assertThat(this.gradleBuild.build("doesNotHaveDependencyManagement")
|
||||
.task(":doesNotHaveDependencyManagement").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("doesNotHaveDependencyManagement").task(":doesNotHaveDependencyManagement")
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void bomIsImportedWhenDependencyManagementPluginIsApplied() {
|
||||
assertThat(this.gradleBuild
|
||||
.build("hasDependencyManagement", "-PapplyDependencyManagementPlugin")
|
||||
.task(":hasDependencyManagement").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("hasDependencyManagement", "-PapplyDependencyManagementPlugin")
|
||||
.task(":hasDependencyManagement").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void helpfulErrorWhenVersionlessDependencyFailsToResolve() throws IOException {
|
||||
File examplePackage = new File(this.gradleBuild.getProjectDir(),
|
||||
"src/main/java/com/example");
|
||||
File examplePackage = new File(this.gradleBuild.getProjectDir(), "src/main/java/com/example");
|
||||
examplePackage.mkdirs();
|
||||
FileSystemUtils.copyRecursively(new File("src/test/java/com/example"),
|
||||
examplePackage);
|
||||
FileSystemUtils.copyRecursively(new File("src/test/java/com/example"), examplePackage);
|
||||
BuildResult result = this.gradleBuild.buildAndFail("compileJava");
|
||||
assertThat(result.task(":compileJava").getOutcome())
|
||||
.isEqualTo(TaskOutcome.FAILED);
|
||||
assertThat(result.task(":compileJava").getOutcome()).isEqualTo(TaskOutcome.FAILED);
|
||||
String output = result.getOutput();
|
||||
assertThat(output).contains("During the build, one or more dependencies that "
|
||||
+ "were declared without a version failed to resolve:");
|
||||
assertThat(output).contains("org.springframework.boot:spring-boot-starter-web:");
|
||||
assertThat(output).contains("Did you forget to apply the "
|
||||
+ "io.spring.dependency-management plugin to the "
|
||||
assertThat(output).contains("Did you forget to apply the " + "io.spring.dependency-management plugin to the "
|
||||
+ this.gradleBuild.getProjectDir().getName() + " project?");
|
||||
}
|
||||
|
||||
|
||||
@@ -49,9 +49,8 @@ public class JavaPluginActionIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void applyingJavaPluginCreatesBootJarTask() {
|
||||
assertThat(this.gradleBuild
|
||||
.build("taskExists", "-PtaskName=bootJar", "-PapplyJavaPlugin")
|
||||
.getOutput()).contains("bootJar exists = true");
|
||||
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootJar", "-PapplyJavaPlugin").getOutput())
|
||||
.contains("bootJar exists = true");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
@@ -62,16 +61,14 @@ public class JavaPluginActionIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void applyingJavaPluginCreatesBootRunTask() {
|
||||
assertThat(this.gradleBuild
|
||||
.build("taskExists", "-PtaskName=bootRun", "-PapplyJavaPlugin")
|
||||
.getOutput()).contains("bootRun exists = true");
|
||||
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootRun", "-PapplyJavaPlugin").getOutput())
|
||||
.contains("bootRun exists = true");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void javaCompileTasksUseUtf8Encoding() {
|
||||
assertThat(this.gradleBuild.build("javaCompileEncoding", "-PapplyJavaPlugin")
|
||||
.getOutput()).contains("compileJava = UTF-8")
|
||||
.contains("compileTestJava = UTF-8");
|
||||
assertThat(this.gradleBuild.build("javaCompileEncoding", "-PapplyJavaPlugin").getOutput())
|
||||
.contains("compileJava = UTF-8").contains("compileTestJava = UTF-8");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
@@ -106,8 +103,7 @@ public class JavaPluginActionIntegrationTests {
|
||||
public void errorMessageIsHelpfulWhenMainClassCannotBeResolved() {
|
||||
BuildResult result = this.gradleBuild.buildAndFail("build", "-PapplyJavaPlugin");
|
||||
assertThat(result.task(":bootJar").getOutcome()).isEqualTo(TaskOutcome.FAILED);
|
||||
assertThat(result.getOutput()).contains(
|
||||
"Main class name has not been configured and it could not be resolved");
|
||||
assertThat(result.getOutput()).contains("Main class name has not been configured and it could not be resolved");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
@@ -118,42 +114,33 @@ public class JavaPluginActionIntegrationTests {
|
||||
File buildLibs = new File(this.gradleBuild.getProjectDir(), "build/libs");
|
||||
assertThat(buildLibs.listFiles()).containsExactlyInAnyOrder(
|
||||
new File(buildLibs, this.gradleBuild.getProjectDir().getName() + ".jar"),
|
||||
new File(buildLibs,
|
||||
this.gradleBuild.getProjectDir().getName() + "-boot.jar"));
|
||||
new File(buildLibs, this.gradleBuild.getProjectDir().getName() + "-boot.jar"));
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void additionalMetadataLocationsConfiguredWhenProcessorIsPresent()
|
||||
throws IOException {
|
||||
public void additionalMetadataLocationsConfiguredWhenProcessorIsPresent() throws IOException {
|
||||
createMinimalMainSource();
|
||||
File libs = new File(this.gradleBuild.getProjectDir(), "libs");
|
||||
libs.mkdirs();
|
||||
new JarOutputStream(new FileOutputStream(
|
||||
new File(libs, "spring-boot-configuration-processor-1.2.3.jar"))).close();
|
||||
new JarOutputStream(new FileOutputStream(new File(libs, "spring-boot-configuration-processor-1.2.3.jar")))
|
||||
.close();
|
||||
BuildResult result = this.gradleBuild.build("compileJava");
|
||||
assertThat(result.task(":compileJava").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).contains(
|
||||
"compileJava compiler args: [-parameters, -Aorg.springframework.boot."
|
||||
+ "configurationprocessor.additionalMetadataLocations="
|
||||
+ new File(this.gradleBuild.getProjectDir(), "src/main/resources")
|
||||
.getCanonicalPath());
|
||||
assertThat(result.task(":compileJava").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).contains("compileJava compiler args: [-parameters, -Aorg.springframework.boot."
|
||||
+ "configurationprocessor.additionalMetadataLocations="
|
||||
+ new File(this.gradleBuild.getProjectDir(), "src/main/resources").getCanonicalPath());
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void additionalMetadataLocationsNotConfiguredWhenProcessorIsAbsent()
|
||||
throws IOException {
|
||||
public void additionalMetadataLocationsNotConfiguredWhenProcessorIsAbsent() throws IOException {
|
||||
createMinimalMainSource();
|
||||
BuildResult result = this.gradleBuild.build("compileJava");
|
||||
assertThat(result.task(":compileJava").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput())
|
||||
.contains("compileJava compiler args: [-parameters]");
|
||||
assertThat(result.task(":compileJava").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).contains("compileJava compiler args: [-parameters]");
|
||||
}
|
||||
|
||||
private void createMinimalMainSource() throws IOException {
|
||||
File examplePackage = new File(this.gradleBuild.getProjectDir(),
|
||||
"src/main/java/com/example");
|
||||
File examplePackage = new File(this.gradleBuild.getProjectDir(), "src/main/java/com/example");
|
||||
examplePackage.mkdirs();
|
||||
new File(examplePackage, "Application.java").createNewFile();
|
||||
}
|
||||
|
||||
@@ -36,29 +36,26 @@ public class KotlinPluginActionIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void noKotlinVersionPropertyWithoutKotlinPlugin() {
|
||||
assertThat(this.gradleBuild.build("kotlinVersion").getOutput())
|
||||
.contains("Kotlin version: none");
|
||||
assertThat(this.gradleBuild.build("kotlinVersion").getOutput()).contains("Kotlin version: none");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void kotlinVersionPropertyIsSet() {
|
||||
String output = this.gradleBuild.build("kotlinVersion", "dependencies",
|
||||
"--configuration", "compileClasspath").getOutput();
|
||||
String output = this.gradleBuild.build("kotlinVersion", "dependencies", "--configuration", "compileClasspath")
|
||||
.getOutput();
|
||||
assertThat(output).containsPattern("Kotlin version: [0-9]\\.[0-9]\\.[0-9]+");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void kotlinCompileTasksUseJavaParametersFlagByDefault() {
|
||||
assertThat(this.gradleBuild.build("kotlinCompileTasksJavaParameters").getOutput())
|
||||
.contains("compileKotlin java parameters: true")
|
||||
.contains("compileTestKotlin java parameters: true");
|
||||
.contains("compileKotlin java parameters: true").contains("compileTestKotlin java parameters: true");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void kotlinCompileTasksCanOverrideDefaultJavaParametersFlag() {
|
||||
assertThat(this.gradleBuild.build("kotlinCompileTasksJavaParameters").getOutput())
|
||||
.contains("compileKotlin java parameters: false")
|
||||
.contains("compileTestKotlin java parameters: false");
|
||||
.contains("compileKotlin java parameters: false").contains("compileTestKotlin java parameters: false");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,29 +47,27 @@ public class MainClassConventionTests {
|
||||
|
||||
@Test
|
||||
public void mainClassNameProjectPropertyIsUsed() throws Exception {
|
||||
this.project.getExtensions().getByType(ExtraPropertiesExtension.class)
|
||||
.set("mainClassName", "com.example.MainClass");
|
||||
this.project.getExtensions().getByType(ExtraPropertiesExtension.class).set("mainClassName",
|
||||
"com.example.MainClass");
|
||||
assertThat(this.convention.call()).isEqualTo("com.example.MainClass");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void springBootExtensionMainClassNameIsUsed() throws Exception {
|
||||
SpringBootExtension extension = this.project.getExtensions().create("springBoot",
|
||||
SpringBootExtension.class, this.project);
|
||||
SpringBootExtension extension = this.project.getExtensions().create("springBoot", SpringBootExtension.class,
|
||||
this.project);
|
||||
extension.setMainClassName("com.example.MainClass");
|
||||
assertThat(this.convention.call()).isEqualTo("com.example.MainClass");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void springBootExtensionMainClassNameIsUsedInPreferenceToMainClassNameProjectProperty()
|
||||
throws Exception {
|
||||
this.project.getExtensions().getByType(ExtraPropertiesExtension.class)
|
||||
.set("mainClassName", "com.example.ProjectPropertyMainClass");
|
||||
SpringBootExtension extension = this.project.getExtensions().create("springBoot",
|
||||
SpringBootExtension.class, this.project);
|
||||
public void springBootExtensionMainClassNameIsUsedInPreferenceToMainClassNameProjectProperty() throws Exception {
|
||||
this.project.getExtensions().getByType(ExtraPropertiesExtension.class).set("mainClassName",
|
||||
"com.example.ProjectPropertyMainClass");
|
||||
SpringBootExtension extension = this.project.getExtensions().create("springBoot", SpringBootExtension.class,
|
||||
this.project);
|
||||
extension.setMainClassName("com.example.SpringBootExtensionMainClass");
|
||||
assertThat(this.convention.call())
|
||||
.isEqualTo("com.example.SpringBootExtensionMainClass");
|
||||
assertThat(this.convention.call()).isEqualTo("com.example.SpringBootExtensionMainClass");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -36,8 +36,7 @@ public class MavenPluginActionIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void clearsConf2ScopeMappingsOfUploadBootArchivesTask() {
|
||||
assertThat(this.gradleBuild.build("conf2ScopeMappings").getOutput())
|
||||
.contains("Conf2ScopeMappings = 0");
|
||||
assertThat(this.gradleBuild.build("conf2ScopeMappings").getOutput()).contains("Conf2ScopeMappings = 0");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ public class SpringBootPluginIntegrationTests {
|
||||
@Test
|
||||
public void failFastWithVersionOfGradleLowerThanRequired() {
|
||||
BuildResult result = this.gradleBuild.gradleVersion("4.9").buildAndFail();
|
||||
assertThat(result.getOutput()).contains("Spring Boot plugin requires Gradle 4.10"
|
||||
+ " or later. The current version is Gradle 4.9");
|
||||
assertThat(result.getOutput())
|
||||
.contains("Spring Boot plugin requires Gradle 4.10" + " or later. The current version is Gradle 4.9");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,19 +56,17 @@ public class SpringBootPluginIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unresolvedDependenciesAreAnalyzedWhenDependencyResolutionFails()
|
||||
throws IOException {
|
||||
public void unresolvedDependenciesAreAnalyzedWhenDependencyResolutionFails() throws IOException {
|
||||
createMinimalMainSource();
|
||||
BuildResult result = this.gradleBuild.buildAndFail("compileJava");
|
||||
assertThat(result.getOutput()).contains(
|
||||
"During the build, one or more dependencies that were declared without a"
|
||||
assertThat(result.getOutput())
|
||||
.contains("During the build, one or more dependencies that were declared without a"
|
||||
+ " version failed to resolve:")
|
||||
.contains(" org.springframework.boot:spring-boot-starter:");
|
||||
}
|
||||
|
||||
private void createMinimalMainSource() throws IOException {
|
||||
File examplePackage = new File(this.gradleBuild.getProjectDir(),
|
||||
"src/main/java/com/example");
|
||||
File examplePackage = new File(this.gradleBuild.getProjectDir(), "src/main/java/com/example");
|
||||
examplePackage.mkdirs();
|
||||
new File(examplePackage, "Application.java").createNewFile();
|
||||
}
|
||||
|
||||
@@ -46,9 +46,8 @@ public class WarPluginActionIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void applyingWarPluginCreatesBootWarTask() {
|
||||
assertThat(this.gradleBuild
|
||||
.build("taskExists", "-PtaskName=bootWar", "-PapplyWarPlugin")
|
||||
.getOutput()).contains("bootWar exists = true");
|
||||
assertThat(this.gradleBuild.build("taskExists", "-PtaskName=bootWar", "-PapplyWarPlugin").getOutput())
|
||||
.contains("bootWar exists = true");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
@@ -66,16 +65,14 @@ public class WarPluginActionIntegrationTests {
|
||||
File buildLibs = new File(this.gradleBuild.getProjectDir(), "build/libs");
|
||||
assertThat(buildLibs.listFiles()).containsExactlyInAnyOrder(
|
||||
new File(buildLibs, this.gradleBuild.getProjectDir().getName() + ".war"),
|
||||
new File(buildLibs,
|
||||
this.gradleBuild.getProjectDir().getName() + "-boot.war"));
|
||||
new File(buildLibs, this.gradleBuild.getProjectDir().getName() + "-boot.war"));
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void errorMessageIsHelpfulWhenMainClassCannotBeResolved() {
|
||||
BuildResult result = this.gradleBuild.buildAndFail("build", "-PapplyWarPlugin");
|
||||
assertThat(result.task(":bootWar").getOutcome()).isEqualTo(TaskOutcome.FAILED);
|
||||
assertThat(result.getOutput()).contains(
|
||||
"Main class name has not been configured and it could not be resolved");
|
||||
assertThat(result.getOutput()).contains("Main class name has not been configured and it could not be resolved");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,21 +46,18 @@ public class BuildInfoIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void defaultValues() {
|
||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
Properties buildInfoProperties = buildInfoProperties();
|
||||
assertThat(buildInfoProperties).containsKey("build.time");
|
||||
assertThat(buildInfoProperties).containsEntry("build.artifact", "unspecified");
|
||||
assertThat(buildInfoProperties).containsEntry("build.group", "");
|
||||
assertThat(buildInfoProperties).containsEntry("build.name",
|
||||
this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(buildInfoProperties).containsEntry("build.name", this.gradleBuild.getProjectDir().getName());
|
||||
assertThat(buildInfoProperties).containsEntry("build.version", "unspecified");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void basicExecution() {
|
||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
Properties buildInfoProperties = buildInfoProperties();
|
||||
assertThat(buildInfoProperties).containsKey("build.time");
|
||||
assertThat(buildInfoProperties).containsEntry("build.artifact", "foo");
|
||||
@@ -72,49 +69,43 @@ public class BuildInfoIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void notUpToDateWhenExecutedTwiceAsTimeChanges() {
|
||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("buildInfo").task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void upToDateWhenExecutedTwiceWithFixedTime() {
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
|
||||
.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void notUpToDateWhenExecutedTwiceWithFixedTimeAndChangedProjectVersion() {
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
BuildResult result = this.gradleBuild.build("buildInfo", "-PnullTime",
|
||||
"-PprojectVersion=0.2.0");
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
BuildResult result = this.gradleBuild.build("buildInfo", "-PnullTime", "-PprojectVersion=0.2.0");
|
||||
assertThat(result.task(":buildInfo").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void reproducibleOutputWithFixedTime()
|
||||
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure,
|
||||
IOException, InterruptedException {
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
File buildInfoProperties = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/build-info.properties");
|
||||
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure, IOException, InterruptedException {
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
File buildInfoProperties = new File(this.gradleBuild.getProjectDir(), "build/build-info.properties");
|
||||
String firstHash = FileUtils.sha1Hash(buildInfoProperties);
|
||||
assertThat(buildInfoProperties.delete()).isTrue();
|
||||
Thread.sleep(1500);
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo")
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("buildInfo", "-PnullTime").task(":buildInfo").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
String secondHash = FileUtils.sha1Hash(buildInfoProperties);
|
||||
assertThat(firstHash).isEqualTo(secondHash);
|
||||
}
|
||||
|
||||
private Properties buildInfoProperties() {
|
||||
File file = new File(this.gradleBuild.getProjectDir(),
|
||||
"build/build-info.properties");
|
||||
File file = new File(this.gradleBuild.getProjectDir(), "build/build-info.properties");
|
||||
assertThat(file).isFile();
|
||||
Properties properties = new Properties();
|
||||
try (FileReader reader = new FileReader(file)) {
|
||||
|
||||
@@ -111,8 +111,7 @@ public class BuildInfoTests {
|
||||
Instant now = Instant.now();
|
||||
BuildInfo task = createTask(createProject("test"));
|
||||
task.getProperties().setTime(now);
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.time",
|
||||
DateTimeFormatter.ISO_INSTANT.format(now));
|
||||
assertThat(buildInfoProperties(task)).containsEntry("build.time", DateTimeFormatter.ISO_INSTANT.format(now));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,8 +125,7 @@ public class BuildInfoTests {
|
||||
|
||||
private Project createProject(String projectName) {
|
||||
File projectDir = new File(this.temp, projectName);
|
||||
return ProjectBuilder.builder().withProjectDir(projectDir).withName(projectName)
|
||||
.build();
|
||||
return ProjectBuilder.builder().withProjectDir(projectDir).withName(projectName).build();
|
||||
}
|
||||
|
||||
private BuildInfo createTask(Project project) {
|
||||
@@ -136,8 +134,7 @@ public class BuildInfoTests {
|
||||
|
||||
private Properties buildInfoProperties(BuildInfo task) {
|
||||
task.generateBuildProperties();
|
||||
return buildInfoProperties(
|
||||
new File(task.getDestinationDir(), "build-info.properties"));
|
||||
return buildInfoProperties(new File(task.getDestinationDir(), "build-info.properties"));
|
||||
}
|
||||
|
||||
private Properties buildInfoProperties(File file) {
|
||||
|
||||
@@ -49,80 +49,72 @@ public abstract class AbstractBootArchiveIntegrationTests {
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void basicBuild() throws InvalidRunnerConfigurationException,
|
||||
UnexpectedBuildFailure, IOException {
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
public void basicBuild() throws InvalidRunnerConfigurationException, UnexpectedBuildFailure, IOException {
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void reproducibleArchive() throws InvalidRunnerConfigurationException,
|
||||
UnexpectedBuildFailure, IOException, InterruptedException {
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
File jar = new File(this.gradleBuild.getProjectDir(), "build/libs")
|
||||
.listFiles()[0];
|
||||
public void reproducibleArchive()
|
||||
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure, IOException, InterruptedException {
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
File jar = new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0];
|
||||
String firstHash = FileUtils.sha1Hash(jar);
|
||||
Thread.sleep(1500);
|
||||
assertThat(this.gradleBuild.build("clean", this.taskName)
|
||||
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("clean", this.taskName).task(":" + this.taskName).getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
String secondHash = FileUtils.sha1Hash(jar);
|
||||
assertThat(firstHash).isEqualTo(secondHash);
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void upToDateWhenBuiltTwice() throws InvalidRunnerConfigurationException,
|
||||
UnexpectedBuildFailure, IOException {
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
public void upToDateWhenBuiltTwice()
|
||||
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure, IOException {
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
|
||||
.isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void upToDateWhenBuiltTwiceWithLaunchScriptIncluded()
|
||||
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure,
|
||||
IOException {
|
||||
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName)
|
||||
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName)
|
||||
.task(":" + this.taskName).getOutcome())
|
||||
.isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
throws InvalidRunnerConfigurationException, UnexpectedBuildFailure, IOException {
|
||||
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
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);
|
||||
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName)
|
||||
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
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);
|
||||
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", this.taskName)
|
||||
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void notUpToDateWhenLaunchScriptPropertyChanges() {
|
||||
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true",
|
||||
"-PlaunchScriptProperty=foo", this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true",
|
||||
"-PlaunchScriptProperty=bar", this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", "-PlaunchScriptProperty=foo", this.taskName)
|
||||
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build("-PincludeLaunchScript=true", "-PlaunchScriptProperty=bar", this.taskName)
|
||||
.task(":" + this.taskName).getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void applicationPluginMainClassNameIsUsed() throws IOException {
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
try (JarFile jarFile = new JarFile(
|
||||
new File(this.gradleBuild.getProjectDir(), "build/libs")
|
||||
.listFiles()[0])) {
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
try (JarFile jarFile = new JarFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) {
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
|
||||
.isEqualTo("com.example.CustomMain");
|
||||
}
|
||||
@@ -130,11 +122,9 @@ public abstract class AbstractBootArchiveIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void springBootExtensionMainClassNameIsUsed() throws IOException {
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
try (JarFile jarFile = new JarFile(
|
||||
new File(this.gradleBuild.getProjectDir(), "build/libs")
|
||||
.listFiles()[0])) {
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
try (JarFile jarFile = new JarFile(new File(this.gradleBuild.getProjectDir(), "build/libs").listFiles()[0])) {
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
|
||||
.isEqualTo("com.example.CustomMain");
|
||||
}
|
||||
@@ -142,8 +132,8 @@ public abstract class AbstractBootArchiveIntegrationTests {
|
||||
|
||||
@TestTemplate
|
||||
public void duplicatesAreHandledGracefully() throws IOException {
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName)
|
||||
.getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(this.gradleBuild.build(this.taskName).task(":" + this.taskName).getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,8 +72,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
|
||||
private T task;
|
||||
|
||||
protected AbstractBootArchiveTests(Class<T> taskClass, String launcherClass,
|
||||
String libPath, String classesPath) {
|
||||
protected AbstractBootArchiveTests(Class<T> taskClass, String launcherClass, String libPath, String classesPath) {
|
||||
this.taskClass = taskClass;
|
||||
this.launcherClass = launcherClass;
|
||||
this.libPath = libPath;
|
||||
@@ -86,10 +85,8 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
File projectDir = new File(this.temp, "project");
|
||||
projectDir.mkdirs();
|
||||
this.project = ProjectBuilder.builder().withProjectDir(projectDir).build();
|
||||
this.project
|
||||
.setDescription("Test project for " + this.taskClass.getSimpleName());
|
||||
this.task = configure(
|
||||
this.project.getTasks().create("testArchive", this.taskClass));
|
||||
this.project.setDescription("Test project for " + this.taskClass.getSimpleName());
|
||||
this.task = configure(this.project.getTasks().create("testArchive", this.taskClass));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
@@ -102,17 +99,12 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
executeTask();
|
||||
assertThat(this.task.getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class"))
|
||||
.isEqualTo(this.launcherClass);
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
|
||||
.isEqualTo("com.example.Main");
|
||||
assertThat(jarFile.getManifest().getMainAttributes()
|
||||
.getValue("Spring-Boot-Classes")).isEqualTo(this.classesPath);
|
||||
assertThat(
|
||||
jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Lib"))
|
||||
.isEqualTo(this.libPath);
|
||||
assertThat(jarFile.getManifest().getMainAttributes()
|
||||
.getValue("Spring-Boot-Version")).isNotNull();
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class")).isEqualTo(this.launcherClass);
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class")).isEqualTo("com.example.Main");
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Classes"))
|
||||
.isEqualTo(this.classesPath);
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Lib")).isEqualTo(this.libPath);
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Spring-Boot-Version")).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,16 +123,13 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
public void classpathFoldersArePackagedBeneathClassesPath() throws IOException {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
File classpathFolder = new File(this.temp, "classes");
|
||||
File applicationClass = new File(classpathFolder,
|
||||
"com/example/Application.class");
|
||||
File applicationClass = new File(classpathFolder, "com/example/Application.class");
|
||||
applicationClass.getParentFile().mkdirs();
|
||||
applicationClass.createNewFile();
|
||||
this.task.classpath(classpathFolder);
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(
|
||||
jarFile.getEntry(this.classesPath + "com/example/Application.class"))
|
||||
.isNotNull();
|
||||
assertThat(jarFile.getEntry(this.classesPath + "com/example/Application.class")).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,20 +140,16 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
File moduleInfoClass = new File(classpathFolder, "module-info.class");
|
||||
moduleInfoClass.getParentFile().mkdirs();
|
||||
moduleInfoClass.createNewFile();
|
||||
File applicationClass = new File(classpathFolder,
|
||||
"com/example/Application.class");
|
||||
File applicationClass = new File(classpathFolder, "com/example/Application.class");
|
||||
applicationClass.getParentFile().mkdirs();
|
||||
applicationClass.createNewFile();
|
||||
this.task.classpath(classpathFolder);
|
||||
this.task.execute();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(
|
||||
jarFile.getEntry(this.classesPath + "com/example/Application.class"))
|
||||
.isNotNull();
|
||||
assertThat(jarFile.getEntry(this.classesPath + "com/example/Application.class")).isNotNull();
|
||||
assertThat(jarFile.getEntry("com/example/Application.class")).isNull();
|
||||
assertThat(jarFile.getEntry("module-info.class")).isNotNull();
|
||||
assertThat(jarFile.getEntry(this.classesPath + "/module-info.class"))
|
||||
.isNull();
|
||||
assertThat(jarFile.getEntry(this.classesPath + "/module-info.class")).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,24 +192,18 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(jarFile.getEntry(
|
||||
"org/springframework/boot/loader/LaunchedURLClassLoader.class"))
|
||||
.isNotNull();
|
||||
assertThat(jarFile.getEntry("org/springframework/boot/loader/LaunchedURLClassLoader.class")).isNotNull();
|
||||
assertThat(jarFile.getEntry("org/springframework/boot/loader/")).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loaderIsWrittenToTheRootOfTheJarWhenUsingThePropertiesLauncher()
|
||||
throws IOException {
|
||||
public void loaderIsWrittenToTheRootOfTheJarWhenUsingThePropertiesLauncher() throws IOException {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
executeTask();
|
||||
this.task.getManifest().getAttributes().put("Main-Class",
|
||||
"org.springframework.boot.loader.PropertiesLauncher");
|
||||
this.task.getManifest().getAttributes().put("Main-Class", "org.springframework.boot.loader.PropertiesLauncher");
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(jarFile.getEntry(
|
||||
"org/springframework/boot/loader/LaunchedURLClassLoader.class"))
|
||||
.isNotNull();
|
||||
assertThat(jarFile.getEntry("org/springframework/boot/loader/LaunchedURLClassLoader.class")).isNotNull();
|
||||
assertThat(jarFile.getEntry("org/springframework/boot/loader/")).isNotNull();
|
||||
}
|
||||
}
|
||||
@@ -236,8 +215,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.requiresUnpack("**/one.jar");
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(jarFile.getEntry(this.libPath + "one.jar").getComment())
|
||||
.startsWith("UNPACK:");
|
||||
assertThat(jarFile.getEntry(this.libPath + "one.jar").getComment()).startsWith("UNPACK:");
|
||||
assertThat(jarFile.getEntry(this.libPath + "two.jar").getComment()).isNull();
|
||||
}
|
||||
}
|
||||
@@ -249,8 +227,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.requiresUnpack((element) -> element.getName().endsWith("two.jar"));
|
||||
executeTask();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(jarFile.getEntry(this.libPath + "two.jar").getComment())
|
||||
.startsWith("UNPACK:");
|
||||
assertThat(jarFile.getEntry(this.libPath + "two.jar").getComment()).startsWith("UNPACK:");
|
||||
assertThat(jarFile.getEntry(this.libPath + "one.jar").getComment()).isNull();
|
||||
}
|
||||
}
|
||||
@@ -267,8 +244,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
assertThat(Files.readAllBytes(this.task.getArchivePath().toPath()))
|
||||
.startsWith(new DefaultLaunchScript(null, properties).toByteArray());
|
||||
try {
|
||||
Set<PosixFilePermission> permissions = Files
|
||||
.getPosixFilePermissions(this.task.getArchivePath().toPath());
|
||||
Set<PosixFilePermission> permissions = Files.getPosixFilePermissions(this.task.getArchivePath().toPath());
|
||||
assertThat(permissions).contains(PosixFilePermission.OWNER_EXECUTE);
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
@@ -280,12 +256,10 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
public void customLaunchScriptCanBePrepended() throws IOException {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
File customScript = new File(this.temp, "custom.script");
|
||||
Files.write(customScript.toPath(), Arrays.asList("custom script"),
|
||||
StandardOpenOption.CREATE);
|
||||
Files.write(customScript.toPath(), Arrays.asList("custom script"), StandardOpenOption.CREATE);
|
||||
this.task.launchScript((configuration) -> configuration.setScript(customScript));
|
||||
executeTask();
|
||||
assertThat(Files.readAllBytes(this.task.getArchivePath().toPath()))
|
||||
.startsWith("custom script".getBytes());
|
||||
assertThat(Files.readAllBytes(this.task.getArchivePath().toPath())).startsWith("custom script".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -293,46 +267,38 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.launchScript((configuration) -> {
|
||||
configuration.getProperties().put("initInfoProvides", "provides");
|
||||
configuration.getProperties().put("initInfoShortDescription",
|
||||
"short description");
|
||||
configuration.getProperties().put("initInfoShortDescription", "short description");
|
||||
configuration.getProperties().put("initInfoDescription", "description");
|
||||
});
|
||||
executeTask();
|
||||
byte[] bytes = Files.readAllBytes(this.task.getArchivePath().toPath());
|
||||
assertThat(bytes).containsSequence("Provides: provides".getBytes());
|
||||
assertThat(bytes)
|
||||
.containsSequence("Short-Description: short description".getBytes());
|
||||
assertThat(bytes).containsSequence("Short-Description: short description".getBytes());
|
||||
assertThat(bytes).containsSequence("Description: description".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customMainClassInTheManifestIsHonored() throws IOException {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.getManifest().getAttributes().put("Main-Class",
|
||||
"com.example.CustomLauncher");
|
||||
this.task.getManifest().getAttributes().put("Main-Class", "com.example.CustomLauncher");
|
||||
executeTask();
|
||||
assertThat(this.task.getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class"))
|
||||
.isEqualTo("com.example.CustomLauncher");
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
|
||||
.isEqualTo("com.example.Main");
|
||||
assertThat(jarFile.getEntry(
|
||||
"org/springframework/boot/loader/LaunchedURLClassLoader.class"))
|
||||
.isNull();
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class")).isEqualTo("com.example.Main");
|
||||
assertThat(jarFile.getEntry("org/springframework/boot/loader/LaunchedURLClassLoader.class")).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customStartClassInTheManifestIsHonored() throws IOException {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.getManifest().getAttributes().put("Start-Class",
|
||||
"com.example.CustomMain");
|
||||
this.task.getManifest().getAttributes().put("Start-Class", "com.example.CustomMain");
|
||||
executeTask();
|
||||
assertThat(this.task.getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class"))
|
||||
.isEqualTo(this.launcherClass);
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Main-Class")).isEqualTo(this.launcherClass);
|
||||
assertThat(jarFile.getManifest().getMainAttributes().getValue("Start-Class"))
|
||||
.isEqualTo("com.example.CustomMain");
|
||||
}
|
||||
@@ -348,8 +314,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
Enumeration<JarEntry> entries = jarFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
assertThat(entry.getTime())
|
||||
.isEqualTo(BootZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES);
|
||||
assertThat(entry.getTime()).isEqualTo(BootZipCopyAction.CONSTANT_TIME_FOR_ZIP_ENTRIES);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -357,8 +322,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
@Test
|
||||
public void reproducibleOrderingCanBeEnabled() throws IOException {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
this.task.from(newFile("bravo.txt"), newFile("alpha.txt"),
|
||||
newFile("charlie.txt"));
|
||||
this.task.from(newFile("bravo.txt"), newFile("alpha.txt"), newFile("charlie.txt"));
|
||||
this.task.setReproducibleFileOrder(true);
|
||||
executeTask();
|
||||
assertThat(this.task.getArchivePath()).exists();
|
||||
@@ -382,8 +346,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
executeTask();
|
||||
assertThat(this.task.getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar"))
|
||||
.isNull();
|
||||
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar")).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,8 +358,7 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
executeTask();
|
||||
assertThat(this.task.getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(this.task.getArchivePath())) {
|
||||
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar"))
|
||||
.isNotNull();
|
||||
assertThat(jarFile.getEntry(this.libPath + "spring-boot-devtools-0.1.2.jar")).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -422,23 +384,19 @@ public abstract class AbstractBootArchiveTests<T extends Jar & BootArchive> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loaderIsWrittenFirstThenApplicationClassesThenLibraries()
|
||||
throws IOException {
|
||||
public void loaderIsWrittenFirstThenApplicationClassesThenLibraries() throws IOException {
|
||||
this.task.setMainClassName("com.example.Main");
|
||||
File classpathFolder = new File(this.temp, "classes");
|
||||
File applicationClass = new File(classpathFolder,
|
||||
"com/example/Application.class");
|
||||
File applicationClass = new File(classpathFolder, "com/example/Application.class");
|
||||
applicationClass.getParentFile().mkdirs();
|
||||
applicationClass.createNewFile();
|
||||
this.task.classpath(classpathFolder, jarFile("first-library.jar"),
|
||||
jarFile("second-library.jar"), jarFile("third-library.jar"));
|
||||
this.task.classpath(classpathFolder, jarFile("first-library.jar"), jarFile("second-library.jar"),
|
||||
jarFile("third-library.jar"));
|
||||
this.task.requiresUnpack("second-library.jar");
|
||||
executeTask();
|
||||
assertThat(getEntryNames(this.task.getArchivePath())).containsSubsequence(
|
||||
"org/springframework/boot/loader/",
|
||||
this.classesPath + "com/example/Application.class",
|
||||
this.libPath + "first-library.jar", this.libPath + "second-library.jar",
|
||||
this.libPath + "third-library.jar");
|
||||
assertThat(getEntryNames(this.task.getArchivePath())).containsSubsequence("org/springframework/boot/loader/",
|
||||
this.classesPath + "com/example/Application.class", this.libPath + "first-library.jar",
|
||||
this.libPath + "second-library.jar", this.libPath + "third-library.jar");
|
||||
}
|
||||
|
||||
protected File jarFile(String name) throws IOException {
|
||||
|
||||
@@ -32,16 +32,14 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class BootJarTests extends AbstractBootArchiveTests<BootJar> {
|
||||
|
||||
public BootJarTests() {
|
||||
super(BootJar.class, "org.springframework.boot.loader.JarLauncher",
|
||||
"BOOT-INF/lib/", "BOOT-INF/classes/");
|
||||
super(BootJar.class, "org.springframework.boot.loader.JarLauncher", "BOOT-INF/lib/", "BOOT-INF/classes/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentCanBeAddedToBootInfUsingCopySpecFromGetter() throws IOException {
|
||||
BootJar bootJar = getTask();
|
||||
bootJar.setMainClassName("com.example.Application");
|
||||
bootJar.getBootInf().into("test")
|
||||
.from(new File("build.gradle").getAbsolutePath());
|
||||
bootJar.getBootInf().into("test").from(new File("build.gradle").getAbsolutePath());
|
||||
bootJar.copy();
|
||||
try (JarFile jarFile = new JarFile(bootJar.getArchivePath())) {
|
||||
assertThat(jarFile.getJarEntry("BOOT-INF/test/build.gradle")).isNotNull();
|
||||
@@ -52,8 +50,7 @@ public class BootJarTests extends AbstractBootArchiveTests<BootJar> {
|
||||
public void contentCanBeAddedToBootInfUsingCopySpecAction() throws IOException {
|
||||
BootJar bootJar = getTask();
|
||||
bootJar.setMainClassName("com.example.Application");
|
||||
bootJar.bootInf((copySpec) -> copySpec.into("test")
|
||||
.from(new File("build.gradle").getAbsolutePath()));
|
||||
bootJar.bootInf((copySpec) -> copySpec.into("test").from(new File("build.gradle").getAbsolutePath()));
|
||||
bootJar.copy();
|
||||
try (JarFile jarFile = new JarFile(bootJar.getArchivePath())) {
|
||||
assertThat(jarFile.getJarEntry("BOOT-INF/test/build.gradle")).isNotNull();
|
||||
|
||||
@@ -32,8 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
|
||||
public BootWarTests() {
|
||||
super(BootWar.class, "org.springframework.boot.loader.WarLauncher",
|
||||
"WEB-INF/lib/", "WEB-INF/classes/");
|
||||
super(BootWar.class, "org.springframework.boot.loader.WarLauncher", "WEB-INF/lib/", "WEB-INF/classes/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,37 +71,30 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void devtoolsJarIsExcludedByDefaultWhenItsOnTheProvidedClasspath()
|
||||
throws IOException {
|
||||
public void devtoolsJarIsExcludedByDefaultWhenItsOnTheProvidedClasspath() throws IOException {
|
||||
getTask().setMainClassName("com.example.Main");
|
||||
getTask().providedClasspath(newFile("spring-boot-devtools-0.1.2.jar"));
|
||||
executeTask();
|
||||
assertThat(getTask().getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
|
||||
assertThat(jarFile
|
||||
.getEntry("WEB-INF/lib-provided/spring-boot-devtools-0.1.2.jar"))
|
||||
.isNull();
|
||||
assertThat(jarFile.getEntry("WEB-INF/lib-provided/spring-boot-devtools-0.1.2.jar")).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void devtoolsJarCanBeIncludedWhenItsOnTheProvidedClasspath()
|
||||
throws IOException {
|
||||
public void devtoolsJarCanBeIncludedWhenItsOnTheProvidedClasspath() throws IOException {
|
||||
getTask().setMainClassName("com.example.Main");
|
||||
getTask().providedClasspath(jarFile("spring-boot-devtools-0.1.2.jar"));
|
||||
getTask().setExcludeDevtools(false);
|
||||
executeTask();
|
||||
assertThat(getTask().getArchivePath()).exists();
|
||||
try (JarFile jarFile = new JarFile(getTask().getArchivePath())) {
|
||||
assertThat(jarFile
|
||||
.getEntry("WEB-INF/lib-provided/spring-boot-devtools-0.1.2.jar"))
|
||||
.isNotNull();
|
||||
assertThat(jarFile.getEntry("WEB-INF/lib-provided/spring-boot-devtools-0.1.2.jar")).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webappResourcesInDirectoriesThatOverlapWithLoaderCanBePackaged()
|
||||
throws IOException {
|
||||
public void webappResourcesInDirectoriesThatOverlapWithLoaderCanBePackaged() throws IOException {
|
||||
File webappFolder = new File(this.temp, "src/main/webapp");
|
||||
webappFolder.mkdirs();
|
||||
File orgFolder = new File(webappFolder, "org");
|
||||
@@ -124,8 +116,8 @@ public class BootWarTests extends AbstractBootArchiveTests<BootWar> {
|
||||
getTask().classpath(jarFile("library.jar"));
|
||||
getTask().providedClasspath(jarFile("provided-library.jar"));
|
||||
executeTask();
|
||||
assertThat(getEntryNames(getTask().getArchivePath())).containsSubsequence(
|
||||
"WEB-INF/lib/library.jar", "WEB-INF/lib-provided/provided-library.jar");
|
||||
assertThat(getEntryNames(getTask().getArchivePath())).containsSubsequence("WEB-INF/lib/library.jar",
|
||||
"WEB-INF/lib-provided/provided-library.jar");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,50 +44,50 @@ public class LaunchScriptConfigurationTests {
|
||||
@Test
|
||||
public void initInfoProvidesUsesArchiveBaseNameByDefault() {
|
||||
given(this.task.getBaseName()).willReturn("base-name");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
|
||||
.containsEntry("initInfoProvides", "base-name");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoProvides",
|
||||
"base-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initInfoShortDescriptionUsesDescriptionByDefault() {
|
||||
given(this.project.getDescription()).willReturn("Project description");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
|
||||
.containsEntry("initInfoShortDescription", "Project description");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoShortDescription",
|
||||
"Project description");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initInfoShortDescriptionUsesArchiveBaseNameWhenDescriptionIsNull() {
|
||||
given(this.task.getBaseName()).willReturn("base-name");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
|
||||
.containsEntry("initInfoShortDescription", "base-name");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoShortDescription",
|
||||
"base-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initInfoShortDescriptionUsesSingleLineVersionOfMultiLineProjectDescription() {
|
||||
given(this.project.getDescription()).willReturn("Project\ndescription");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
|
||||
.containsEntry("initInfoShortDescription", "Project description");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoShortDescription",
|
||||
"Project description");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initInfoDescriptionUsesArchiveBaseNameWhenDescriptionIsNull() {
|
||||
given(this.task.getBaseName()).willReturn("base-name");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
|
||||
.containsEntry("initInfoDescription", "base-name");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoDescription",
|
||||
"base-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initInfoDescriptionUsesProjectDescriptionByDefault() {
|
||||
given(this.project.getDescription()).willReturn("Project description");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
|
||||
.containsEntry("initInfoDescription", "Project description");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoDescription",
|
||||
"Project description");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initInfoDescriptionUsesCorrectlyFormattedMultiLineProjectDescription() {
|
||||
given(this.project.getDescription()).willReturn("The\nproject\ndescription");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties())
|
||||
.containsEntry("initInfoDescription", "The\n# project\n# description");
|
||||
assertThat(new LaunchScriptConfiguration(this.task).getProperties()).containsEntry("initInfoDescription",
|
||||
"The\n# project\n# description");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,23 +43,20 @@ public class MavenIntegrationTests {
|
||||
@TestTemplate
|
||||
public void bootJarCanBeUploaded() throws FileNotFoundException, IOException {
|
||||
BuildResult result = this.gradleBuild.build("uploadBootArchives");
|
||||
assertThat(result.task(":uploadBootArchives").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.task(":uploadBootArchives").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(artifactWithSuffix("jar")).isFile();
|
||||
assertThat(artifactWithSuffix("pom")).is(pomWith().groupId("com.example")
|
||||
.artifactId(this.gradleBuild.getProjectDir().getName()).version("1.0")
|
||||
.noPackaging().noDependencies());
|
||||
.artifactId(this.gradleBuild.getProjectDir().getName()).version("1.0").noPackaging().noDependencies());
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void bootWarCanBeUploaded() throws IOException {
|
||||
BuildResult result = this.gradleBuild.build("uploadBootArchives");
|
||||
assertThat(result.task(":uploadBootArchives").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.task(":uploadBootArchives").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(artifactWithSuffix("war")).isFile();
|
||||
assertThat(artifactWithSuffix("pom")).is(pomWith().groupId("com.example")
|
||||
.artifactId(this.gradleBuild.getProjectDir().getName()).version("1.0")
|
||||
.packaging("war").noDependencies());
|
||||
assertThat(artifactWithSuffix("pom"))
|
||||
.is(pomWith().groupId("com.example").artifactId(this.gradleBuild.getProjectDir().getName())
|
||||
.version("1.0").packaging("war").noDependencies());
|
||||
}
|
||||
|
||||
private File artifactWithSuffix(String suffix) {
|
||||
|
||||
@@ -47,8 +47,7 @@ public class MavenPublishingIntegrationTests {
|
||||
assertThat(result.task(":publish").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(artifactWithSuffix("jar")).isFile();
|
||||
assertThat(artifactWithSuffix("pom")).is(pomWith().groupId("com.example")
|
||||
.artifactId(this.gradleBuild.getProjectDir().getName()).version("1.0")
|
||||
.noPackaging().noDependencies());
|
||||
.artifactId(this.gradleBuild.getProjectDir().getName()).version("1.0").noPackaging().noDependencies());
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
@@ -56,9 +55,9 @@ public class MavenPublishingIntegrationTests {
|
||||
BuildResult result = this.gradleBuild.build("publish");
|
||||
assertThat(result.task(":publish").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(artifactWithSuffix("war")).isFile();
|
||||
assertThat(artifactWithSuffix("pom")).is(pomWith().groupId("com.example")
|
||||
.artifactId(this.gradleBuild.getProjectDir().getName()).version("1.0")
|
||||
.packaging("war").noDependencies());
|
||||
assertThat(artifactWithSuffix("pom"))
|
||||
.is(pomWith().groupId("com.example").artifactId(this.gradleBuild.getProjectDir().getName())
|
||||
.version("1.0").packaging("war").noDependencies());
|
||||
}
|
||||
|
||||
private File artifactWithSuffix(String suffix) {
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,8 +44,8 @@ class PomCondition extends Condition<File> {
|
||||
}
|
||||
|
||||
private PomCondition(Set<String> expectedContents, Set<String> notExpectedContents) {
|
||||
super(new TextDescription("Pom file containing %s and not containing %s",
|
||||
expectedContents, notExpectedContents));
|
||||
super(new TextDescription("Pom file containing %s and not containing %s", expectedContents,
|
||||
notExpectedContents));
|
||||
this.expectedContents = expectedContents;
|
||||
this.notExpectedContents = notExpectedContents;
|
||||
}
|
||||
@@ -73,8 +73,8 @@ class PomCondition extends Condition<File> {
|
||||
|
||||
@Override
|
||||
public Description description() {
|
||||
return new TextDescription("Pom file containing %s and not containing %s",
|
||||
this.expectedContents, this.notExpectedContents);
|
||||
return new TextDescription("Pom file containing %s and not containing %s", this.expectedContents,
|
||||
this.notExpectedContents);
|
||||
}
|
||||
|
||||
PomCondition groupId(String groupId) {
|
||||
@@ -83,8 +83,7 @@ class PomCondition extends Condition<File> {
|
||||
}
|
||||
|
||||
PomCondition artifactId(String artifactId) {
|
||||
this.expectedContents
|
||||
.add(String.format("<artifactId>%s</artifactId>", artifactId));
|
||||
this.expectedContents.add(String.format("<artifactId>%s</artifactId>", artifactId));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,12 +46,9 @@ public class BootRunIntegrationTests {
|
||||
new File(this.gradleBuild.getProjectDir(), "src/main/resources").mkdirs();
|
||||
BuildResult result = this.gradleBuild.build("bootRun");
|
||||
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput())
|
||||
.contains("1. " + canonicalPathOf("build/classes/java/main"));
|
||||
assertThat(result.getOutput())
|
||||
.contains("2. " + canonicalPathOf("build/resources/main"));
|
||||
assertThat(result.getOutput())
|
||||
.doesNotContain(canonicalPathOf("src/main/resources"));
|
||||
assertThat(result.getOutput()).contains("1. " + canonicalPathOf("build/classes/java/main"));
|
||||
assertThat(result.getOutput()).contains("2. " + canonicalPathOf("build/resources/main"));
|
||||
assertThat(result.getOutput()).doesNotContain(canonicalPathOf("src/main/resources"));
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
@@ -59,40 +56,31 @@ public class BootRunIntegrationTests {
|
||||
copyClasspathApplication();
|
||||
BuildResult result = this.gradleBuild.build("bootRun");
|
||||
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput())
|
||||
.contains("1. " + canonicalPathOf("src/main/resources"));
|
||||
assertThat(result.getOutput())
|
||||
.contains("2. " + canonicalPathOf("build/classes/java/main"));
|
||||
assertThat(result.getOutput())
|
||||
.doesNotContain(canonicalPathOf("build/resources/main"));
|
||||
assertThat(result.getOutput()).contains("1. " + canonicalPathOf("src/main/resources"));
|
||||
assertThat(result.getOutput()).contains("2. " + canonicalPathOf("build/classes/java/main"));
|
||||
assertThat(result.getOutput()).doesNotContain(canonicalPathOf("build/resources/main"));
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void springBootExtensionMainClassNameIsUsed() throws IOException {
|
||||
BuildResult result = this.gradleBuild.build("echoMainClassName");
|
||||
assertThat(result.task(":echoMainClassName").getOutcome())
|
||||
.isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
assertThat(result.getOutput())
|
||||
.contains("Main class name = com.example.CustomMainClass");
|
||||
assertThat(result.task(":echoMainClassName").getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
assertThat(result.getOutput()).contains("Main class name = com.example.CustomMainClass");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void applicationPluginMainClassNameIsUsed() throws IOException {
|
||||
BuildResult result = this.gradleBuild.build("echoMainClassName");
|
||||
assertThat(result.task(":echoMainClassName").getOutcome())
|
||||
.isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
assertThat(result.getOutput())
|
||||
.contains("Main class name = com.example.CustomMainClass");
|
||||
assertThat(result.task(":echoMainClassName").getOutcome()).isEqualTo(TaskOutcome.UP_TO_DATE);
|
||||
assertThat(result.getOutput()).contains("Main class name = com.example.CustomMainClass");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
public void applicationPluginMainClassNameIsNotUsedWhenItIsNull() throws IOException {
|
||||
copyClasspathApplication();
|
||||
BuildResult result = this.gradleBuild.build("echoMainClassName");
|
||||
assertThat(result.task(":echoMainClassName").getOutcome())
|
||||
.isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).contains(
|
||||
"Main class name = com.example.classpath.BootRunClasspathApplication");
|
||||
assertThat(result.task(":echoMainClassName").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).contains("Main class name = com.example.classpath.BootRunClasspathApplication");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
@@ -100,8 +88,7 @@ public class BootRunIntegrationTests {
|
||||
copyJvmArgsApplication();
|
||||
BuildResult result = this.gradleBuild.build("bootRun");
|
||||
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).contains("1. -Xverify:none")
|
||||
.contains("2. -XX:TieredStopAtLevel=1");
|
||||
assertThat(result.getOutput()).contains("1. -Xverify:none").contains("2. -XX:TieredStopAtLevel=1");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
@@ -109,8 +96,7 @@ public class BootRunIntegrationTests {
|
||||
copyJvmArgsApplication();
|
||||
BuildResult result = this.gradleBuild.build("bootRun");
|
||||
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).doesNotContain("-Xverify:none")
|
||||
.doesNotContain("-XX:TieredStopAtLevel=1");
|
||||
assertThat(result.getOutput()).doesNotContain("-Xverify:none").doesNotContain("-XX:TieredStopAtLevel=1");
|
||||
}
|
||||
|
||||
@TestTemplate
|
||||
@@ -118,9 +104,8 @@ public class BootRunIntegrationTests {
|
||||
copyJvmArgsApplication();
|
||||
BuildResult result = this.gradleBuild.build("bootRun");
|
||||
assertThat(result.task(":bootRun").getOutcome()).isEqualTo(TaskOutcome.SUCCESS);
|
||||
assertThat(result.getOutput()).contains("1. -Dcom.bar=baz")
|
||||
.contains("2. -Dcom.foo=bar").contains("3. -Xverify:none")
|
||||
.contains("4. -XX:TieredStopAtLevel=1");
|
||||
assertThat(result.getOutput()).contains("1. -Dcom.bar=baz").contains("2. -Dcom.foo=bar")
|
||||
.contains("3. -Xverify:none").contains("4. -XX:TieredStopAtLevel=1");
|
||||
}
|
||||
|
||||
private void copyClasspathApplication() throws IOException {
|
||||
@@ -132,11 +117,9 @@ public class BootRunIntegrationTests {
|
||||
}
|
||||
|
||||
private void copyApplication(String name) throws IOException {
|
||||
File output = new File(this.gradleBuild.getProjectDir(),
|
||||
"src/main/java/com/example/" + name);
|
||||
File output = new File(this.gradleBuild.getProjectDir(), "src/main/java/com/example/" + name);
|
||||
output.mkdirs();
|
||||
FileSystemUtils.copyRecursively(new File("src/test/java/com/example/" + name),
|
||||
output);
|
||||
FileSystemUtils.copyRecursively(new File("src/test/java/com/example/" + name), output);
|
||||
}
|
||||
|
||||
private String canonicalPathOf(String path) throws IOException {
|
||||
|
||||
@@ -80,15 +80,11 @@ public class GradleBuild {
|
||||
}
|
||||
|
||||
private List<File> pluginClasspath() {
|
||||
return Arrays.asList(new File("bin"), new File("build/classes/java/main"),
|
||||
new File("build/resources/main"),
|
||||
new File(pathOfJarContaining(LaunchScript.class)),
|
||||
new File(pathOfJarContaining(ClassVisitor.class)),
|
||||
return Arrays.asList(new File("bin"), new File("build/classes/java/main"), new File("build/resources/main"),
|
||||
new File(pathOfJarContaining(LaunchScript.class)), new File(pathOfJarContaining(ClassVisitor.class)),
|
||||
new File(pathOfJarContaining(DependencyManagementPlugin.class)),
|
||||
new File(pathOfJarContaining(PropertiesKt.class)),
|
||||
new File(pathOfJarContaining(KotlinLogger.class)),
|
||||
new File(pathOfJarContaining(KotlinPlugin.class)),
|
||||
new File(pathOfJarContaining(KotlinProject.class)),
|
||||
new File(pathOfJarContaining(PropertiesKt.class)), new File(pathOfJarContaining(KotlinLogger.class)),
|
||||
new File(pathOfJarContaining(KotlinPlugin.class)), new File(pathOfJarContaining(KotlinProject.class)),
|
||||
new File(pathOfJarContaining(KotlinGradleSubplugin.class)),
|
||||
new File(pathOfJarContaining(ArchiveEntry.class)));
|
||||
}
|
||||
@@ -98,8 +94,7 @@ public class GradleBuild {
|
||||
}
|
||||
|
||||
public GradleBuild script(String script) {
|
||||
this.script = script.endsWith(this.dsl.getExtension()) ? script
|
||||
: script + this.dsl.getExtension();
|
||||
this.script = script.endsWith(this.dsl.getExtension()) ? script : script + this.dsl.getExtension();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -124,10 +119,8 @@ public class GradleBuild {
|
||||
public GradleRunner prepareRunner(String... arguments) throws IOException {
|
||||
String scriptContent = FileCopyUtils.copyToString(new FileReader(this.script))
|
||||
.replace("{version}", getBootVersion())
|
||||
.replace("{dependency-management-plugin-version}",
|
||||
getDependencyManagementPluginVersion());
|
||||
FileCopyUtils.copy(scriptContent, new FileWriter(
|
||||
new File(this.projectDir, "build" + this.dsl.getExtension())));
|
||||
.replace("{dependency-management-plugin-version}", getDependencyManagementPluginVersion());
|
||||
FileCopyUtils.copy(scriptContent, new FileWriter(new File(this.projectDir, "build" + this.dsl.getExtension())));
|
||||
FileSystemUtils.copyRecursively(new File("src/test/resources/repository"),
|
||||
new File(this.projectDir, "repository"));
|
||||
GradleRunner gradleRunner = GradleRunner.create().withProjectDir(this.projectDir)
|
||||
@@ -172,16 +165,13 @@ public class GradleBuild {
|
||||
|
||||
private static String getDependencyManagementPluginVersion() {
|
||||
try {
|
||||
URL location = DependencyManagementExtension.class.getProtectionDomain()
|
||||
.getCodeSource().getLocation();
|
||||
URL location = DependencyManagementExtension.class.getProtectionDomain().getCodeSource().getLocation();
|
||||
try (JarFile jar = new JarFile(new File(location.toURI()))) {
|
||||
return jar.getManifest().getMainAttributes()
|
||||
.getValue("Implementation-Version");
|
||||
return jar.getManifest().getMainAttributes().getValue("Implementation-Version");
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(
|
||||
"Failed to find dependency management plugin version", ex);
|
||||
throw new IllegalStateException("Failed to find dependency management plugin version", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
*/
|
||||
public class GradleBuildExtension implements BeforeEachCallback, AfterEachCallback {
|
||||
|
||||
private static final Pattern GRADLE_VERSION_PATTERN = Pattern
|
||||
.compile("\\[Gradle .+\\]");
|
||||
private static final Pattern GRADLE_VERSION_PATTERN = Pattern.compile("\\[Gradle .+\\]");
|
||||
|
||||
private Dsl dsl = Dsl.GROOVY;
|
||||
|
||||
@@ -51,8 +50,7 @@ public class GradleBuildExtension implements BeforeEachCallback, AfterEachCallba
|
||||
|
||||
private GradleBuild extractGradleBuild(ExtensionContext context) throws Exception {
|
||||
Object testInstance = context.getRequiredTestInstance();
|
||||
Field gradleBuildField = ReflectionUtils.findField(testInstance.getClass(),
|
||||
"gradleBuild");
|
||||
Field gradleBuildField = ReflectionUtils.findField(testInstance.getClass(), "gradleBuild");
|
||||
gradleBuildField.setAccessible(true);
|
||||
GradleBuild gradleBuild = (GradleBuild) gradleBuildField.get(testInstance);
|
||||
return gradleBuild;
|
||||
@@ -68,8 +66,7 @@ public class GradleBuildExtension implements BeforeEachCallback, AfterEachCallba
|
||||
|
||||
private URL getScriptForTestMethod(ExtensionContext context) {
|
||||
Class<?> testClass = context.getRequiredTestClass();
|
||||
String name = testClass.getSimpleName() + "-"
|
||||
+ removeGradleVersion(context.getRequiredTestMethod().getName())
|
||||
String name = testClass.getSimpleName() + "-" + removeGradleVersion(context.getRequiredTestMethod().getName())
|
||||
+ this.dsl.getExtension();
|
||||
return testClass.getResource(name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user