Skip to content

Commit 572fe05

Browse files
committed
Add WAR TLD loader integration test
Fixes gh-38068 Signed-off-by: Vinod Kumar <codingkiddo@gmail.com>
1 parent 8a449c5 commit 572fe05

6 files changed

Lines changed: 165 additions & 12 deletions

File tree

integration-test/spring-boot-loader-integration-tests/build.gradle

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,17 @@ tasks.register("buildSignedJarRsaApp", GradleBuild) {
8282
tasks = ["build"]
8383
}
8484

85+
tasks.register("syncWarAppSource", org.springframework.boot.build.SyncAppSource) {
86+
sourceDirectory = file("spring-boot-loader-tests-war")
87+
destinationDirectory = file(layout.buildDirectory.dir("spring-boot-loader-tests-war"))
88+
}
89+
90+
tasks.register("buildWarApp", GradleBuild) {
91+
dependsOn syncWarAppSource, syncMavenRepository
92+
dir = layout.buildDirectory.dir("spring-boot-loader-tests-war")
93+
startParameter.buildCacheEnabled = false
94+
tasks = ["build"]
95+
}
8596

8697
tasks.register("downloadJdk", Download) {
8798
def destFolder = new File(project.gradle.gradleUserHomeDir, "caches/springboot/downloads/jdk/oracle")
@@ -105,5 +116,5 @@ tasks.named("processDockerTestResources").configure {
105116
}
106117

107118
tasks.named("dockerTest").configure {
108-
dependsOn buildApp, buildSignedJarApp, buildSignedJarRsaApp
119+
dependsOn buildApp, buildWarApp, buildSignedJarApp, buildSignedJarRsaApp
109120
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id "war"
19+
id "org.springframework.boot"
20+
}
21+
22+
java {
23+
sourceCompatibility = '17'
24+
targetCompatibility = '17'
25+
}
26+
27+
repositories {
28+
maven { url = layout.projectDirectory.dir("../docker-test-maven-repository") }
29+
mavenCentral()
30+
spring.mavenRepositories()
31+
}
32+
33+
dependencies {
34+
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
35+
implementation("org.springframework.boot:spring-boot-starter-webmvc")
36+
37+
providedRuntime(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))
38+
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat-runtime")
39+
providedRuntime("org.glassfish.web:jakarta.servlet.jsp.jstl")
40+
providedRuntime("org.apache.tomcat.embed:tomcat-embed-jasper")
41+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the License);
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
pluginManagement {
18+
evaluate(new File("${gradle.parent.rootProject.rootDir}/buildSrc/SpringRepositorySupport.groovy")).apply(this)
19+
repositories {
20+
maven { url = layout.settingsDirectory.dir("../docker-test-maven-repository") }
21+
mavenCentral()
22+
spring.mavenRepositories()
23+
}
24+
resolutionStrategy {
25+
eachPlugin {
26+
if (requested.id.id == "org.springframework.boot") {
27+
useModule "org.springframework.boot:spring-boot-gradle-plugin:${requested.version}"
28+
}
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.loaderwarapp;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
import org.springframework.boot.builder.SpringApplicationBuilder;
22+
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
23+
24+
@SpringBootApplication
25+
public class LoaderWarTestApplication extends SpringBootServletInitializer {
26+
27+
@Override
28+
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
29+
return application.sources(LoaderWarTestApplication.class);
30+
}
31+
32+
public static void main(String[] args) {
33+
SpringApplication.run(LoaderWarTestApplication.class, args).close();
34+
}
35+
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
3+
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
4+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
5+
6+
<html lang="en">
7+
<body>
8+
<c:url value="/" var="url"/>
9+
<spring:url value="/" htmlEscape="true" var="springUrl" />
10+
Spring URL: ${springUrl}
11+
JSTL URL: ${url}
12+
</body>
13+
</html>

integration-test/spring-boot-loader-integration-tests/src/dockerTest/java/org/springframework/boot/loader/LoaderIntegrationTests.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ void runJar(JavaRuntime javaRuntime) {
6363
}
6464
}
6565

66+
@ParameterizedTest
67+
@MethodSource("javaRuntimes")
68+
void runWarWithTldScanning(JavaRuntime javaRuntime) {
69+
try (GenericContainer<?> container = createContainer(javaRuntime, "spring-boot-loader-tests-war", null,
70+
"war")) {
71+
container.start();
72+
System.out.println(this.output.toUtf8String());
73+
assertThat(this.output.toUtf8String()).contains("Started LoaderWarTestApplication")
74+
.doesNotContain("no entry name specified")
75+
.doesNotContain("Failed to scan")
76+
.doesNotContain("ZipException")
77+
.doesNotContain("WARNING:");
78+
}
79+
}
80+
6681
@ParameterizedTest
6782
@MethodSource("javaRuntimes")
6883
void runSignedJar(JavaRuntime javaRuntime) {
@@ -97,31 +112,37 @@ void runSignedJarWhenRsa(JavaRuntime javaRuntime) {
97112
}
98113

99114
private GenericContainer<?> createContainer(JavaRuntime javaRuntime, String name, String classifier) {
115+
return createContainer(javaRuntime, name, classifier, "jar");
116+
}
117+
118+
private GenericContainer<?> createContainer(JavaRuntime javaRuntime, String name, String classifier,
119+
String extension) {
120+
String application = "app." + extension;
100121
return javaRuntime.getContainer()
101122
.withLogConsumer(this.output)
102-
.withCopyFileToContainer(findApplication(name, classifier), "/app.jar")
123+
.withCopyFileToContainer(findApplication(name, classifier, extension), "/" + application)
103124
.withStartupCheckStrategy(new OneShotStartupCheckStrategy().withTimeout(Duration.ofMinutes(5)))
104-
.withCommand(command());
125+
.withCommand(command(application));
105126
}
106127

107-
private String[] command() {
128+
private String[] command(String application) {
108129
List<String> command = new ArrayList<>();
109130
command.add("java");
110131
command.add("-jar");
111-
command.add("app.jar");
132+
command.add(application);
112133
return command.toArray(new String[0]);
113134
}
114135

115-
private MountableFile findApplication(String name, String classifier) {
116-
return MountableFile.forHostPath(findJarFile(name, classifier).toPath());
136+
private MountableFile findApplication(String name, String classifier, String extension) {
137+
return MountableFile.forHostPath(findArchiveFile(name, classifier, extension).toPath());
117138
}
118139

119-
private File findJarFile(String name, String classifier) {
140+
private File findArchiveFile(String name, String classifier, String extension) {
120141
classifier = (classifier != null) ? "-" + classifier : "";
121-
String path = String.format("build/%1$s/build/libs/%1$s%2$s.jar", name, classifier);
122-
File jar = new File(path);
123-
Assert.state(jar.isFile(), () -> "Could not find " + path + ". Have you built it?");
124-
return jar;
142+
String path = String.format("build/%1$s/build/libs/%1$s%2$s.%3$s", name, classifier, extension);
143+
File archive = new File(path);
144+
Assert.state(archive.isFile(), () -> "Could not find " + path + ". Have you built it?");
145+
return archive;
125146
}
126147

127148
static Stream<JavaRuntime> javaRuntimes() {

0 commit comments

Comments
 (0)