Skip to content

Commit

Permalink
Add test case and few more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cherylking committed Jun 28, 2023
1 parent 594be96 commit 482936d
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* (c) Copyright IBM Corporation 2017.
* (c) Copyright IBM Corporation 2017, 2023.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -65,5 +65,20 @@ public void testLooseApplicationFileContent() throws Exception {
File appXml = new File("../src/main/application/META-INF/application.xml");
assertEquals("file sourceOnDisk attribute value", appXml.getCanonicalPath(),
nodes.item(0).getAttributes().getNamedItem("sourceOnDisk").getNodeValue());

expression = "/archive/archive/archive";
nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET);
assertEquals("Number of <archive/> element ==>", 1, nodes.getLength());
assertEquals("archive targetInArchive attribute value", "/WEB-INF/lib/SampleBundle-1.0-SNAPSHOT.jar",
nodes.item(0).getAttributes().getNamedItem("targetInArchive").getNodeValue());

expression = "/archive/archive/archive/dir";
nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET);
assertEquals("Number of <dir/> element ==>", 1, nodes.getLength());

expression = "/archive/archive/archive/file";
nodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET);
assertEquals("Number of <dir/> element ==>", 1, nodes.getLength());

}
}
51 changes: 51 additions & 0 deletions liberty-maven-plugin/src/it/ear-project-it/SampleBundle/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.openliberty.tools.it</groupId>
<artifactId>ear-project-it</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>SampleBundle</artifactId>
<packaging>bundle</packaging>

<name>ear-project-it: SampleBundle Module</name>

<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
</dependency>

<!-- Test scope dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>io.openliberty.tools.it</Bundle-SymbolicName>
<Export-Package>wasdev.sample.bundle*;version=${project.version}</Export-Package>
<Import-Package>
*
</Import-Package>
<_removeheaders>Bnd-LastModified</_removeheaders>
<_reproducible>true</_reproducible>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

package wasdev.sample.bundle;

public class SampleBundle {

public String hello() {
return "Hello Bundle World.";
}
}
5 changes: 5 additions & 0 deletions liberty-maven-plugin/src/it/ear-project-it/SampleWAR/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
<version>1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.openliberty.tools.it</groupId>
<artifactId>SampleBundle</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>

<!-- Test scope dependencies -->
<dependency>
Expand Down
6 changes: 6 additions & 0 deletions liberty-maven-plugin/src/it/ear-project-it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<modules>
<module>SampleEJB</module>
<module>SampleBundle</module>
<module>SampleWAR</module>
<module>SampleWAR2</module>
<module>AppXmlEAR</module>
Expand Down Expand Up @@ -70,6 +71,11 @@
<artifactId>maven-ejb-plugin</artifactId>
<version>3.2.1</version>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.8</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ protected void installLooseConfigEar(MavenProject proj, LooseConfigData config,
case "ejb":
looseEar.addEjbModule(dependencyProject, artifact);
break;
case "bundle":
looseEar.addBundleModule(dependencyProject, artifact);
break;
case "war":
Element warArchive = looseEar.addWarModule(dependencyProject, artifact,
getWarSourceDirectory(dependencyProject));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public Element addEjbModule(MavenProject proj, Artifact artifact) throws MojoExe
return addModule(proj, artifact, "maven-ejb-plugin");
}

public Element addBundleModule(MavenProject proj, Artifact artifact) throws MojoExecutionException, IOException {
return addModule(proj, artifact, "maven-bundle-plugin");
}

public Element addModule(MavenProject proj, Artifact artifact, String pluginId) throws MojoExecutionException, IOException {
File outputDirectory = new File(proj.getBuild().getOutputDirectory());
Element moduleArchive = config.addArchive(getModuleUri(artifact));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ private void doRunServer() throws MojoExecutionException {
case "ejb":
runMojo("org.apache.maven.plugins", "maven-ejb-plugin", "ejb");
break;
case "bundle":
runMojo("org.apache.felix", "maven-bundle-plugin", "bundle");
break;
case "jar":
runMojo("org.apache.maven.plugins", "maven-jar-plugin", "jar");
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ public class ExecuteMojoUtil {
"clientIncludes", "ejbJar", "ejbVersion", "escapeBackslashesInFilePath", "escapeString", "excludes",
"filterDeploymentDescriptor", "filters", "generateClient", "outputTimestamp"));

// https://felix.apache.org/documentation/_attachments/components/bundle-plugin/bundle-mojo.html
private static final ArrayList<String> BUNDLE_PARAMS = new ArrayList<>(
Arrays.asList("archive", "buildDirectory", "classifier", "createDependencyReducedPom", "dependencyReducedPomLocation",
"dumpClasspath", "dumpInstructions", "excludeDependencies", "exportScr", "finalName", "instructions",
"manifestLocation", "niceManifest", "noWarningProjectTypes", "outputDirectory", "packaging", "scrLocation",
"supportedProjectTypes", "unpackbundle"));

// https://maven.apache.org/plugins/maven-war-plugin/war-mojo.html
private static final ArrayList<String> WAR_PARAMS = new ArrayList<>(Arrays.asList("outputDirectory",
"warSourceDirectory", "webappDirectory", "workDirectory", "archive", "archiveClasses", "attachClasses",
Expand Down Expand Up @@ -350,6 +357,9 @@ private static Xpp3Dom validateConfiguration(Plugin plugin, String goal, Xpp3Dom
case "maven-ejb-plugin:ejb":
goalConfig = stripConfigElements(config, EJB_PARAMS);
break;
case "maven-bundle-plugin:bundle":
goalConfig = stripConfigElements(config, BUNDLE_PARAMS);
break;
case "maven-war-plugin:war":
goalConfig = stripConfigElements(config, WAR_PARAMS);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ public static PluginExecution getPluginGoalExecution(MavenProject project, Strin
* @return the manifest file
*/
public static File getManifestFile(MavenProject proj, String pluginArtifactId) {
Xpp3Dom dom = proj.getGoalConfiguration("org.apache.maven.plugins", pluginArtifactId, null, null);
String groupId = pluginArtifactId.equals("maven-bundle-plugin") ? "org.apache.felix" : "org.apache.maven.plugins";
Xpp3Dom dom = proj.getGoalConfiguration(groupId, pluginArtifactId, null, null);
if (dom != null) {
Xpp3Dom archive = dom.getChild("archive");
if (archive != null) {
Expand All @@ -185,6 +186,16 @@ public static File getManifestFile(MavenProject proj, String pluginArtifactId) {
}
}
}

if (pluginArtifactId.equals("maven-bundle-plugin")) {
// check for generated manifest file in target/classes/META-INF
String dependProjectTargetDir = proj.getBuild().getDirectory();
File generatedManifest = new File(dependProjectTargetDir, "/classes/META-INF/MANIFEST.MF");
if (generatedManifest.exists()) {
return generatedManifest;
}
}

return null;
}

Expand Down

0 comments on commit 482936d

Please sign in to comment.