diff --git a/integration-test/spring-boot-loader-integration-tests/build.gradle b/integration-test/spring-boot-loader-integration-tests/build.gradle index 9803aaea9e0d..9da9ae26256d 100644 --- a/integration-test/spring-boot-loader-integration-tests/build.gradle +++ b/integration-test/spring-boot-loader-integration-tests/build.gradle @@ -82,6 +82,17 @@ tasks.register("buildSignedJarRsaApp", GradleBuild) { tasks = ["build"] } +tasks.register("syncWarAppSource", org.springframework.boot.build.SyncAppSource) { + sourceDirectory = file("spring-boot-loader-tests-war") + destinationDirectory = file(layout.buildDirectory.dir("spring-boot-loader-tests-war")) +} + +tasks.register("buildWarApp", GradleBuild) { + dependsOn syncWarAppSource, syncMavenRepository + dir = layout.buildDirectory.dir("spring-boot-loader-tests-war") + startParameter.buildCacheEnabled = false + tasks = ["build"] +} tasks.register("downloadJdk", Download) { def destFolder = new File(project.gradle.gradleUserHomeDir, "caches/springboot/downloads/jdk/oracle") @@ -105,5 +116,5 @@ tasks.named("processDockerTestResources").configure { } tasks.named("dockerTest").configure { - dependsOn buildApp, buildSignedJarApp, buildSignedJarRsaApp + dependsOn buildApp, buildWarApp, buildSignedJarApp, buildSignedJarRsaApp } diff --git a/integration-test/spring-boot-loader-integration-tests/spring-boot-loader-tests-war/build.gradle b/integration-test/spring-boot-loader-integration-tests/spring-boot-loader-tests-war/build.gradle new file mode 100644 index 000000000000..a3e0b11f58e6 --- /dev/null +++ b/integration-test/spring-boot-loader-integration-tests/spring-boot-loader-tests-war/build.gradle @@ -0,0 +1,41 @@ +/* + * Copyright 2012-present 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. + */ + +plugins { + id "war" + id "org.springframework.boot" +} + +java { + sourceCompatibility = '17' + targetCompatibility = '17' +} + +repositories { + maven { url = layout.projectDirectory.dir("../docker-test-maven-repository") } + mavenCentral() + spring.mavenRepositories() +} + +dependencies { + implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + implementation("org.springframework.boot:spring-boot-starter-webmvc") + + providedRuntime(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)) + providedRuntime("org.springframework.boot:spring-boot-starter-tomcat-runtime") + providedRuntime("org.glassfish.web:jakarta.servlet.jsp.jstl") + providedRuntime("org.apache.tomcat.embed:tomcat-embed-jasper") +} diff --git a/integration-test/spring-boot-loader-integration-tests/spring-boot-loader-tests-war/settings.gradle b/integration-test/spring-boot-loader-integration-tests/spring-boot-loader-tests-war/settings.gradle new file mode 100644 index 000000000000..d5cca12cf132 --- /dev/null +++ b/integration-test/spring-boot-loader-integration-tests/spring-boot-loader-tests-war/settings.gradle @@ -0,0 +1,31 @@ +/* + * Copyright 2012-present 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. + */ + +pluginManagement { + evaluate(new File("${gradle.parent.rootProject.rootDir}/buildSrc/SpringRepositorySupport.groovy")).apply(this) + repositories { + maven { url = layout.settingsDirectory.dir("../docker-test-maven-repository") } + mavenCentral() + spring.mavenRepositories() + } + resolutionStrategy { + eachPlugin { + if (requested.id.id == "org.springframework.boot") { + useModule "org.springframework.boot:spring-boot-gradle-plugin:${requested.version}" + } + } + } +} diff --git a/integration-test/spring-boot-loader-integration-tests/spring-boot-loader-tests-war/src/main/java/org/springframework/boot/loaderwarapp/LoaderWarTestApplication.java b/integration-test/spring-boot-loader-integration-tests/spring-boot-loader-tests-war/src/main/java/org/springframework/boot/loaderwarapp/LoaderWarTestApplication.java new file mode 100644 index 000000000000..6d9e218ccf5a --- /dev/null +++ b/integration-test/spring-boot-loader-integration-tests/spring-boot-loader-tests-war/src/main/java/org/springframework/boot/loaderwarapp/LoaderWarTestApplication.java @@ -0,0 +1,36 @@ +/* + * Copyright 2012-present 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.loaderwarapp; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; + +@SpringBootApplication +public class LoaderWarTestApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(LoaderWarTestApplication.class); + } + + public static void main(String[] args) { + SpringApplication.run(LoaderWarTestApplication.class, args).close(); + } + +} diff --git a/integration-test/spring-boot-loader-integration-tests/spring-boot-loader-tests-war/src/main/webapp/WEB-INF/jsp/welcome.jsp b/integration-test/spring-boot-loader-integration-tests/spring-boot-loader-tests-war/src/main/webapp/WEB-INF/jsp/welcome.jsp new file mode 100644 index 000000000000..811f3e7d00f2 --- /dev/null +++ b/integration-test/spring-boot-loader-integration-tests/spring-boot-loader-tests-war/src/main/webapp/WEB-INF/jsp/welcome.jsp @@ -0,0 +1,13 @@ + + +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> + + + + + + Spring URL: ${springUrl} + JSTL URL: ${url} + + diff --git a/integration-test/spring-boot-loader-integration-tests/src/dockerTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java b/integration-test/spring-boot-loader-integration-tests/src/dockerTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java index 54d662e738ab..56c1fecd4e29 100644 --- a/integration-test/spring-boot-loader-integration-tests/src/dockerTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java +++ b/integration-test/spring-boot-loader-integration-tests/src/dockerTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java @@ -63,6 +63,21 @@ void runJar(JavaRuntime javaRuntime) { } } + @ParameterizedTest + @MethodSource("javaRuntimes") + void runWarWithTldScanning(JavaRuntime javaRuntime) { + try (GenericContainer container = createContainer(javaRuntime, "spring-boot-loader-tests-war", null, + "war")) { + container.start(); + System.out.println(this.output.toUtf8String()); + assertThat(this.output.toUtf8String()).contains("Started LoaderWarTestApplication") + .doesNotContain("no entry name specified") + .doesNotContain("Failed to scan") + .doesNotContain("ZipException") + .doesNotContain("WARNING:"); + } + } + @ParameterizedTest @MethodSource("javaRuntimes") void runSignedJar(JavaRuntime javaRuntime) { @@ -97,31 +112,37 @@ void runSignedJarWhenRsa(JavaRuntime javaRuntime) { } private GenericContainer createContainer(JavaRuntime javaRuntime, String name, String classifier) { + return createContainer(javaRuntime, name, classifier, "jar"); + } + + private GenericContainer createContainer(JavaRuntime javaRuntime, String name, String classifier, + String extension) { + String application = "app." + extension; return javaRuntime.getContainer() .withLogConsumer(this.output) - .withCopyFileToContainer(findApplication(name, classifier), "/app.jar") + .withCopyFileToContainer(findApplication(name, classifier, extension), "/" + application) .withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofMinutes(5))) - .withCommand(command()); + .withCommand(command(application)); } - private String[] command() { + private String[] command(String application) { List command = new ArrayList<>(); command.add("java"); command.add("-jar"); - command.add("app.jar"); + command.add(application); return command.toArray(new String[0]); } - private MountableFile findApplication(String name, String classifier) { - return MountableFile.forHostPath(findJarFile(name, classifier).toPath()); + private MountableFile findApplication(String name, String classifier, String extension) { + return MountableFile.forHostPath(findArchiveFile(name, classifier, extension).toPath()); } - private File findJarFile(String name, String classifier) { + private File findArchiveFile(String name, String classifier, String extension) { classifier = (classifier != null) ? "-" + classifier : ""; - String path = String.format("build/%1$s/build/libs/%1$s%2$s.jar", name, classifier); - File jar = new File(path); - Assert.state(jar.isFile(), () -> "Could not find " + path + ". Have you built it?"); - return jar; + String path = String.format("build/%1$s/build/libs/%1$s%2$s.%3$s", name, classifier, extension); + File archive = new File(path); + Assert.state(archive.isFile(), () -> "Could not find " + path + ". Have you built it?"); + return archive; } static Stream javaRuntimes() {