Skip to content

Commit

Permalink
adding skinnyModule option for maven ear plugin
Browse files Browse the repository at this point in the history
Signed-off-by: Arun Venmany <[email protected]>
  • Loading branch information
arunvenmany-ibm committed Jan 22, 2025
1 parent dc36c69 commit e495890
Show file tree
Hide file tree
Showing 14 changed files with 597 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<?xml version='1.0' encoding='utf-8'?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-ear-skinny-modules</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ear</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- Liberty configuration -->
<liberty.var.default.http.port>9080</liberty.var.default.http.port>
<liberty.var.default.https.port>9443</liberty.var.default.https.port>
<!-- Test Configuration -->
<!-- <skipTests>true</skipTests> -->
<!-- <skipITs>true</skipITs> -->
<!-- <skipUTs>true</skipUTs> -->
</properties>
<repositories>
<!-- Sonatype repository used to get the latest binary scanner jar -->
<repository>
<id>oss-sonatype</id>
<name>oss-sonatype</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>

<dependencies>
<!-- web and jar modules as dependencies -->
<dependency>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-jar</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-war</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-war2</artifactId>
<version>1.0-SNAPSHOT</version>
<type>war</type>
</dependency>
<dependency>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-rar</artifactId>
<version>1.0-SNAPSHOT</version>
<type>rar</type>
</dependency>
<!-- For tests -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<!-- Set skinnyModules -->
<skinnyModules>true</skinnyModules>
<modules>
<webModule>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-war</artifactId>
<uri>/guide-maven-multimodules-war-1.0-SNAPSHOT.war</uri>
<!-- Set custom context root -->
<contextRoot>/converter</contextRoot>
</webModule>
<webModule>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-war2</artifactId>
<uri>/guide-maven-multimodules-war2-1.0-SNAPSHOT.war</uri>
<!-- Set custom context root -->
<contextRoot>/servlet</contextRoot>
</webModule>
<rarModule>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-rar</artifactId>
</rarModule>
</modules>
</configuration>
</plugin>

<!-- Enable liberty-maven plugin -->
<plugin>
<groupId>io.openliberty.tools</groupId>
<artifactId>liberty-maven-plugin</artifactId>
<version>SUB_VERSION</version>
</plugin>

<!-- Since the package type is ear,
need to run testCompile to compile the tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<executions>
<execution>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Plugin to run integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<systemPropertyVariables>
<default.http.port>
${liberty.var.default.http.port}
</default.http.port>
<default.https.port>
${liberty.var.default.https.port}
</default.https.port>
<cf.context.root>/converter</cf.context.root>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<server description="Sample Liberty server">

<featureManager>
<feature>jsp-2.3</feature>
</featureManager>

<variable name="default.http.port" defaultValue="9080" />
<variable name="default.https.port" defaultValue="9443" />

<httpEndpoint host="*" httpPort="${default.http.port}"
httpsPort="${default.https.port}" id="defaultHttpEndpoint" />

<enterpriseApplication id="guide-maven-multimodules-ear-skinny-modules"
location="guide-maven-multimodules-ear-skinny-modules.ear"
name="guide-maven-multimodules-ear-skinny-modules" />
</server>
Original file line number Diff line number Diff line change
@@ -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 <file/> 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 <archive/> 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 <dir/> element expected 4");

expression = "/archive/archive/file";
nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET);
assertEquals(5, nodes.getLength(),"Number of <file/> 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 <archive/> element inside any other <archive/> 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();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
<modules>
<module>jar</module>
<module>war</module>
<module>war2</module>
<module>ear1</module>
<module>ear2</module>
<module>rar</module>
<module>ear-skinny-modules</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-rar</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>rar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<!-- Provided dependencies -->
<dependency>
<groupId>io.openliberty.guides</groupId>
<artifactId>guide-maven-multimodules-jar</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-rar-plugin</artifactId>
<configuration>
<raXmlFile>src/main/rar-source/META-INF/ra.xml</raXmlFile>
<rarSourceDirectory>src/main/resources</rarSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -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);
}
}
Loading

0 comments on commit e495890

Please sign in to comment.