diff --git a/liberty-maven-plugin/src/it/dev-it/resources/springboot-project/pom.xml b/liberty-maven-plugin/src/it/dev-it/resources/springboot-project/pom.xml new file mode 100644 index 000000000..5f35d88cf --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/springboot-project/pom.xml @@ -0,0 +1,159 @@ + + + 4.0.0 + + springboot-project + 1.0.0.Final + jar + + + org.springframework.boot + spring-boot-starter-parent + 2.6.7 + + + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + junit + junit + 4.13.2 + test + + + + javax.xml.bind + jaxb-api + 2.3.1 + provided + + + com.sun.xml.bind + jaxb-core + 2.3.0.1 + provided + + + javax.activation + activation + 1.1.1 + provided + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + exec + + + + + io.openliberty.tools + liberty-maven-plugin + SUB_VERSION + + + + test + src/test/resources/server.xml + + ${runtimeGroupId} + ${runtimeArtifactId} + ${runtimeVersion} + zip + + apps + spring-boot-project + + + + + stop-server-before-clean + pre-clean + + stop + + + + create-server + prepare-package + + install-server + create + install-feature + + + + install-apps + package + + deploy + + + + + test-start-server + pre-integration-test + + test-start + + + + test-stop-server + post-integration-test + + test-stop + + + + + + + maven-failsafe-plugin + 3.1.2 + + alphabetical + + + + default-integration-test + integration-test + + integration-test + + + + default-verify + verify + + verify + + + + + + + + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/springboot-project/src/main/java/application/SpringBootApp.java b/liberty-maven-plugin/src/it/dev-it/resources/springboot-project/src/main/java/application/SpringBootApp.java new file mode 100644 index 000000000..caa4db557 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/springboot-project/src/main/java/application/SpringBootApp.java @@ -0,0 +1,35 @@ +/** + * (C) Copyright IBM Corporation 2018. + * + * 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 + * + * http://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 application; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +@RestController +public class SpringBootApp { + public static void main(String[] args) { + SpringApplication.run(SpringBootApp.class, args); + } + + @RequestMapping("/spring") + public String hello() { + return "HELLO SPRING BOOT!!"; + } +} \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/dev-it/resources/springboot-project/src/test/resources/server.xml b/liberty-maven-plugin/src/it/dev-it/resources/springboot-project/src/test/resources/server.xml new file mode 100644 index 000000000..202a9aa19 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/springboot-project/src/test/resources/server.xml @@ -0,0 +1,14 @@ + + + + + + springBoot-2.0 + servlet-4.0 + + + + + \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/SpringBootRunTest.java b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/SpringBootRunTest.java new file mode 100644 index 000000000..06d1cadf2 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/SpringBootRunTest.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * (c) Copyright IBM Corporation 2019, 2022. + * + * 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 + * + * http://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 net.wasdev.wlp.test.dev.it; + +import static org.junit.Assert.*; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.nio.file.Files; +import java.util.Scanner; + +import org.apache.commons.io.FileUtils; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import static io.openliberty.tools.common.plugins.util.BinaryScannerUtil.*; + +public class SpringBootRunTest extends BaseDevTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + setUpBeforeClass(null, "../resources/springboot-project", false, false, null, null); + } + + @AfterClass + public static void cleanUpAfterClass() throws Exception { + BaseDevTest.cleanUpAfterClass(false); + } + + /** + * As part of the multi-module validation, the run goal is skipped on projects with a "jar" packaging type. + * There is an exception for Spring Boot projects. This test will validate that the spring boot project is not skipped + * + * @throws Exception + */ + @Test + public void validateRunExecutionNotSkipped() throws Exception { + String mavenPluginCommand = "mvn package io.openliberty.tools:liberty-maven-plugin:"+System.getProperty("mavenPluginVersion")+":run"; + + StringBuilder command = new StringBuilder(mavenPluginCommand); + ProcessBuilder builder = buildProcess(command.toString()); + + builder.redirectOutput(logFile); + builder.redirectError(logFile); + process = builder.start(); + assertTrue(process.isAlive()); + + OutputStream stdin = process.getOutputStream(); + + writer = new BufferedWriter(new OutputStreamWriter(stdin)); + + // Make sure we are not skipping the project + assertTrue(getLogTail(), verifyLogMessageDoesNotExist("Skipping module springboot-project which is not included in this invocation of the run goal", 30000)); + + // Check that the server has started + assertTrue(getLogTail(), verifyLogMessageExists("CWWKF0011I", 120000)); + } +} diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/ServerFeatureSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/ServerFeatureSupport.java index 189e986a7..36cf2e422 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/ServerFeatureSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/ServerFeatureSupport.java @@ -170,7 +170,7 @@ private static boolean isSubModule(MavenProject potentialTopModule, MavenProject * @return * @throws MojoExecutionException */ - protected List getRelevantMultiModuleProjects(ProjectDependencyGraph graph) throws MojoExecutionException { + protected List getRelevantMultiModuleProjects(ProjectDependencyGraph graph, boolean skipJars) throws MojoExecutionException { getLog().debug("Resolve relevant multi-module projects"); List sortedReactorProjects = graph.getSortedProjects(); @@ -181,10 +181,10 @@ protected List getRelevantMultiModuleProjects(ProjectDependencyGra for (MavenProject reactorProject : sortedReactorProjects) { if (graph.getDownstreamProjects(reactorProject, true).isEmpty()) { getLog().debug("Found final downstream project: " + reactorProject.getArtifactId()); - + if (skipConfigured(reactorProject)) { getLog().debug("Skip configured on project: " + reactorProject.getArtifactId() + " - Ignoring"); - } else if (reactorProject.getPackaging().equals("jar")) { + } else if (reactorProject.getPackaging().equals("jar") && skipJars) { getLog().debug(reactorProject.getArtifactId() + " is a jar project - Ignoring"); } else { leaves.add(reactorProject); diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java index e6278eb1f..f41c0ff83 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/DevMojo.java @@ -1342,7 +1342,11 @@ private void doDevMode() throws MojoExecutionException { // In a multi-module build, dev mode will only be run on one project (the farthest downstream) and compile will // be run on any relative upstream projects. If this current project in the Maven Reactor is not one of those projects, skip it. - List relevantProjects = getRelevantMultiModuleProjects(graph); + boolean skipJars = true; + if("spring-boot-project".equals(getDeployPackages())) { + skipJars = false; + } + List relevantProjects = getRelevantMultiModuleProjects(graph, skipJars); if (!relevantProjects.contains(project)) { getLog().info("\nSkipping module " + project.getArtifactId() + " which is not included in this invocation of dev mode.\n"); return; diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/GenerateFeaturesMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/GenerateFeaturesMojo.java index 557d0d046..82c51bc65 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/GenerateFeaturesMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/GenerateFeaturesMojo.java @@ -54,7 +54,7 @@ * config/dropins directory. */ @Mojo(name = "generate-features", threadSafe = true) -public class GenerateFeaturesMojo extends ServerFeatureSupport { +public class GenerateFeaturesMojo extends PluginConfigSupport { public static final String FEATURES_FILE_MESSAGE = "The Liberty Maven Plugin has generated Liberty features necessary for your application in " + GENERATED_FEATURES_FILE_PATH; @@ -119,7 +119,11 @@ private void generateFeatures() throws MojoExecutionException, PluginExecutionEx // In a multi-module build, generate-features will only be run on one project (the farthest downstream). // If this current project in the Maven Reactor is not that project or any of its upstream projects, skip it. - List relevantProjects = getRelevantMultiModuleProjects(graph); + boolean skipJars = true; + if("spring-boot-project".equals(getDeployPackages())) { + skipJars = false; + } + List relevantProjects = getRelevantMultiModuleProjects(graph, skipJars); if (!relevantProjects.contains(project)) { getLog().info("\nSkipping module " + project.getArtifactId() + " which is not configured for the generate-features goal.\n"); return; @@ -367,22 +371,6 @@ private File getBinaryScannerJarFromRepository() throws PluginExecutionException } } - /* - * Return specificFile if it exists; otherwise return the file with the requested fileName from the - * configDirectory, but only if it exists. Null is returned if the file does not exist in either location. - */ - private File findConfigFile(String fileName, File specificFile) { - if (specificFile != null && specificFile.exists()) { - return specificFile; - } - - File f = new File(configDirectory, fileName); - if (configDirectory != null && f.exists()) { - return f; - } - return null; - } - private ServerConfigXmlDocument getServerXmlDocFromConfig(File serverXml) { if (serverXml == null || !serverXml.exists()) { return null; diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/RunServerMojo.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/RunServerMojo.java index 130502207..70267f3f8 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/RunServerMojo.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/RunServerMojo.java @@ -68,7 +68,11 @@ private void doRunServer() throws MojoExecutionException { // In a multi-module build, the run server goal will only be run on one project (the farthest downstream) and compile will // be run on any relative upstream projects. If this current project in the Maven Reactor is not one of those projects, skip it. - List relevantProjects = getRelevantMultiModuleProjects(graph); + boolean skipJars = true; + if("spring-boot-project".equals(getDeployPackages())) { + skipJars = false; + } + List relevantProjects = getRelevantMultiModuleProjects(graph, skipJars); if (!relevantProjects.contains(project)) { getLog().info("\nSkipping module " + project.getArtifactId() + " which is not included in this invocation of the run goal.\n"); return;