diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle index f0b5d3fb9b..399542a47b 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/build.gradle @@ -13,7 +13,6 @@ configurations { dependencies { app project(path: ":spring-boot-project:spring-boot-dependencies", configuration: "mavenRepository") app project(path: ":spring-boot-project:spring-boot-parent", configuration: "mavenRepository") - app project(path: ":spring-boot-project:spring-boot-starters:spring-boot-starter-web", configuration: "mavenRepository") app project(path: ":spring-boot-project:spring-boot-tools:spring-boot-gradle-plugin", configuration: "mavenRepository") intTestImplementation(enforcedPlatform(project(":spring-boot-project:spring-boot-parent"))) diff --git a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/spring-boot-launch-script-tests-app/build.gradle b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/spring-boot-launch-script-tests-app/build.gradle index 7ab763fe56..4c842b1e1c 100644 --- a/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/spring-boot-launch-script-tests-app/build.gradle +++ b/spring-boot-tests/spring-boot-integration-tests/spring-boot-launch-script-tests/spring-boot-launch-script-tests-app/build.gradle @@ -13,7 +13,7 @@ repositories { } dependencies { - implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.apache.tomcat.embed:tomcat-embed-core") } bootJar { diff --git a/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 b/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 index a5d87e0afe..8bf6791404 100644 --- a/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 +++ b/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 @@ -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,14 +16,73 @@ package org.springframework.boot.launchscript; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; +import java.io.IOException; +import java.net.URL; +import java.security.CodeSource; +import java.security.ProtectionDomain; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.catalina.Context; +import org.apache.catalina.LifecycleException; +import org.apache.catalina.startup.Tomcat; -@SpringBootApplication public class LaunchScriptTestApplication { - public static void main(String[] args) { - SpringApplication.run(LaunchScriptTestApplication.class, args); + public static void main(String[] args) throws LifecycleException { + System.out.println("Starting " + LaunchScriptTestApplication.class.getSimpleName() + " (" + findSource() + ")"); + Tomcat tomcat = new Tomcat(); + tomcat.getConnector().setPort(getPort(args)); + Context context = tomcat.addContext(getContextPath(args), null); + tomcat.addServlet(context.getPath(), "test", new HttpServlet() { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws ServletException, IOException { + resp.getWriter().println("Launched"); + } + + }); + context.addServletMappingDecoded("/", "test"); + tomcat.start(); + } + + private static URL findSource() { + try { + ProtectionDomain domain = LaunchScriptTestApplication.class.getProtectionDomain(); + CodeSource codeSource = (domain != null) ? domain.getCodeSource() : null; + return (codeSource != null) ? codeSource.getLocation() : null; + } + catch (Exception ex) { + } + return null; + } + + private static int getPort(String[] args) { + String port = getProperty(args, "server.port"); + return (port != null) ? Integer.parseInt(port) : 8080; + } + + private static String getContextPath(String[] args) { + String contextPath = getProperty(args, "server.servlet.context-path"); + return (contextPath != null) ? contextPath : ""; + } + + private static String getProperty(String[] args, String property) { + String value = System.getProperty(property); + if (value != null) { + return value; + } + String prefix = "--" + property + "="; + for (String arg : args) { + if (arg.startsWith(prefix)) { + return arg.substring(prefix.length()); + } + } + return null; } } diff --git a/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 b/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 deleted file mode 100644 index 67d08ccb05..0000000000 --- a/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 +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2012-2020 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.launchscript; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -public class LaunchVerificationController { - - @RequestMapping("/") - public String verifyLaunch() { - return "Launched\n"; - } - -}