From e4958907a903d4fc9f9574c545cef16727c5aed0 Mon Sep 17 00:00:00 2001 From: Arun Venmany Date: Wed, 22 Jan 2025 15:46:31 +0530 Subject: [PATCH] adding skinnyModule option for maven ear plugin Signed-off-by: Arun Venmany --- .../ear-skinny-modules/pom.xml | 151 ++++++++++++++++++ .../src/main/liberty/config/server.xml | 16 ++ .../guides/multimodules/ConverterAppIT.java | 140 ++++++++++++++++ .../multipleLibertyModules/pom.xml | 3 + .../multipleLibertyModules/rar/pom.xml | 35 ++++ .../net/wasdev/wlp/test/util/Welcome.java | 27 ++++ .../rar/src/main/rar-source/META-INF/ra.xml | 24 +++ .../rar/src/main/resources/License | 0 .../multipleLibertyModules/war2/pom.xml | 59 +++++++ .../wasdev/sample/ejb/web/EJBServlet.java | 45 ++++++ ...ltipleLibertyModulesSkinnyModulesTest.java | 70 ++++++++ .../dev/it/MultipleLibertyModulesTest.java | 2 +- .../maven/applications/DeployMojoSupport.java | 26 ++- .../applications/LooseEarApplication.java | 8 +- 14 files changed, 597 insertions(+), 9 deletions(-) create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/ear-skinny-modules/pom.xml create mode 100755 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/ear-skinny-modules/src/main/liberty/config/server.xml create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/ear-skinny-modules/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/rar/pom.xml create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/src/main/java/net/wasdev/wlp/test/util/Welcome.java create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/src/main/rar-source/META-INF/ra.xml create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/src/main/resources/License create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/war2/pom.xml create mode 100644 liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/war2/src/main/java/wasdev/sample/ejb/web/EJBServlet.java create mode 100644 liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultipleLibertyModulesSkinnyModulesTest.java diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/ear-skinny-modules/pom.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/ear-skinny-modules/pom.xml new file mode 100644 index 000000000..d771bd656 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/ear-skinny-modules/pom.xml @@ -0,0 +1,151 @@ + + + + 4.0.0 + + io.openliberty.guides + guide-maven-multimodules-ear-skinny-modules + 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 + + + io.openliberty.guides + guide-maven-multimodules-war2 + 1.0-SNAPSHOT + war + + + io.openliberty.guides + guide-maven-multimodules-rar + 1.0-SNAPSHOT + rar + + + + org.junit.jupiter + junit-jupiter + 5.6.2 + test + + + + + ${project.artifactId} + + + org.apache.maven.plugins + maven-ear-plugin + 3.3.0 + + lib + + true + + + io.openliberty.guides + guide-maven-multimodules-war + /guide-maven-multimodules-war-1.0-SNAPSHOT.war + + /converter + + + io.openliberty.guides + guide-maven-multimodules-war2 + /guide-maven-multimodules-war2-1.0-SNAPSHOT.war + + /servlet + + + io.openliberty.guides + guide-maven-multimodules-rar + + + + + + + + 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/ear-skinny-modules/src/main/liberty/config/server.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/ear-skinny-modules/src/main/liberty/config/server.xml new file mode 100755 index 000000000..3a626c380 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/ear-skinny-modules/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/ear-skinny-modules/src/test/java/it/io/openliberty/guides/multimodules/ConverterAppIT.java b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/ear-skinny-modules/src/test/java/it/io/openliberty/guides/multimodules/ConverterAppIT.java new file mode 100644 index 000000000..e37880b9f --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/ear-skinny-modules/src/test/java/it/io/openliberty/guides/multimodules/ConverterAppIT.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * 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.File; +import java.io.FileInputStream; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +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 + "/"; + + public final String LOOSE_APP = "target/liberty/wlp/usr/servers/defaultServer/apps/guide-maven-multimodules-ear-skinny-modules.ear.xml"; + + @Test + public void testLooseApplicationFileExist() throws Exception { + File f = new File(LOOSE_APP); + assertTrue(f.exists(),f.getCanonicalFile() + " doesn't exist"); + } + + @Test + public void testLooseApplicationFileContent() throws Exception { + File f = new File(LOOSE_APP); + try (FileInputStream input = new FileInputStream(f);) { + + // get input XML Document + DocumentBuilderFactory inputBuilderFactory = DocumentBuilderFactory.newInstance(); + inputBuilderFactory.setIgnoringComments(true); + inputBuilderFactory.setCoalescing(true); + inputBuilderFactory.setIgnoringElementContentWhitespace(true); + inputBuilderFactory.setValidating(false); + inputBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false); + inputBuilderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false); + DocumentBuilder inputBuilder = inputBuilderFactory.newDocumentBuilder(); + Document inputDoc=inputBuilder.parse(input); + + // parse input XML Document + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = "/archive/file"; + NodeList nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET); + assertEquals(2, nodes.getLength(),"Number of element expected 2 including ear application.xml and manifest.mf"); + assertEquals( "/META-INF/application.xml", + nodes.item(0).getAttributes().getNamedItem("targetInArchive").getNodeValue(),"file targetInArchive attribute value"); + assertEquals( "/META-INF/MANIFEST.MF", + nodes.item(1).getAttributes().getNamedItem("targetInArchive").getNodeValue(),"file targetInArchive attribute value"); + + expression = "/archive/archive"; + nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET); + assertEquals( 4, nodes.getLength(),"Number of elements expected 4 including jar, war, war2, rar"); + assertEquals( "/lib/io.openliberty.guides-guide-maven-multimodules-jar-1.0-SNAPSHOT.jar", + nodes.item(0).getAttributes().getNamedItem("targetInArchive").getNodeValue(),"archive targetInArchive attribute value expected with jar path"); + assertEquals("/guide-maven-multimodules-war-1.0-SNAPSHOT.war", + nodes.item(1).getAttributes().getNamedItem("targetInArchive").getNodeValue(),"archive targetInArchive attribute value expected with war path"); + + assertEquals("/guide-maven-multimodules-war2-1.0-SNAPSHOT.war", + nodes.item(2).getAttributes().getNamedItem("targetInArchive").getNodeValue(),"archive targetInArchive attribute value expected with war2 path"); + + assertEquals("/io.openliberty.guides-guide-maven-multimodules-rar-1.0-SNAPSHOT.rar", + nodes.item(3).getAttributes().getNamedItem("targetInArchive").getNodeValue(),"archive targetInArchive attribute value expected with rar path"); + + expression = "/archive/archive/dir"; + nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET); + assertEquals( 4, nodes.getLength(),"Number of element expected 4"); + + expression = "/archive/archive/file"; + nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET); + assertEquals(5, nodes.getLength(),"Number of element expected 5 including all manifest.mf and library jars"); + expression = "/archive/archive/archive"; + nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET); + assertEquals(0, nodes.getLength(),"Number of element inside any other is expected to be zero, since we are using skinnymodules"); + + } + } + + @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/pom.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/pom.xml index d98cc41a1..0b8439d85 100644 --- a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/pom.xml +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/pom.xml @@ -14,7 +14,10 @@ jar war + war2 ear1 ear2 + rar + ear-skinny-modules diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/pom.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/pom.xml new file mode 100644 index 000000000..af9e6bbba --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/pom.xml @@ -0,0 +1,35 @@ + + 4.0.0 + + io.openliberty.guides + guide-maven-multimodules-rar + 1.0-SNAPSHOT + rar + + UTF-8 + UTF-8 + 1.8 + 1.8 + + + + + + io.openliberty.guides + guide-maven-multimodules-jar + 1.0-SNAPSHOT + + + + + + org.apache.maven.plugins + maven-rar-plugin + + src/main/rar-source/META-INF/ra.xml + src/main/resources + + + + + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/src/main/java/net/wasdev/wlp/test/util/Welcome.java b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/src/main/java/net/wasdev/wlp/test/util/Welcome.java new file mode 100644 index 000000000..911e4a3b6 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/src/main/java/net/wasdev/wlp/test/util/Welcome.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * (c) Copyright IBM Corporation 2025. + * + * 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.util; + +import java.util.ResourceBundle; + +public class Welcome { + + protected static final ResourceBundle messages = ResourceBundle.getBundle("net.wasdev.wlp.test.util.Messages"); + + public static String getMessage(String key) { + return messages.getString(key); + } +} diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/src/main/rar-source/META-INF/ra.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/src/main/rar-source/META-INF/ra.xml new file mode 100644 index 000000000..550c2cbdb --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/src/main/rar-source/META-INF/ra.xml @@ -0,0 +1,24 @@ + + + + + + Hello World Sample + wasdev + 1.0 + Hello World + 1.0 + + wasdev.sample.adapter.helloworld.HelloWorldManagedConnectionFactoryImpl + javax.resource.cci.ConnectionFactory + wasdev.sample.adapter.helloworld.HelloWorldConnectionFactoryImpl + javax.resource.cci.Connection + wasdev.sample.adapter.helloworld.HelloWorldConnectionImpl + NoTransaction + + + false + + + + diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/src/main/resources/License b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/rar/src/main/resources/License new file mode 100644 index 000000000..e69de29bb diff --git a/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/war2/pom.xml b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/war2/pom.xml new file mode 100644 index 000000000..017eaf3ee --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/war2/pom.xml @@ -0,0 +1,59 @@ + + + 4.0.0 + io.openliberty.guides + guide-maven-multimodules-war2 + war + 1.0-SNAPSHOT + guide-maven-multimodules-war2 + http://maven.apache.org + + + + + + commons-io + commons-io + 2.14.0 + runtime + + + javax + javaee-api + 7.0 + 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/war2/src/main/java/wasdev/sample/ejb/web/EJBServlet.java b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/war2/src/main/java/wasdev/sample/ejb/web/EJBServlet.java new file mode 100644 index 000000000..3925d96f7 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/resources/multi-module-projects/multipleLibertyModules/war2/src/main/java/wasdev/sample/ejb/web/EJBServlet.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * (c) Copyright IBM Corporation 2017. + * + * 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 wasdev.sample.ejb.web; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.ejb.EJB; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * A servlet which injects a stateless EJB + */ +@WebServlet({"/", "/sampleServlet"}) +public class EJBServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + + @Override + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws IOException { + PrintWriter writer = response.getWriter(); + + String message = String.valueOf(io.openliberty.guides.multimodules.lib.Converter.getInches(0)); + + writer.println(message); + } +} diff --git a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultipleLibertyModulesSkinnyModulesTest.java b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultipleLibertyModulesSkinnyModulesTest.java new file mode 100644 index 000000000..770404829 --- /dev/null +++ b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultipleLibertyModulesSkinnyModulesTest.java @@ -0,0 +1,70 @@ +/******************************************************************************* + * (c) Copyright IBM Corporation 2025. + * + * 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 MultipleLibertyModulesSkinnyModulesTest extends BaseMultiModuleTest { + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + setUpMultiModule("multipleLibertyModules", "ear-skinny-modules", null); + } + + @Test + public void multipleLibertyModulesPlTest() throws Exception { + String mavenPluginCommand = "mvn io.openliberty.tools:liberty-maven-plugin:"+System.getProperty("mavenPluginVersion")+":dev -pl ear-skinny-modules -am -DhotTests=true"; + + 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)); + + assertTrue(getLogTail(), verifyLogMessageExists("CWWKF0011I", 120000)); + assertTrue(verifyLogMessageExists("Liberty is running in dev mode.", 60000)); + // making sure all integration tests are success. Integration tests contain verification of loose app ear xml file contents + assertTrue(verifyLogMessageExists("Integration tests for guide-maven-multimodules-ear-skinny-modules finished", 60000)); + } +} + diff --git a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultipleLibertyModulesTest.java b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultipleLibertyModulesTest.java index 96ae62563..ccecdc1b1 100644 --- a/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultipleLibertyModulesTest.java +++ b/liberty-maven-plugin/src/it/dev-it/src/test/java/net/wasdev/wlp/test/dev/it/MultipleLibertyModulesTest.java @@ -61,7 +61,7 @@ public void multipleLibertyModulesTest() throws Exception { writer = new BufferedWriter(new OutputStreamWriter(stdin)); - assertTrue(getLogTail(), verifyLogMessageExists("Found multiple independent modules in the Reactor build order: [ear1, ear2]", 30000)); + assertTrue(getLogTail(), verifyLogMessageExists("Found multiple independent modules in the Reactor build order: [ear1, ear2, ear-skinny-modules]", 30000)); } diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java index f890d41ce..5174bb01d 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/DeployMojoSupport.java @@ -21,7 +21,6 @@ import java.io.InputStreamReader; import java.text.MessageFormat; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -266,17 +265,22 @@ protected void installLooseConfigEar(MavenProject proj, LooseConfigData config, case "war": Element warArchive = looseEar.addWarModule(dependencyProject, artifact, getWarSourceDirectory(dependencyProject)); - if (looseEar.isEarSkinnyWars()) { + if (looseEar.isEarSkinnyWars() || looseEar.isEarSkinnyModules()) { // add embedded lib only if they are not a compile dependency in the ear // project. - addSkinnyWarLib(warArchive, dependencyProject, looseEar); + addSkinnyArtifactLib(warArchive, dependencyProject, looseEar); } else { addEmbeddedLib(warArchive, dependencyProject, looseEar, "/WEB-INF/lib/"); } break; case "rar": Element rarArchive = looseEar.addRarModule(dependencyProject, artifact); - addEmbeddedLib(rarArchive, dependencyProject, looseEar, "/"); + // rar dependencies should be removed in case of skinny modules + if (Boolean.TRUE.equals(looseEar.isEarSkinnyModules())) { + addSkinnyArtifactLib(rarArchive, dependencyProject, looseEar); + }else { + addEmbeddedLib(rarArchive, dependencyProject, looseEar, "/"); + } break; default: // use the artifact from local .m2 repo @@ -344,9 +348,17 @@ private void addEmbeddedLib(Element parent, MavenProject warProject, LooseApplic } } - private void addSkinnyWarLib(Element parent, MavenProject warProject, LooseEarApplication looseEar) throws MojoExecutionException, IOException { - Set artifacts = warProject.getArtifacts(); - getLog().debug("Number of compile dependencies for " + warProject.getArtifactId() + " : " + artifacts.size()); + /** + * used for war and rar to add jar files to lib folder + * @param parent + * @param artifactProject + * @param looseEar + * @throws MojoExecutionException + * @throws IOException + */ + private void addSkinnyArtifactLib(Element parent, MavenProject artifactProject, LooseEarApplication looseEar) throws MojoExecutionException, IOException { + Set artifacts = artifactProject.getArtifacts(); + getLog().debug("Number of compile dependencies for " + artifactProject.getArtifactId() + " : " + artifacts.size()); for (Artifact artifact : artifacts) { // skip the embedded library if it is included in the lib directory of the ear diff --git a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/LooseEarApplication.java b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/LooseEarApplication.java index 4285b4767..cceb3b62d 100644 --- a/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/LooseEarApplication.java +++ b/liberty-maven-plugin/src/main/java/io/openliberty/tools/maven/applications/LooseEarApplication.java @@ -309,12 +309,18 @@ public Boolean isEarSkinnyWars() { } } + public Boolean isEarSkinnyModules() { + String skinnyModules = MavenProjectUtil.getPluginConfiguration(project, "org.apache.maven.plugins", + "maven-ear-plugin", "skinnyModules"); + return "true".equals(skinnyModules); + } + public void addWarManifestFile(Element parent, Artifact artifact, MavenProject proj) throws Exception { // the ear plug-in modify the skinnyWar module manifest file in // ${project.build.directory}/temp File newMf = new File(project.getBuild().getDirectory() + "/temp/" + getModuleUri(artifact) + "/META-INF"); if (newMf.exists()) { //use new META-INF dir if it exists - if (isEarSkinnyWars()) { + if (isEarSkinnyWars() || isEarSkinnyModules()) { config.addDir(parent, newMf, "/META-INF"); } else { File manifestFile = MavenProjectUtil.getManifestFile(proj, "maven-war-plugin");