Skip to content

Commit 14a57ad

Browse files
committed
Merge branch '2.4.x' into 2.5.x
Closes gh-28165
2 parents d238566 + 35b16ea commit 14a57ad

File tree

4 files changed

+66
-38
lines changed

4 files changed

+66
-38
lines changed

spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ configurations {
1313
dependencies {
1414
app project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "mavenRepository")
1515
app project(path: ":spring-boot-project:spring-boot-parent", configuration: "mavenRepository")
16-
app project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-web", configuration: "mavenRepository")
1716
app project(path: ":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin", configuration: "mavenRepository")
1817

1918
intTestImplementation(enforcedPlatform(project(":spring-boot-project:spring-boot-parent")))

spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/spring-boot-launch-script-tests-app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repositories {
1313
}
1414

1515
dependencies {
16-
implementation("org.springframework.boot:spring-boot-starter-web")
16+
implementation("org.apache.tomcat.embed:tomcat-embed-core")
1717
}
1818

1919
bootJar {

spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/spring-boot-launch-script-tests-app/src/main/java/org/springframework/boot/launchscript/LaunchScriptTestApplication.java

+65-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,14 +16,73 @@
1616

1717
package org.springframework.boot.launchscript;
1818

19-
import org.springframework.boot.SpringApplication;
20-
import org.springframework.boot.autoconfigure.SpringBootApplication;
19+
import java.io.IOException;
20+
import java.net.URL;
21+
import java.security.CodeSource;
22+
import java.security.ProtectionDomain;
23+
24+
import javax.servlet.ServletException;
25+
import javax.servlet.http.HttpServlet;
26+
import javax.servlet.http.HttpServletRequest;
27+
import javax.servlet.http.HttpServletResponse;
28+
29+
import org.apache.catalina.Context;
30+
import org.apache.catalina.LifecycleException;
31+
import org.apache.catalina.startup.Tomcat;
2132

22-
@SpringBootApplication
2333
public class LaunchScriptTestApplication {
2434

25-
public static void main(String[] args) {
26-
SpringApplication.run(LaunchScriptTestApplication.class, args);
35+
public static void main(String[] args) throws LifecycleException {
36+
System.out.println("Starting " + LaunchScriptTestApplication.class.getSimpleName() + " (" + findSource() + ")");
37+
Tomcat tomcat = new Tomcat();
38+
tomcat.getConnector().setPort(getPort(args));
39+
Context context = tomcat.addContext(getContextPath(args), null);
40+
tomcat.addServlet(context.getPath(), "test", new HttpServlet() {
41+
42+
@Override
43+
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
44+
throws ServletException, IOException {
45+
resp.getWriter().println("Launched");
46+
}
47+
48+
});
49+
context.addServletMappingDecoded("/", "test");
50+
tomcat.start();
51+
}
52+
53+
private static URL findSource() {
54+
try {
55+
ProtectionDomain domain = LaunchScriptTestApplication.class.getProtectionDomain();
56+
CodeSource codeSource = (domain != null) ? domain.getCodeSource() : null;
57+
return (codeSource != null) ? codeSource.getLocation() : null;
58+
}
59+
catch (Exception ex) {
60+
}
61+
return null;
62+
}
63+
64+
private static int getPort(String[] args) {
65+
String port = getProperty(args, "server.port");
66+
return (port != null) ? Integer.parseInt(port) : 8080;
67+
}
68+
69+
private static String getContextPath(String[] args) {
70+
String contextPath = getProperty(args, "server.servlet.context-path");
71+
return (contextPath != null) ? contextPath : "";
72+
}
73+
74+
private static String getProperty(String[] args, String property) {
75+
String value = System.getProperty(property);
76+
if (value != null) {
77+
return value;
78+
}
79+
String prefix = "--" + property + "=";
80+
for (String arg : args) {
81+
if (arg.startsWith(prefix)) {
82+
return arg.substring(prefix.length());
83+
}
84+
}
85+
return null;
2786
}
2887

2988
}

spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/spring-boot-launch-script-tests-app/src/main/java/org/springframework/boot/launchscript/LaunchVerificationController.java

-30
This file was deleted.

0 commit comments

Comments
 (0)