From ed12a3636b0c313d34525562aff203547edd7286 Mon Sep 17 00:00:00 2001 From: Adam Wisniewski Date: Mon, 4 Mar 2024 11:21:24 -0500 Subject: [PATCH] Enhance multi-module check for run goal Signed-off-by: Adam Wisniewski --- .../multiModuleTestCases.md | 6 + .../ear1/pom.xml | 130 +++++++++++++ .../ear1/src/main/liberty/config/server.xml | 16 ++ .../guides/multimodules/ConverterAppIT.java | 66 +++++++ .../ear2/pom.xml | 133 ++++++++++++++ .../ear2/src/main/liberty/config/server.xml | 16 ++ .../guides/multimodules/ConverterAppIT.java | 66 +++++++ .../jar/pom.xml | 41 +++++ .../guides/multimodules/lib/Converter.java | 42 +++++ .../multimodules/lib/ConverterUnitTest.java | 15 ++ .../jar2/pom.xml | 41 +++++ .../guides/multimodules/lib/Converter.java | 42 +++++ .../multimodules/lib/ConverterUnitTest.java | 15 ++ .../pom.xml | 21 +++ .../war/pom.xml | 81 +++++++++ .../guides/multimodules/web/HeightsBean.java | 59 ++++++ .../src/main/resources/META-INF/MANIFEST.mf | 3 + .../war/src/main/webapp/WEB-INF/web.xml | 7 + .../war/src/main/webapp/heights.jsp | 42 +++++ .../war/src/main/webapp/index.jsp | 27 +++ .../mutlimodules/web/HeightsBeanIT.java | 67 +++++++ .../mutlimodules/web/HeightsBeanUnitTest.java | 16 ++ .../wasdev/wlp/test/dev/it/BaseDevTest.java | 5 + ...ltipleLibertyModulesSkipConflictsTest.java | 82 +++++++++ .../tools/maven/ServerFeatureSupport.java | 172 +++++++++++++++++- .../tools/maven/server/DevMojo.java | 90 +-------- .../maven/server/GenerateFeaturesMojo.java | 10 +- .../tools/maven/server/RunServerMojo.java | 9 +- .../maven/server/StartDebugMojoSupport.java | 74 +------- 29 files changed, 1228 insertions(+), 166 deletions(-) create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear1/pom.xml create mode 100755 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear1/src/main/liberty/config/server.xml create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear1/src/test/java/it/io/openliberty/guides/multimodules/ConverterAppIT.java create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear2/pom.xml create mode 100755 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear2/src/main/liberty/config/server.xml create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear2/src/test/java/it/io/openliberty/guides/multimodules/ConverterAppIT.java create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar/pom.xml create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar/src/main/java/io/openliberty/guides/multimodules/lib/Converter.java create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar/src/test/java/io/openliberty/guides/multimodules/lib/ConverterUnitTest.java create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar2/pom.xml create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar2/src/main/java/io/openliberty/guides/multimodules/lib/Converter.java create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar2/src/test/java/io/openliberty/guides/multimodules/lib/ConverterUnitTest.java create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/pom.xml create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/pom.xml create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/java/io/openliberty/guides/multimodules/web/HeightsBean.java create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/resources/META-INF/MANIFEST.mf create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/webapp/WEB-INF/web.xml create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/webapp/heights.jsp create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/webapp/index.jsp create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/test/java/it/io/openliberty/guides/mutlimodules/web/HeightsBeanIT.java create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/test/java/it/io/openliberty/guides/mutlimodules/web/HeightsBeanUnitTest.java create mode 100644 liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultipleLibertyModulesSkipConflictsTest.java diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multiModuleTestCases.md b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multiModuleTestCases.md index 8566d5058..9dc8f1551 100644 --- a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multiModuleTestCases.md +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multiModuleTestCases.md @@ -5,6 +5,12 @@ multipleLibertyModules)  pom, ear1+war+jar, ear2+war+jar - Main pom: ./pom.xml - Tests exist in every module +multipleLibertyModules-skip-conflicts)  pom, ear1+war+jar, ear2+war+jar, jar2 +- Server info in ear1 and ear2 modules +- Main pom: ./pom.xml +- Tests exist in every module +- ear2 has true configured in LMP configuration + sample.ejb) pom, ear+war+ejb - Based on https://github.com/WASdev/sample.ejb diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear1/pom.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear1/pom.xml new file mode 100644 index 000000000..484154d45 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear1/pom.xml @@ -0,0 +1,130 @@ + + + + 4.0.0 + + io.openliberty.guides + guide-maven-multimodules-ear1 + 1.0-SNAPSHOT + ear + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + 9080 + 9443 + + + + + + + + + oss-sonatype + oss-sonatype + https://oss.sonatype.org/content/repositories/snapshots/ + + true + + + false + + + + + + + + io.openliberty.guides + guide-maven-multimodules-jar + 1.0-SNAPSHOT + jar + + + io.openliberty.guides + guide-maven-multimodules-war + 1.0-SNAPSHOT + war + + + + org.junit.jupiter + junit-jupiter + 5.6.2 + test + + + + + ${project.artifactId} + + + org.apache.maven.plugins + maven-ear-plugin + 3.3.0 + + + + io.openliberty.guides + guide-maven-multimodules-jar + /guide-maven-multimodules-jar-1.0-SNAPSHOT.jar + + + io.openliberty.guides + guide-maven-multimodules-war + /guide-maven-multimodules-war-1.0-SNAPSHOT.war + + /converter + + + + + + + + io.openliberty.tools + liberty-maven-plugin + SUB_VERSION + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + + test-compile + + testCompile + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.1.2 + + + + ${liberty.var.default.http.port} + + + ${liberty.var.default.https.port} + + /converter + + + + + + + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear1/src/main/liberty/config/server.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear1/src/main/liberty/config/server.xml new file mode 100755 index 000000000..7edefbfee --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear1/src/main/liberty/config/server.xml @@ -0,0 +1,16 @@ + + + + jsp-2.3 + + + + + + + + + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear1/src/test/java/it/io/openliberty/guides/multimodules/ConverterAppIT.java b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear1/src/test/java/it/io/openliberty/guides/multimodules/ConverterAppIT.java new file mode 100644 index 000000000..916da475c --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear1/src/test/java/it/io/openliberty/guides/multimodules/ConverterAppIT.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2017, 2019 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +package it.io.openliberty.guides.multimodules; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import org.junit.jupiter.api.Test; + +public class ConverterAppIT { + String port = System.getProperty("default.http.port"); + String war = "converter"; + String urlBase = "http://localhost:" + port + "/" + war + "/"; + + @Test + public void testIndexPage() throws Exception { + String url = this.urlBase; + HttpURLConnection con = testRequestHelper(url, "GET"); + assertEquals(200, con.getResponseCode(), "Incorrect response code from " + url); + assertTrue(testBufferHelper(con).contains("Enter the height in centimeters"), + "Incorrect response from " + url); + } + + @Test + public void testHeightsPage() throws Exception { + String url = this.urlBase + "heights.jsp?heightCm=10"; + HttpURLConnection con = testRequestHelper(url, "POST"); + assertTrue(testBufferHelper(con).contains("3 inches"), + "Incorrect response from " + url); + } + + private HttpURLConnection testRequestHelper(String url, String method) + throws Exception { + URL obj = new URL(url); + HttpURLConnection con = (HttpURLConnection) obj.openConnection(); + // optional default is GET + con.setRequestMethod(method); + return con; + } + + private String testBufferHelper(HttpURLConnection con) throws Exception { + BufferedReader in = new BufferedReader( + new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer response = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + return response.toString(); + } + +} diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear2/pom.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear2/pom.xml new file mode 100644 index 000000000..f7e4a979d --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear2/pom.xml @@ -0,0 +1,133 @@ + + + + 4.0.0 + + io.openliberty.guides + guide-maven-multimodules-ear2 + 1.0-SNAPSHOT + ear + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + 9081 + 9444 + + + + + + + + + oss-sonatype + oss-sonatype + https://oss.sonatype.org/content/repositories/snapshots/ + + true + + + false + + + + + + + + io.openliberty.guides + guide-maven-multimodules-jar + 1.0-SNAPSHOT + jar + + + io.openliberty.guides + guide-maven-multimodules-war + 1.0-SNAPSHOT + war + + + + org.junit.jupiter + junit-jupiter + 5.6.2 + test + + + + + ${project.artifactId} + + + org.apache.maven.plugins + maven-ear-plugin + 3.3.0 + + + + io.openliberty.guides + guide-maven-multimodules-jar + /guide-maven-multimodules-jar-1.0-SNAPSHOT.jar + + + io.openliberty.guides + guide-maven-multimodules-war + /guide-maven-multimodules-war-1.0-SNAPSHOT.war + + /converter + + + + + + + + io.openliberty.tools + liberty-maven-plugin + SUB_VERSION + + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.11.0 + + + test-compile + + testCompile + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.1.2 + + + + ${liberty.var.default.http.port} + + + ${liberty.var.default.https.port} + + /converter + + + + + + + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear2/src/main/liberty/config/server.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear2/src/main/liberty/config/server.xml new file mode 100755 index 000000000..a5eee3187 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear2/src/main/liberty/config/server.xml @@ -0,0 +1,16 @@ + + + + jsp-2.3 + + + + + + + + + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear2/src/test/java/it/io/openliberty/guides/multimodules/ConverterAppIT.java b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear2/src/test/java/it/io/openliberty/guides/multimodules/ConverterAppIT.java new file mode 100644 index 000000000..916da475c --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/ear2/src/test/java/it/io/openliberty/guides/multimodules/ConverterAppIT.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2017, 2019 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +package it.io.openliberty.guides.multimodules; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import org.junit.jupiter.api.Test; + +public class ConverterAppIT { + String port = System.getProperty("default.http.port"); + String war = "converter"; + String urlBase = "http://localhost:" + port + "/" + war + "/"; + + @Test + public void testIndexPage() throws Exception { + String url = this.urlBase; + HttpURLConnection con = testRequestHelper(url, "GET"); + assertEquals(200, con.getResponseCode(), "Incorrect response code from " + url); + assertTrue(testBufferHelper(con).contains("Enter the height in centimeters"), + "Incorrect response from " + url); + } + + @Test + public void testHeightsPage() throws Exception { + String url = this.urlBase + "heights.jsp?heightCm=10"; + HttpURLConnection con = testRequestHelper(url, "POST"); + assertTrue(testBufferHelper(con).contains("3 inches"), + "Incorrect response from " + url); + } + + private HttpURLConnection testRequestHelper(String url, String method) + throws Exception { + URL obj = new URL(url); + HttpURLConnection con = (HttpURLConnection) obj.openConnection(); + // optional default is GET + con.setRequestMethod(method); + return con; + } + + private String testBufferHelper(HttpURLConnection con) throws Exception { + BufferedReader in = new BufferedReader( + new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer response = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + return response.toString(); + } + +} diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar/pom.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar/pom.xml new file mode 100644 index 000000000..c3611cb0f --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + io.openliberty.guides + guide-maven-multimodules-jar + 1.0-SNAPSHOT + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + + org.junit.jupiter + junit-jupiter + 5.6.2 + test + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + + + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar/src/main/java/io/openliberty/guides/multimodules/lib/Converter.java b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar/src/main/java/io/openliberty/guides/multimodules/lib/Converter.java new file mode 100644 index 000000000..4f14c700c --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar/src/main/java/io/openliberty/guides/multimodules/lib/Converter.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2017 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +package io.openliberty.guides.multimodules.lib; + +public class Converter { + + public static int getFeet(int cm) { + int feet = (int) (cm / 30.48); + return feet; + } + + public static int getInches(int cm) { + double feet = cm / 30.48; + int inches = (int) (cm / 2.54) - ((int) feet * 12); + return inches; + } + + public static int sum(int a, int b) { + return a + b; + } + + public static int diff(int a, int b) { + return a - b; + } + + public static int product(int a, int b) { + return a * b; + } + + public static int quotient(int a, int b) { + return a / b; + } + +} diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar/src/test/java/io/openliberty/guides/multimodules/lib/ConverterUnitTest.java b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar/src/test/java/io/openliberty/guides/multimodules/lib/ConverterUnitTest.java new file mode 100644 index 000000000..e46adcbec --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar/src/test/java/io/openliberty/guides/multimodules/lib/ConverterUnitTest.java @@ -0,0 +1,15 @@ +package io.openliberty.guides.multimodules.lib; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ConverterUnitTest { + + @Test + public void testHeightFeet() { + int feet = Converter.getFeet(61); + assertEquals(2, feet); + } + +} \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar2/pom.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar2/pom.xml new file mode 100644 index 000000000..9471bde97 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar2/pom.xml @@ -0,0 +1,41 @@ + + + + 4.0.0 + + io.openliberty.guides + guide-maven-multimodules-jar2 + 1.0-SNAPSHOT + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + + org.junit.jupiter + junit-jupiter + 5.6.2 + test + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + + + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar2/src/main/java/io/openliberty/guides/multimodules/lib/Converter.java b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar2/src/main/java/io/openliberty/guides/multimodules/lib/Converter.java new file mode 100644 index 000000000..4f14c700c --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar2/src/main/java/io/openliberty/guides/multimodules/lib/Converter.java @@ -0,0 +1,42 @@ +/******************************************************************************* + * Copyright (c) 2017 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +package io.openliberty.guides.multimodules.lib; + +public class Converter { + + public static int getFeet(int cm) { + int feet = (int) (cm / 30.48); + return feet; + } + + public static int getInches(int cm) { + double feet = cm / 30.48; + int inches = (int) (cm / 2.54) - ((int) feet * 12); + return inches; + } + + public static int sum(int a, int b) { + return a + b; + } + + public static int diff(int a, int b) { + return a - b; + } + + public static int product(int a, int b) { + return a * b; + } + + public static int quotient(int a, int b) { + return a / b; + } + +} diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar2/src/test/java/io/openliberty/guides/multimodules/lib/ConverterUnitTest.java b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar2/src/test/java/io/openliberty/guides/multimodules/lib/ConverterUnitTest.java new file mode 100644 index 000000000..e46adcbec --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/jar2/src/test/java/io/openliberty/guides/multimodules/lib/ConverterUnitTest.java @@ -0,0 +1,15 @@ +package io.openliberty.guides.multimodules.lib; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class ConverterUnitTest { + + @Test + public void testHeightFeet() { + int feet = Converter.getFeet(61); + assertEquals(2, feet); + } + +} \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/pom.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/pom.xml new file mode 100644 index 000000000..ff1ae0e92 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/pom.xml @@ -0,0 +1,21 @@ + + + + 4.0.0 + + io.openliberty.guides + guide-maven-multimodules + 1.0-SNAPSHOT + pom + + + jar + jar2 + war + ear1 + ear2 + + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/pom.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/pom.xml new file mode 100644 index 000000000..44e7bf0c9 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/pom.xml @@ -0,0 +1,81 @@ + + + + 4.0.0 + + io.openliberty.guides + guide-maven-multimodules-war + war + 1.0-SNAPSHOT + guide-maven-multimodules-war + http://maven.apache.org + + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + + + + + + + javax.servlet + javax.servlet-api + 4.0.1 + provided + + + jakarta.platform + jakarta.jakartaee-api + 8.0.0 + provided + + + org.eclipse.microprofile + microprofile + 3.3 + pom + provided + + + + io.openliberty.guides + guide-maven-multimodules-jar + 1.0-SNAPSHOT + + + + org.junit.jupiter + junit-jupiter + 5.6.2 + test + + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.1.2 + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.1.2 + + + + + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/java/io/openliberty/guides/multimodules/web/HeightsBean.java b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/java/io/openliberty/guides/multimodules/web/HeightsBean.java new file mode 100644 index 000000000..585b4e3d0 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/java/io/openliberty/guides/multimodules/web/HeightsBean.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2017, 2019 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +package io.openliberty.guides.multimodules.web; + +public class HeightsBean implements java.io.Serializable { + private String heightCm = null; + private String heightFeet = null; + private String heightInches = null; + private int cm = 0; + private int feet = 0; + private int inches = 0; + + public HeightsBean() { + + } + + // Capitalize the first letter of the name i.e. first letter after get + // If first letter is not capitalized, it must match the property name in + // index.jsp + public String getHeightCm() { + return heightCm; + } + + public String getHeightFeet() { + return heightFeet; + } + + public String getHeightInches() { + return heightInches; + } + + public void setHeightCm(String heightcm) { + this.heightCm = heightcm; + } + + // Need an input as placeholder, you can choose not to use the input + public void setHeightFeet(String heightfeet) { + this.cm = Integer.valueOf(heightCm); + this.feet = io.openliberty.guides.multimodules.lib.Converter.getFeet(cm); + String result = String.valueOf(feet); + this.heightFeet = result; + } + + public void setHeightInches(String heightinches) { + this.cm = Integer.valueOf(heightCm); + this.inches = io.openliberty.guides.multimodules.lib.Converter.getInches(cm); + String result = String.valueOf(inches); + this.heightInches = result; + } + +} \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/resources/META-INF/MANIFEST.mf b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/resources/META-INF/MANIFEST.mf new file mode 100644 index 000000000..ed50078e5 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/resources/META-INF/MANIFEST.mf @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Ant-Version: Apache Ant 1.7.1 +Created-By: 2.6 (IBM Corporation) \ No newline at end of file diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/webapp/WEB-INF/web.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..8bed23c46 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,7 @@ + + + + Archetype Created Web Application + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/webapp/heights.jsp b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/webapp/heights.jsp new file mode 100644 index 000000000..331a58413 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/webapp/heights.jsp @@ -0,0 +1,42 @@ +<%-- +******************************************************************************* + * Copyright (c) 2017 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + ******************************************************************************* +--%> + + +Height Converter + + +

Height Converter

+ + + + + + +

+ Height in centimeters: + + cm +

+ +
+ +

+ Height in feet and inches: + + feet + + inches +

+ + + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/webapp/index.jsp b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/webapp/index.jsp new file mode 100644 index 000000000..e9ea63ce0 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/main/webapp/index.jsp @@ -0,0 +1,27 @@ +<%-- +******************************************************************************* + * Copyright (c) 2017 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + ******************************************************************************* +--%> + + +Height Converter + + +

Height Converter

+

Enter the height in centimeters

+ +
+ cm
+
+ + + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/test/java/it/io/openliberty/guides/mutlimodules/web/HeightsBeanIT.java b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/test/java/it/io/openliberty/guides/mutlimodules/web/HeightsBeanIT.java new file mode 100644 index 000000000..4f2462395 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/test/java/it/io/openliberty/guides/mutlimodules/web/HeightsBeanIT.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2017, 2019 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - Initial implementation + *******************************************************************************/ +package it.io.openliberty.guides.multimodules.web; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; + +import org.junit.jupiter.api.Test; + +public class HeightsBeanIT { + String war = "converter"; + String urlBase = "http://localhost:" + "9080" + "/" + war + "/"; + + @Test + public void testIndexPage() throws Exception { + String url = this.urlBase; + HttpURLConnection con = testRequestHelper(url, "GET"); + assertEquals(200, con.getResponseCode(), "Incorrect response code from " + url); + assertTrue(testBufferHelper(con).contains("Enter the height in centimeters"), + "Incorrect response from " + url); + } + + @Test + public void testHeightsPage() throws Exception { + String url = this.urlBase + "heights.jsp?heightCm=10"; + HttpURLConnection con = testRequestHelper(url, "POST"); + assertTrue(testBufferHelper(con).contains("3 inches"), + "Incorrect response from " + url); + } + + private HttpURLConnection testRequestHelper(String url, String method) + throws Exception { + URL obj = new URL(url); + HttpURLConnection con = (HttpURLConnection) obj.openConnection(); + // optional default is GET + con.setRequestMethod(method); + return con; + } + + private String testBufferHelper(HttpURLConnection con) throws Exception { + BufferedReader in = new BufferedReader( + new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer response = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + response.append(inputLine); + } + in.close(); + return response.toString(); + } + +} + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/test/java/it/io/openliberty/guides/mutlimodules/web/HeightsBeanUnitTest.java b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/test/java/it/io/openliberty/guides/mutlimodules/web/HeightsBeanUnitTest.java new file mode 100644 index 000000000..76dfca460 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules-skip-conflicts/war/src/test/java/it/io/openliberty/guides/mutlimodules/web/HeightsBeanUnitTest.java @@ -0,0 +1,16 @@ +package it.io.openliberty.guides.multimodules.web; + +import org.junit.jupiter.api.Test; +import io.openliberty.guides.multimodules.web.HeightsBean; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class HeightsBeanUnitTest { + + @Test + public void testGetHeightCm() { + HeightsBean heightBean = new HeightsBean(); + heightBean.setHeightCm("2"); + assertEquals("2", heightBean.getHeightCm()); + } +} \ 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/BaseDevTest.java b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/BaseDevTest.java index 27086ed75..ea3795bab 100644 --- a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/BaseDevTest.java +++ b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/BaseDevTest.java @@ -467,6 +467,11 @@ protected static boolean verifyLogMessageExists(String message, int timeout, Fil } return false; } + + protected static boolean verifyLogMessageDoesNotExist(String message, int timeout) + throws InterruptedException, FileNotFoundException, IOException { + return verifyLogMessageDoesNotExist(message, timeout, logFile); + } protected static boolean verifyLogMessageDoesNotExist(String message, int timeout, File log) throws InterruptedException, FileNotFoundException, IOException { diff --git a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultipleLibertyModulesSkipConflictsTest.java b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultipleLibertyModulesSkipConflictsTest.java new file mode 100644 index 000000000..abd7768b7 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultipleLibertyModulesSkipConflictsTest.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * (c) Copyright IBM Corporation 2024. + * + * 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.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.HttpException; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.httpclient.methods.GetMethod; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.nio.file.Files; +import java.util.concurrent.TimeUnit; + +import org.apache.commons.io.FileUtils; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class MultipleLibertyModulesSkipConflictsTest extends BaseMultiModuleTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + setUpMultiModule("multipleLibertyModules-skip-conflicts", null /* this param is not used in this scenario */, null); + } + + /** + * The multipleLibertyModules-skip-conflicts project has the following module chains: + * + * jar->war->ear + * jar->war->ear2 + * jar2 + * + * The jar2 module should be skipped implicitly when calling dev mode since dev mode cannot run in a jar project. + * The ear2 module should also be skipped bacause skip is explicitly set in the plugin configuration. + * @throws Exception + */ + @Test + public void MultipleLibertyModulesSkipConflictsTest() throws Exception { + String mavenPluginCommand = "mvn io.openliberty.tools:liberty-maven-plugin:"+System.getProperty("mavenPluginVersion")+":dev"; + + 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 skipping the jar2 project + assertTrue(getLogTail(), verifyLogMessageExists("Skipping module guide-maven-multimodules-jar2 which is not configured for dev mode", 30000)); + + // Make sure neither the ear2 or jar2 projects cause conflicts + assertTrue(getLogTail(), verifyLogMessageDoesNotExist("Found multiple independent modules in the Reactor build order", 30000)); + } +} + 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 958411ee5..239874541 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 @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2021, 2023. + * (C) Copyright IBM Corporation 2021, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,23 +15,45 @@ */ package io.openliberty.tools.maven; +import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId; +import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; +import static org.twdata.maven.mojoexecutor.MojoExecutor.version; + import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; import org.apache.maven.execution.ProjectDependencyGraph; +import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginManagement; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.descriptor.PluginDescriptor; +import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.util.xml.Xpp3Dom; import io.openliberty.tools.common.plugins.util.ServerFeatureUtil; +import io.openliberty.tools.maven.utils.DevHelper; +import io.openliberty.tools.maven.utils.ExecuteMojoUtil; public abstract class ServerFeatureSupport extends BasicSupport { + + private static final String LIBERTY_MAVEN_PLUGIN_GROUP_ID = "io.openliberty.tools"; + private static final String LIBERTY_MAVEN_PLUGIN_ARTIFACT_ID = "liberty-maven-plugin"; private ServerFeatureUtil servUtil; + + /** + * The current plugin's descriptor. This is auto-filled by Maven 3. + */ + @Parameter( defaultValue = "${plugin}", readonly = true ) + private PluginDescriptor plugin; protected class ServerFeatureMojoUtil extends ServerFeatureUtil { @@ -112,7 +134,7 @@ protected ServerFeatureUtil getServerFeatureUtil(boolean suppressLogs, Map multiModules = potentialTopModule.getModules(); if (multiModules != null) { for (String module : multiModules) { @@ -191,6 +213,91 @@ protected static boolean isSubModule(MavenProject potentialTopModule, MavenProje } return false; } + + /** + * Get the list of projects that are relevant when certain goals (e.g. "dev" and "run") are executed + * against a multi-module project. Relevant projects are any projects in the same downstream/upstream flow. + * Jar projects without any downstream modules are implicitly ignored and any projects with skip=true + * configured in the plugin configuration are also ignored. If multiple "streams" still exist, a MojoExecutionException + * is thrown logging the conflict. + * + * + * @param graph + * @return + * @throws MojoExecutionException + */ + protected List getRelevantMultiModuleProjects(ProjectDependencyGraph graph) throws MojoExecutionException { + getLog().debug("Resolve relevant multi-module projects"); + + List sortedReactorProjects = graph.getSortedProjects(); + Set conflicts = new LinkedHashSet(); // keeps the order of items added in + + // A leaf here is a module without any downstream modules depending on it + List leaves = new ArrayList(); + 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")) { + getLog().debug(reactorProject.getArtifactId() + " is a jar project - Ignoring"); + } else { + leaves.add(reactorProject); + } + } + } + + // At this point, the only leaves we should have is one final downstream project and the parent pom project. + // Loop through and find any conflicts. + for (MavenProject leaf1 : leaves) { + for (MavenProject leaf2 : leaves) { + // Check that the leaves are not the same module and that one of the leaves is not the parent. + if (leaf1 != leaf2 && !(isSubModule(leaf2, leaf1) || isSubModule(leaf1, leaf2)) ) { + conflicts.add(leaf1); + conflicts.add(leaf2); + } + } + } + + if (conflicts.isEmpty() ) { + List devModeProjects = new ArrayList(); + for (MavenProject leaf : leaves) { + devModeProjects.addAll(graph.getUpstreamProjects(leaf, true)); + devModeProjects.add(leaf); + } + + getLog().debug("Resolved multi-module projects: "); + for (MavenProject project : devModeProjects) { + getLog().debug(project.getArtifactId()); + } + return devModeProjects; + } else { + + List conflictModuleRelativeDirs = new ArrayList(); + for (MavenProject conflict : conflicts) { + // Make the module path relative to the multi-module project directory + conflictModuleRelativeDirs.add(getModuleRelativePath(conflict)); + } + + throw new MojoExecutionException("Found multiple independent modules in the Reactor build order: " + + conflictModuleRelativeDirs + + ". Skip a conflicting module in the Liberty configuration or specify the module containing the Liberty configuration that you want to use for the server by including the following parameters in the Maven command: -pl -am"); + } + } + + private boolean skipConfigured(MavenProject project) { + + // Properties that are set in the pom file + Properties props = project.getProperties(); + + // Properties that are set by user via CLI parameters + Properties userProps = session.getUserProperties(); + Plugin libertyPlugin = getLibertyPluginForProject(project); + Xpp3Dom config = ExecuteMojoUtil.getPluginGoalConfig(libertyPlugin, "dev", getLog()); + + return DevHelper.getBooleanFlag(config, userProps, props, "skip"); + } /** * If there was a previous module without downstream projects, assume Liberty @@ -235,5 +342,62 @@ protected boolean containsPreviousLibertyModule(ProjectDependencyGraph graph) { protected String getModuleRelativePath(MavenProject module) { return multiModuleProjectDirectory.toPath().relativize(module.getBasedir().toPath()).toString(); } - + + protected Plugin getLibertyPluginForProject(MavenProject currentProject) { + // Try getting the version from Maven 3's plugin descriptor + String version = null; + if (plugin != null && plugin.getPlugin() != null) { + version = plugin.getVersion(); + getLog().debug("Setting plugin version to " + version); + } + Plugin projectPlugin = currentProject.getPlugin(LIBERTY_MAVEN_PLUGIN_GROUP_ID + ":" + LIBERTY_MAVEN_PLUGIN_ARTIFACT_ID); + if (projectPlugin == null) { + getLog().debug("Did not find liberty-maven-plugin configured in currentProject: "+currentProject.toString()); + projectPlugin = getPluginFromPluginManagement(LIBERTY_MAVEN_PLUGIN_GROUP_ID, LIBERTY_MAVEN_PLUGIN_ARTIFACT_ID, currentProject); + } else { + getLog().debug("Found liberty-maven-plugin configured in currentProject: "+currentProject.toString()); + } + if (projectPlugin == null) { + getLog().debug("Did not find liberty-maven-plugin in pluginManagement in currentProject: "+currentProject.toString()); + projectPlugin = plugin(LIBERTY_MAVEN_PLUGIN_GROUP_ID, LIBERTY_MAVEN_PLUGIN_ARTIFACT_ID, "LATEST"); + } + if (version != null) { + projectPlugin.setVersion(version); + } + return projectPlugin; + } + + protected Plugin getPluginFromPluginManagement(String groupId, String artifactId, MavenProject currentProject) { + Plugin retVal = null; + PluginManagement pm = currentProject.getPluginManagement(); + if (pm != null) { + for (Plugin p : pm.getPlugins()) { + if (groupId.equals(p.getGroupId()) && artifactId.equals(p.getArtifactId())) { + retVal = p; + break; + } + } + } + return retVal; + } + + /** + * Given the groupId and artifactId get the corresponding plugin for the + * specified project + * + * @param groupId + * @param artifactId + * @param currentProject + * @return Plugin + */ + protected Plugin getPluginForProject(String groupId, String artifactId, MavenProject currentProject) { + Plugin plugin = currentProject.getPlugin(groupId + ":" + artifactId); + if (plugin == null) { + plugin = getPluginFromPluginManagement(groupId, artifactId, currentProject); + } + if (plugin == null) { + plugin = plugin(groupId(groupId), artifactId(artifactId), version("RELEASE")); + } + return plugin; + } } 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 8aa0ca547..fe8938c8d 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 @@ -32,7 +32,6 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Objects; @@ -1281,9 +1280,9 @@ 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 devModeProjects = getMultiModuleDevModeProjects(graph); - if (!devModeProjects.contains(project)) { - getLog().info("\nSkipping dev goal.\n"); + List relevantProjects = getRelevantMultiModuleProjects(graph); + if (!relevantProjects.contains(project)) { + getLog().info("\nSkipping module " + project.getArtifactId() + " which is not configured for dev mode.\n"); return; } @@ -1571,89 +1570,6 @@ public void execute() throws MojoExecutionException { doDevMode(); } - - protected List getMultiModuleDevModeProjects(ProjectDependencyGraph graph) throws MojoExecutionException { - getLog().debug("Resolve dev mode projects"); - - List sortedReactorProjects = graph.getSortedProjects(); - Set conflicts = new LinkedHashSet(); // keeps the order of items added in - - // A leaf here is a module without any downstream modules depending on it - List leaves = new ArrayList(); - for (MavenProject reactorProject : sortedReactorProjects) { - if (graph.getDownstreamProjects(reactorProject, true).isEmpty()) { - leaves.add(reactorProject); - getLog().debug("Found final downstream project: " + reactorProject.getArtifactId()); - } - } - - // Remove jar projects since these are not relavent to dev mode - List jarLeaves = new ArrayList(); - for (MavenProject leaf : leaves) { - if (leaf.getPackaging().equals("jar")) { - jarLeaves.add(leaf); - getLog().debug("Removing jar project: " + leaf.getArtifactId()); - } - } - leaves.removeAll(jarLeaves); - - // Remove any projects that are configured to be skipped - List skipLeaves = new ArrayList(); - for (MavenProject leaf : leaves) { - - // Properties that are set in the pom file - Properties props = leaf.getProperties(); - - // Properties that are set by user via CLI parameters - Properties userProps = session.getUserProperties(); - Plugin libertyPlugin = getLibertyPluginForProject(leaf); - Xpp3Dom config = ExecuteMojoUtil.getPluginGoalConfig(libertyPlugin, "dev", getLog()); - - boolean skipGoal = DevHelper.getBooleanFlag(config, userProps, props, "skip"); - - if (skipGoal) { - getLog().debug("Skip configured on project: " + leaf.getArtifactId()); - skipLeaves.add(leaf); - } - } - leaves.removeAll(skipLeaves); - - // Find any remaining conflicts - for (MavenProject leaf1 : leaves) { - for (MavenProject leaf2 : leaves) { - if (leaf1 != leaf2 && !(isSubModule(leaf2, leaf1) || isSubModule(leaf1, leaf2)) ) { - conflicts.add(leaf1); - conflicts.add(leaf2); - } - } - } - - if (conflicts.isEmpty() ) { - List devModeProjects = new ArrayList(); - for (MavenProject leaf : leaves) { - devModeProjects.addAll(graph.getUpstreamProjects(leaf, true)); - devModeProjects.add(leaf); - } - - for (MavenProject project : devModeProjects) { - getLog().debug("Dev mode projects list: "); - getLog().debug(project.getArtifactId()); - } - return devModeProjects; - } else { - - List conflictModuleRelativeDirs = new ArrayList(); - for (MavenProject conflict : conflicts) { - // Make the module path relative to the multi-module project directory - conflictModuleRelativeDirs.add(getModuleRelativePath(conflict)); - } - - throw new MojoExecutionException("Found multiple independent modules in the Reactor build order: " - + conflictModuleRelativeDirs - + ". Skip a conflicting module in the Liberty configuration or specify the module containing the Liberty configuration that you want to use for the server by including the following parameters in the Maven command: -pl -am"); - } - } - /** * Update map with list of parent poms and their subsequent child poms 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 7e5fe9fac..557d0d046 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 @@ -116,7 +116,15 @@ private void generateFeatures() throws MojoExecutionException, PluginExecutionEx ProjectDependencyGraph graph = session.getProjectDependencyGraph(); List upstreamProjects = new ArrayList(); if (graph != null) { - checkMultiModuleConflicts(graph); + + // 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); + if (!relevantProjects.contains(project)) { + getLog().info("\nSkipping module " + project.getArtifactId() + " which is not configured for the generate-features goal.\n"); + return; + } + List downstreamProjects = graph.getDownstreamProjects(project, true); if (!downstreamProjects.isEmpty()) { getLog().debug("Downstream projects: " + downstreamProjects); 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 d8b39a446..4aa27d7c7 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 @@ -65,7 +65,14 @@ private void doRunServer() throws MojoExecutionException { boolean hasDownstreamProjects = false; ProjectDependencyGraph graph = session.getProjectDependencyGraph(); if (graph != null) { - checkMultiModuleConflicts(graph); + + // 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); + if (!relevantProjects.contains(project)) { + getLog().info("\nSkipping module " + project.getArtifactId() + " which is not configured for the run goal.\n"); + return; + } List downstreamProjects = graph.getDownstreamProjects(project, true); if (!downstreamProjects.isEmpty()) { diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java index 224b54a90..953f4eadb 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/server/StartDebugMojoSupport.java @@ -1,5 +1,5 @@ /** - * (C) Copyright IBM Corporation 2014, 2023. + * (C) Copyright IBM Corporation 2014, 2024. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,16 +15,12 @@ */ package io.openliberty.tools.maven.server; -import static org.twdata.maven.mojoexecutor.MojoExecutor.artifactId; import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration; import static org.twdata.maven.mojoexecutor.MojoExecutor.element; import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo; import static org.twdata.maven.mojoexecutor.MojoExecutor.executionEnvironment; import static org.twdata.maven.mojoexecutor.MojoExecutor.goal; -import static org.twdata.maven.mojoexecutor.MojoExecutor.groupId; import static org.twdata.maven.mojoexecutor.MojoExecutor.name; -import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; -import static org.twdata.maven.mojoexecutor.MojoExecutor.version; import java.io.BufferedReader; import java.io.File; @@ -54,10 +50,8 @@ import org.apache.maven.artifact.versioning.ComparableVersion; import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Plugin; -import org.apache.maven.model.PluginManagement; import org.apache.maven.plugin.BuildPluginManager; import org.apache.maven.plugin.MojoExecutionException; -import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; @@ -77,8 +71,6 @@ */ public abstract class StartDebugMojoSupport extends ServerFeatureSupport { - private static final String LIBERTY_MAVEN_PLUGIN_GROUP_ID = "io.openliberty.tools"; - private static final String LIBERTY_MAVEN_PLUGIN_ARTIFACT_ID = "liberty-maven-plugin"; protected static final String HEADER = "# Generated by liberty-maven-plugin"; private static final String LIBERTY_CONFIG_MAVEN_PROPS = "(^liberty\\.(env|jvm|bootstrap|var|defaultVar)\\.).+"; private static final Pattern pattern = Pattern.compile(LIBERTY_CONFIG_MAVEN_PROPS); @@ -131,12 +123,6 @@ public abstract class StartDebugMojoSupport extends ServerFeatureSupport { @Parameter protected List jvmOptions; - /** - * The current plugin's descriptor. This is auto-filled by Maven 3. - */ - @Parameter( defaultValue = "${plugin}", readonly = true ) - private PluginDescriptor plugin; - private enum PropertyType { BOOTSTRAP("liberty.bootstrap."), ENV("liberty.env."), @@ -256,68 +242,10 @@ protected Plugin getPlugin(String groupId, String artifactId) { return getPluginForProject(groupId, artifactId, project); } - /** - * Given the groupId and artifactId get the corresponding plugin for the - * specified project - * - * @param groupId - * @param artifactId - * @param currentProject - * @return Plugin - */ - protected Plugin getPluginForProject(String groupId, String artifactId, MavenProject currentProject) { - Plugin plugin = currentProject.getPlugin(groupId + ":" + artifactId); - if (plugin == null) { - plugin = getPluginFromPluginManagement(groupId, artifactId, currentProject); - } - if (plugin == null) { - plugin = plugin(groupId(groupId), artifactId(artifactId), version("RELEASE")); - } - return plugin; - } - protected Plugin getLibertyPlugin() { return getLibertyPluginForProject(project); } - protected Plugin getLibertyPluginForProject(MavenProject currentProject) { - // Try getting the version from Maven 3's plugin descriptor - String version = null; - if (plugin != null && plugin.getPlugin() != null) { - version = plugin.getVersion(); - getLog().debug("Setting plugin version to " + version); - } - Plugin projectPlugin = currentProject.getPlugin(LIBERTY_MAVEN_PLUGIN_GROUP_ID + ":" + LIBERTY_MAVEN_PLUGIN_ARTIFACT_ID); - if (projectPlugin == null) { - getLog().debug("Did not find liberty-maven-plugin configured in currentProject: "+currentProject.toString()); - projectPlugin = getPluginFromPluginManagement(LIBERTY_MAVEN_PLUGIN_GROUP_ID, LIBERTY_MAVEN_PLUGIN_ARTIFACT_ID, currentProject); - } else { - getLog().debug("Found liberty-maven-plugin configured in currentProject: "+currentProject.toString()); - } - if (projectPlugin == null) { - getLog().debug("Did not find liberty-maven-plugin in pluginManagement in currentProject: "+currentProject.toString()); - projectPlugin = plugin(LIBERTY_MAVEN_PLUGIN_GROUP_ID, LIBERTY_MAVEN_PLUGIN_ARTIFACT_ID, "LATEST"); - } - if (version != null) { - projectPlugin.setVersion(version); - } - return projectPlugin; - } - - protected Plugin getPluginFromPluginManagement(String groupId, String artifactId, MavenProject currentProject) { - Plugin retVal = null; - PluginManagement pm = currentProject.getPluginManagement(); - if (pm != null) { - for (Plugin p : pm.getPlugins()) { - if (groupId.equals(p.getGroupId()) && artifactId.equals(p.getArtifactId())) { - retVal = p; - break; - } - } - } - return retVal; - } - protected void runLibertyMojoCreate() throws MojoExecutionException { Xpp3Dom config = ExecuteMojoUtil.getPluginGoalConfig(getLibertyPlugin(), "create", getLog()); runLibertyMojo("create", config);