diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle index cba62a99b21..bd6ea262683 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/build.gradle @@ -1,29 +1,24 @@ plugins { id "java" id "org.springframework.boot.conventions" + id "org.springframework.boot.integration-test" } -description = "Spring Boot Server Tests" +description = "Spring Boot Server Integration Tests" configurations { testRepository } dependencies { - testImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) - testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) - testImplementation("com.samskivert:jmustache") - testImplementation("jakarta.servlet:jakarta.servlet-api") - testImplementation("org.apache.httpcomponents:httpasyncclient") - testImplementation("org.apache.maven.shared:maven-invoker:3.0.0") - testImplementation("org.awaitility:awaitility") - testImplementation("org.eclipse.jetty:jetty-webapp") { - exclude group: "javax.servlet", module: "javax-servlet-api" - } - testImplementation("org.springframework:spring-web") + intTestImplementation(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-test")) + intTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) + intTestImplementation("org.apache.httpcomponents:httpasyncclient") + intTestImplementation("org.awaitility:awaitility") + intTestImplementation("org.springframework:spring-web") testRepository(project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "mavenRepository")) - testRepository(project(path: ":spring-boot-project:spring-boot-tools:spring-boot-maven-plugin", configuration: "mavenRepository")) + testRepository(project(path: ":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin", configuration: "mavenRepository")) testRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter", configuration: "mavenRepository")) testRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-jetty", configuration: "mavenRepository")) testRepository(project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-json", configuration: "mavenRepository")) @@ -34,11 +29,6 @@ dependencies { testRuntimeOnly(project(":spring-boot-project:spring-boot-starters:spring-boot-starter-logging")) } -task prepareMavenBinaries(type: org.springframework.boot.build.mavenplugin.PrepareMavenBinaries) { - outputDir = file("${buildDir}/maven-binaries") - versions "3.6.2" -} - task syncTestRepository(type: Sync) { destinationDir = file("${buildDir}/test-repository") from { @@ -46,6 +36,28 @@ task syncTestRepository(type: Sync) { } } -test { - dependsOn prepareMavenBinaries, syncTestRepository +task syncAppSource(type: Sync) { + from "spring-boot-server-tests-app" + into "${buildDir}/spring-boot-server-tests-app" + filter { line -> + line.replace("id \"org.springframework.boot\"", "id \"org.springframework.boot\" version \"${project.version}\"") + } } + +task buildApps(type: GradleBuild) { + dependsOn syncAppSource, syncTestRepository + dir = "${buildDir}/spring-boot-server-tests-app" + startParameter.buildCacheEnabled = false + tasks = [ + "jettyBootJar", + "jettyBootWar", + "tomcatBootJar", + "tomcatBootWar", + "undertowBootJar", + "undertowBootWar" + ] +} + +intTest { + dependsOn buildApps +} \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/build.gradle b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/build.gradle new file mode 100644 index 00000000000..2b8a58f9478 --- /dev/null +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/build.gradle @@ -0,0 +1,78 @@ +import org.springframework.boot.gradle.tasks.bundling.BootJar +import org.springframework.boot.gradle.tasks.bundling.BootWar + +plugins { + id "java" + id "org.springframework.boot" + id "war" +} + +apply plugin: "io.spring.dependency-management" + +repositories { + maven { url "file:${rootDir}/../test-repository"} + mavenCentral() + maven { + url "https://repo.spring.io/milestone" + content { + excludeGroup "org.springframework.boot" + } + } + maven { + url "https://repo.spring.io/snapshot" + content { + excludeGroup "org.springframework.boot" + } + } +} + +configurations { + jetty + tomcat + undertow +} + +tasks.register("resourcesJar", Jar) { jar -> + def nested = project.resources.text.fromString("nested") + from(nested) { + into "META-INF/resources/" + rename (".*", "nested-meta-inf-resource.txt") + } + if (!isWindows()) { + def encodedName = project.resources.text.fromString("encoded-name") + from(encodedName) { + into "META-INF/resources/" + rename (".*", 'nested-reserved-!#\\$%&()*+,:=?@[]-meta-inf-resource.txt') + } + } + classifier = 'resources' +} + +dependencies { + compileOnly("org.eclipse.jetty:jetty-server") + + implementation("org.springframework.boot:spring-boot-starter") + implementation("org.springframework:spring-web") + + jetty("org.springframework.boot:spring-boot-starter-jetty") + jetty files(resourcesJar) + tomcat("org.springframework.boot:spring-boot-starter-tomcat") + tomcat files(resourcesJar) + undertow("org.springframework.boot:spring-boot-starter-undertow") + undertow files(resourcesJar) +} + +def boolean isWindows() { + return File.separatorChar == '\\'; +} + +["jetty", "tomcat", "undertow"].each { container -> + def configurer = { task -> + task.dependsOn resourcesJar + task.mainClass = "com.example.ResourceHandlingApplication" + task.classpath = sourceSets.main.runtimeClasspath.plus(configurations.getByName(container)) + task.classifier = container + } + tasks.register("${container}BootJar", BootJar, configurer) + tasks.register("${container}BootWar", BootWar, configurer) +} diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/settings.gradle b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/settings.gradle new file mode 100644 index 00000000000..236e1353729 --- /dev/null +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/settings.gradle @@ -0,0 +1,25 @@ +pluginManagement { + repositories { + maven { url "file:${rootDir}/../test-repository"} + mavenCentral() + maven { + url "https://repo.spring.io/milestone" + content { + excludeGroup "org.springframework.boot" + } + } + maven { + url "https://repo.spring.io/snapshot" + content { + excludeGroup "org.springframework.boot" + } + } + } + resolutionStrategy { + eachPlugin { + if (requested.id.id == "org.springframework.boot") { + useModule "org.springframework.boot:spring-boot-gradle-plugin:${requested.version}" + } + } + } +} \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/autoconfig/ExampleAutoConfiguration.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/java/com/autoconfig/ExampleAutoConfiguration.java similarity index 100% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/autoconfig/ExampleAutoConfiguration.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/java/com/autoconfig/ExampleAutoConfiguration.java diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/example/JettyServerCustomizerConfig.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/java/com/example/JettyServerCustomizerConfig.java similarity index 89% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/example/JettyServerCustomizerConfig.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/java/com/example/JettyServerCustomizerConfig.java index c7b028b957c..f927f9b410c 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/example/JettyServerCustomizerConfig.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/java/com/example/JettyServerCustomizerConfig.java @@ -18,6 +18,7 @@ package com.example; import org.eclipse.jetty.server.handler.ContextHandler; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -28,6 +29,7 @@ import org.springframework.context.annotation.Configuration; * * @author Madhura Bhave */ +@ConditionalOnClass(name = {"org.eclipse.jetty.server.handler.ContextHandler"}) @Configuration(proxyBeanMethods = false) public class JettyServerCustomizerConfig { diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/example/ResourceHandlingApplication.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/java/com/example/ResourceHandlingApplication.java similarity index 100% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/com/example/ResourceHandlingApplication.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/java/com/example/ResourceHandlingApplication.java diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/META-INF/spring.factories b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/resources/META-INF/spring.factories similarity index 100% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/META-INF/spring.factories rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/resources/META-INF/spring.factories diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/webapp/webapp-resource.txt b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/webapp/webapp-resource.txt new file mode 100644 index 00000000000..3036fbe727d --- /dev/null +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/spring-boot-server-tests-app/src/main/webapp/webapp-resource.txt @@ -0,0 +1 @@ +webapp resource \ No newline at end of file diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java similarity index 91% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java index 4683c0cb444..b87a2cf294f 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/AbstractApplicationLauncher.java @@ -41,7 +41,7 @@ import org.springframework.util.StringUtils; */ abstract class AbstractApplicationLauncher implements BeforeEachCallback { - private final ApplicationBuilder applicationBuilder; + private final Application application; private final BuildOutput buildOutput; @@ -49,8 +49,8 @@ abstract class AbstractApplicationLauncher implements BeforeEachCallback { private int httpPort; - protected AbstractApplicationLauncher(ApplicationBuilder applicationBuilder, BuildOutput buildOutput) { - this.applicationBuilder = applicationBuilder; + protected AbstractApplicationLauncher(Application application, BuildOutput buildOutput) { + this.application = application; this.buildOutput = buildOutput; } @@ -87,7 +87,8 @@ abstract class AbstractApplicationLauncher implements BeforeEachCallback { File workingDirectory = getWorkingDirectory(); File serverPortFile = new File(this.buildOutput.getRootLocation(), "server.port"); serverPortFile.delete(); - File archive = this.applicationBuilder.buildApplication(); + File archive = new File("build/spring-boot-server-tests-app/build/libs/spring-boot-server-tests-app-" + + this.application.getContainer() + "." + this.application.getPackaging()); List arguments = new ArrayList<>(); arguments.add(System.getProperty("java.home") + "/bin/java"); arguments.addAll(getArguments(archive, serverPortFile)); diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/Versions.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/Application.java similarity index 52% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/Versions.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/Application.java index c8ef23a467f..9260075b591 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/Versions.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -16,29 +16,35 @@ package org.springframework.boot.context.embedded; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Properties; +import java.io.File; /** - * Provides access to the current Boot version by referring to {@code gradle.properties}. + * An pre-built application that can be launched. * * @author Andy Wilkinson */ -final class Versions { +class Application { - private Versions() { + private final String packaging; + + private final String container; + + Application(String packaging, String container) { + this.packaging = packaging; + this.container = container; } - static String getBootVersion() { - Properties gradleProperties = new Properties(); - try (FileInputStream input = new FileInputStream("../../../gradle.properties")) { - gradleProperties.load(input); - return gradleProperties.getProperty("version"); - } - catch (IOException ex) { - throw new RuntimeException(ex); - } + String getPackaging() { + return this.packaging; + } + + String getContainer() { + return this.container; + } + + File getArchive() { + return new File("build/spring-boot-server-tests-app/build/libs/spring-boot-server-tests-app-" + this.container + + "." + this.packaging); } } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java similarity index 96% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java index a86fd2afbc7..7ea799f6676 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/BootRunApplicationLauncher.java @@ -43,8 +43,8 @@ class BootRunApplicationLauncher extends AbstractApplicationLauncher { private final File exploded; - BootRunApplicationLauncher(ApplicationBuilder applicationBuilder, BuildOutput buildOutput) { - super(applicationBuilder, buildOutput); + BootRunApplicationLauncher(Application application, BuildOutput buildOutput) { + super(application, buildOutput); this.exploded = new File(buildOutput.getRootLocation(), "run"); } @@ -112,7 +112,7 @@ class BootRunApplicationLauncher extends AbstractApplicationLauncher { private List getLibPaths(File archive) { return (archive.getName().endsWith(".jar") ? Collections.singletonList("BOOT-INF/lib") - : Arrays.asList("WEB-INF/lib", "WEB-INF/lib-provided")); + : Arrays.asList("WEB-INF/lib")); } private void explodeArchive(File archive) throws IOException { diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java similarity index 89% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java index d4997364350..95d1e3b1fb5 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServerContainerInvocationContextProvider.java @@ -62,8 +62,6 @@ class EmbeddedServerContainerInvocationContextProvider private static final BuildOutput buildOutput = new BuildOutput( EmbeddedServerContainerInvocationContextProvider.class); - private final Map builderCache = new HashMap<>(); - private final Map launcherCache = new HashMap<>(); private final Path tempDir; @@ -83,7 +81,7 @@ class EmbeddedServerContainerInvocationContextProvider .getAnnotation(EmbeddedServletContainerTest.class); return CONTAINERS .stream().map( - (container) -> getApplicationBuilder(annotation, container)) + (container) -> getApplication(annotation, container)) .flatMap( (builder) -> Stream .of(annotation.launchers()).map( @@ -103,28 +101,21 @@ class EmbeddedServerContainerInvocationContextProvider private void cleanupCaches() { this.launcherCache.values().forEach(AbstractApplicationLauncher::destroyProcess); this.launcherCache.clear(); - this.builderCache.clear(); } - private AbstractApplicationLauncher getAbstractApplicationLauncher(ApplicationBuilder builder, + private AbstractApplicationLauncher getAbstractApplicationLauncher(Application application, Class launcherClass) { - String cacheKey = builder.getContainer() + ":" + builder.getPackaging() + ":" + launcherClass.getName(); + String cacheKey = application.getContainer() + ":" + application.getPackaging() + ":" + launcherClass.getName(); if (this.launcherCache.containsKey(cacheKey)) { return this.launcherCache.get(cacheKey); } - AbstractApplicationLauncher launcher = ReflectionUtils.newInstance(launcherClass, builder, buildOutput); + AbstractApplicationLauncher launcher = ReflectionUtils.newInstance(launcherClass, application, buildOutput); this.launcherCache.put(cacheKey, launcher); return launcher; } - private ApplicationBuilder getApplicationBuilder(EmbeddedServletContainerTest annotation, String container) { - String cacheKey = container + ":" + annotation.packaging(); - if (this.builderCache.containsKey(cacheKey)) { - return this.builderCache.get(cacheKey); - } - ApplicationBuilder builder = new ApplicationBuilder(this.tempDir, annotation.packaging(), container); - this.builderCache.put(cacheKey, builder); - return builder; + private Application getApplication(EmbeddedServletContainerTest annotation, String container) { + return new Application(annotation.packaging(), container); } static class EmbeddedServletContainerInvocationContext implements TestTemplateInvocationContext, ParameterResolver { diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerJarDevelopmentIntegrationTests.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServletContainerJarDevelopmentIntegrationTests.java similarity index 100% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerJarDevelopmentIntegrationTests.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServletContainerJarDevelopmentIntegrationTests.java diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerJarPackagingIntegrationTests.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServletContainerJarPackagingIntegrationTests.java similarity index 100% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerJarPackagingIntegrationTests.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServletContainerJarPackagingIntegrationTests.java diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerTest.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServletContainerTest.java similarity index 100% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerTest.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServletContainerTest.java diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerWarDevelopmentIntegrationTests.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServletContainerWarDevelopmentIntegrationTests.java similarity index 100% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerWarDevelopmentIntegrationTests.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServletContainerWarDevelopmentIntegrationTests.java diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerWarPackagingIntegrationTests.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServletContainerWarPackagingIntegrationTests.java similarity index 100% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/EmbeddedServletContainerWarPackagingIntegrationTests.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/EmbeddedServletContainerWarPackagingIntegrationTests.java diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/ExplodedApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/ExplodedApplicationLauncher.java similarity index 95% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/ExplodedApplicationLauncher.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/ExplodedApplicationLauncher.java index 98c951058b6..041986451f5 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/ExplodedApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/ExplodedApplicationLauncher.java @@ -40,8 +40,8 @@ class ExplodedApplicationLauncher extends AbstractApplicationLauncher { private final Supplier exploded; - ExplodedApplicationLauncher(ApplicationBuilder applicationBuilder, BuildOutput buildOutput) { - super(applicationBuilder, buildOutput); + ExplodedApplicationLauncher(Application application, BuildOutput buildOutput) { + super(application, buildOutput); this.exploded = () -> new File(buildOutput.getRootLocation(), "exploded"); } diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java similarity index 95% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java index dd21bba8dec..62a9df16788 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/IdeApplicationLauncher.java @@ -43,8 +43,8 @@ class IdeApplicationLauncher extends AbstractApplicationLauncher { private final File exploded; - IdeApplicationLauncher(ApplicationBuilder applicationBuilder, BuildOutput buildOutput) { - super(applicationBuilder, buildOutput); + IdeApplicationLauncher(Application application, BuildOutput buildOutput) { + super(application, buildOutput); this.exploded = new File(buildOutput.getRootLocation(), "the+ide application"); } @@ -108,7 +108,7 @@ class IdeApplicationLauncher extends AbstractApplicationLauncher { private File explodedResourcesProject(File dependencies) throws IOException { File resourcesProject = new File(this.exploded, "resources-project/built/classes"); - File resourcesJar = new File(dependencies, "resources-1.0.jar"); + File resourcesJar = new File(dependencies, "spring-boot-server-tests-app-resources.jar"); explodeArchive(resourcesJar, resourcesProject); resourcesJar.delete(); return resourcesProject; @@ -132,7 +132,7 @@ class IdeApplicationLauncher extends AbstractApplicationLauncher { private List getLibPaths(File archive) { return (archive.getName().endsWith(".jar") ? Collections.singletonList("BOOT-INF/lib") - : Arrays.asList("WEB-INF/lib", "WEB-INF/lib-provided")); + : Arrays.asList("WEB-INF/lib")); } private void explodeArchive(File archive, File destination) throws IOException { diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/PackagedApplicationLauncher.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/PackagedApplicationLauncher.java similarity index 91% rename from spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/PackagedApplicationLauncher.java rename to spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/PackagedApplicationLauncher.java index 6bd33bb9f9a..e833d86b05f 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/PackagedApplicationLauncher.java +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/intTest/java/org/springframework/boot/context/embedded/PackagedApplicationLauncher.java @@ -30,8 +30,8 @@ import org.springframework.boot.testsupport.BuildOutput; */ class PackagedApplicationLauncher extends AbstractApplicationLauncher { - PackagedApplicationLauncher(ApplicationBuilder applicationBuilder, BuildOutput buildOutput) { - super(applicationBuilder, buildOutput); + PackagedApplicationLauncher(Application application, BuildOutput buildOutput) { + super(application, buildOutput); } @Override diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/ApplicationBuilder.java b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/ApplicationBuilder.java deleted file mode 100644 index 5b145e7f4e6..00000000000 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/java/org/springframework/boot/context/embedded/ApplicationBuilder.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright 2012-2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.context.embedded; - -import java.io.File; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.jar.JarOutputStream; -import java.util.zip.ZipEntry; - -import com.samskivert.mustache.Mustache; -import org.apache.maven.shared.invoker.DefaultInvocationRequest; -import org.apache.maven.shared.invoker.DefaultInvoker; -import org.apache.maven.shared.invoker.InvocationRequest; -import org.apache.maven.shared.invoker.InvocationResult; -import org.apache.maven.shared.invoker.MavenInvocationException; - -import org.springframework.util.FileCopyUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Builds a Spring Boot application using Maven. - * - * @author Andy Wilkinson - */ -class ApplicationBuilder { - - private final Path temp; - - private final String packaging; - - private final String container; - - ApplicationBuilder(Path temp, String packaging, String container) { - this.temp = temp; - this.packaging = packaging; - this.container = container; - } - - File buildApplication() throws Exception { - File containerDirectory = new File(this.temp.toFile(), this.container); - if (containerDirectory.exists()) { - return new File(containerDirectory, "app/target/app-0.0.1." + this.packaging); - } - return doBuildApplication(containerDirectory); - } - - String getPackaging() { - return this.packaging; - } - - String getContainer() { - return this.container; - } - - private File doBuildApplication(File containerDirectory) throws IOException, MavenInvocationException { - File resourcesJar = createResourcesJar(); - File appDirectory = new File(containerDirectory, "app"); - appDirectory.mkdirs(); - File settingsXml = writeSettingsXml(appDirectory); - writePom(appDirectory, resourcesJar); - copyApplicationSource(appDirectory); - packageApplication(appDirectory, settingsXml); - return new File(appDirectory, "target/app-0.0.1." + this.packaging); - } - - private File createResourcesJar() throws IOException { - File resourcesJar = new File(this.temp.toFile(), "resources.jar"); - if (resourcesJar.exists()) { - return resourcesJar; - } - try (JarOutputStream resourcesJarStream = new JarOutputStream(new FileOutputStream(resourcesJar))) { - resourcesJarStream.putNextEntry(new ZipEntry("META-INF/resources/")); - resourcesJarStream.closeEntry(); - resourcesJarStream.putNextEntry(new ZipEntry("META-INF/resources/nested-meta-inf-resource.txt")); - resourcesJarStream.write("nested".getBytes()); - resourcesJarStream.closeEntry(); - if (!isWindows()) { - resourcesJarStream.putNextEntry( - new ZipEntry("META-INF/resources/nested-reserved-!#$%&()*+,:=?@[]-meta-inf-resource.txt")); - resourcesJarStream.write("encoded-name".getBytes()); - resourcesJarStream.closeEntry(); - } - return resourcesJar; - } - } - - private void writePom(File appDirectory, File resourcesJar) throws IOException { - Map context = new HashMap<>(); - context.put("packaging", this.packaging); - context.put("container", this.container); - context.put("bootVersion", Versions.getBootVersion()); - context.put("resourcesJarPath", resourcesJar.getAbsolutePath()); - try (FileWriter out = new FileWriter(new File(appDirectory, "pom.xml")); - FileReader templateReader = new FileReader("src/test/resources/pom-template.xml")) { - Mustache.compiler().escapeHTML(false).compile(templateReader).execute(context, out); - } - } - - private File writeSettingsXml(File appDirectory) throws IOException { - Map context = new HashMap<>(); - context.put("repository", new File("build/test-repository").toURI().toURL()); - context.put("localRepository", new File("build/local-m2-repository").getAbsolutePath()); - File settingsXml = new File(appDirectory, "settings.xml"); - try (FileWriter out = new FileWriter(settingsXml); - FileReader templateReader = new FileReader("src/test/resources/settings-template.xml")) { - Mustache.compiler().escapeHTML(false).compile(templateReader).execute(context, out); - } - return settingsXml; - } - - private void copyApplicationSource(File appDirectory) throws IOException { - File examplePackage = new File(appDirectory, "src/main/java/com/example"); - examplePackage.mkdirs(); - FileCopyUtils.copy(new File("src/test/java/com/example/ResourceHandlingApplication.java"), - new File(examplePackage, "ResourceHandlingApplication.java")); - // To allow aliased resources on Concourse Windows CI (See gh-15553) to be served - // as static resources. - if (this.container.equals("jetty")) { - FileCopyUtils.copy(new File("src/test/java/com/example/JettyServerCustomizerConfig.java"), - new File(examplePackage, "JettyServerCustomizerConfig.java")); - } - if ("war".equals(this.packaging)) { - File srcMainWebapp = new File(appDirectory, "src/main/webapp"); - srcMainWebapp.mkdirs(); - FileCopyUtils.copy("webapp resource", new FileWriter(new File(srcMainWebapp, "webapp-resource.txt"))); - } - copyAutoConfigurationFiles(appDirectory); - return; - } - - private void copyAutoConfigurationFiles(File appDirectory) throws IOException { - File autoConfigPackage = new File(appDirectory, "src/main/java/com/autoconfig"); - autoConfigPackage.mkdirs(); - FileCopyUtils.copy(new File("src/test/java/com/autoconfig/ExampleAutoConfiguration.java"), - new File(autoConfigPackage, "ExampleAutoConfiguration.java")); - File srcMainResources = new File(appDirectory, "src/main/resources"); - srcMainResources.mkdirs(); - File metaInf = new File(srcMainResources, "META-INF"); - metaInf.mkdirs(); - FileCopyUtils.copy(new File("src/test/resources/META-INF/spring.factories"), - new File(metaInf, "spring.factories")); - } - - private void packageApplication(File appDirectory, File settingsXml) throws MavenInvocationException { - InvocationRequest invocation = new DefaultInvocationRequest(); - invocation.setBaseDirectory(appDirectory); - invocation.setGoals(Collections.singletonList("package")); - if (settingsXml != null) { - invocation.setUserSettingsFile(settingsXml); - } - invocation.setUpdateSnapshots(true); - DefaultInvoker invoker = new DefaultInvoker(); - invoker.setMavenHome(new File("build/maven-binaries/apache-maven-3.6.2")); - InvocationResult execute = invoker.execute(invocation); - assertThat(execute.getExitCode()).isEqualTo(0); - } - - private boolean isWindows() { - return File.separatorChar == '\\'; - } - -} diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/pom-template.xml b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/pom-template.xml deleted file mode 100644 index 4d052d64b6d..00000000000 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/pom-template.xml +++ /dev/null @@ -1,87 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - {{bootVersion}} - - - com.example - app - 0.0.1 - {{packaging}} - - {{resourcesJarPath}} - - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-{{container}} - - - org.springframework - spring-web - - - javax.servlet - javax.servlet-api - provided - - - com.example - resources - 1.0 - system - ${resourcesJarPath} - - - - - - org.springframework.boot - spring-boot-maven-plugin - - true - - - - - - - spring-snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - https://repo.spring.io/milestone - - false - - - - - - spring-snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - https://repo.spring.io/milestone - - false - - - - diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/settings-template.xml b/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/settings-template.xml deleted file mode 100644 index 8f5030fac96..00000000000 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-server-tests/src/test/resources/settings-template.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - {{localRepository}} - - - repository - - true - - - - repository - {{repository}} - - true - - - - - - repository - {{repository}} - - true - - - - - -