-
Notifications
You must be signed in to change notification settings - Fork 48
Loose EAR Manifest Class-Path Issue Fix #1073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sajeerzeji
wants to merge
11
commits into
OpenLiberty:main
Choose a base branch
from
sajeerzeji:GH766-Multi_module_issue_with_loose_app
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1d48694
Instead of using static resource manifest, use jar task generated man…
0d44cfd
EJB Dependency Fixes
f274dfd
Reverts the changes
9718506
Merge branch 'multi-module-loose-app-projects-not-copying-deps-to-lib…
7ef518c
Logs corrected
70b422f
Absolute dirNodes count check added to the test
0943f87
Loose App extensive Tests added
878ac5e
Test issues fixed
0d61ade
Workflow failures are addressed by removing the absolute path logic f…
536ba8c
Test issues fixed: Local git configurations was excluding any /lib fo…
f6228e0
Removed unused buildFilename from the test files
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarEjbDependency.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| package io.openliberty.tools.gradle | ||
|
|
||
| import org.junit.AfterClass | ||
| import org.junit.BeforeClass | ||
| import org.junit.Test | ||
|
|
||
| import java.io.File | ||
| import java.io.FileInputStream | ||
| import java.io.IOException | ||
|
|
||
| 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.apache.commons.io.FileUtils | ||
| import org.junit.Assert | ||
| import org.w3c.dom.Document | ||
| import org.w3c.dom.NodeList | ||
| import org.w3c.dom.Node | ||
|
|
||
| public class TestMultiModuleLooseEarEjbDependency extends AbstractIntegrationTest { | ||
| static File resourceDir = new File("build/resources/test/multi-module-loose-ear-ejb-dependency-test") | ||
| static File buildDir = new File(integTestDir, "/multi-module-loose-ear-ejb-dependency-test") | ||
|
|
||
| @BeforeClass | ||
| public static void setup() { | ||
| createDir(buildDir) | ||
| // Inline createTestProject logic | ||
| if (!resourceDir.exists()){ | ||
| throw new AssertionError("The source file '${resourceDir.canonicalPath}' doesn't exist.", null) | ||
| } | ||
| try { | ||
| // Copy all resources | ||
| FileUtils.copyDirectory(resourceDir, buildDir) | ||
|
cherylking marked this conversation as resolved.
|
||
| // Copy gradle.properties | ||
| copyFile(new File("build/gradle.properties"), new File(buildDir, "gradle.properties")) | ||
| } catch (IOException e) { | ||
| throw new AssertionError("Unable to copy directory '${buildDir.canonicalPath}'.", e) | ||
| } | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDown() throws Exception { | ||
| runTasks(buildDir, 'libertyStop') | ||
| } | ||
|
|
||
| @Test | ||
| public void test_loose_config_file_exists() { | ||
| try { | ||
| runTasks(buildDir, 'deploy') | ||
| } catch (Exception e) { | ||
| throw new AssertionError("Fail on task deploy.", e) | ||
| } | ||
|
|
||
| File looseXml = new File('build/testBuilds/multi-module-loose-ear-ejb-dependency-test/ear/build/wlp/usr/servers/testServer/apps/ejb-dependency-ear-1.0.ear.xml') | ||
| assert looseXml.exists() : 'Loose application config file was not created' | ||
| } | ||
|
|
||
| @Test | ||
| public void test_ejb_module_includes_dependency_classes() { | ||
| File looseXml = new File('build/testBuilds/multi-module-loose-ear-ejb-dependency-test/ear/build/wlp/usr/servers/testServer/apps/ejb-dependency-ear-1.0.ear.xml') | ||
| FileInputStream input = new FileInputStream(looseXml) | ||
|
|
||
| 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) | ||
|
|
||
| XPath xPath = XPathFactory.newInstance().newXPath() | ||
|
|
||
| String expression = "/archive/archive[@targetInArchive='/ejb-dependency-ejb-jar-1.0.jar']" | ||
| NodeList ejbModuleNodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET) | ||
| Assert.assertEquals("Should have exactly one EJB module archive", 1, ejbModuleNodes.getLength()) | ||
|
|
||
| Node ejbModuleNode = ejbModuleNodes.item(0) | ||
|
|
||
| expression = "dir" | ||
| NodeList dirNodes = (NodeList) xPath.compile(expression).evaluate(ejbModuleNode, XPathConstants.NODESET) | ||
|
|
||
| Assert.assertEquals("EJB module should have exactly 2 <dir> elements (own classes + dependency classes)", | ||
| 2, dirNodes.getLength()) | ||
|
|
||
| // Verify that one of the directories is from lib-jar module | ||
| boolean foundLibJarClasses = false | ||
| for (int i = 0; i < dirNodes.getLength(); i++) { | ||
| Node dirNode = dirNodes.item(i) | ||
| String sourceOnDisk = dirNode.getAttributes().getNamedItem("sourceOnDisk").getNodeValue() | ||
|
|
||
| if (sourceOnDisk.contains("lib-jar") && sourceOnDisk.contains("classes")) { | ||
| foundLibJarClasses = true | ||
|
|
||
| // Verify targetInArchive is "/" | ||
| String targetInArchive = dirNode.getAttributes().getNamedItem("targetInArchive").getNodeValue() | ||
| Assert.assertEquals("Dependency classes should be at root of EJB JAR", "/", targetInArchive) | ||
| break | ||
| } | ||
| } | ||
|
|
||
| Assert.assertTrue("EJB module should include lib-jar classes directory", foundLibJarClasses) | ||
| } | ||
|
|
||
| @Test | ||
| public void test_ejb_module_own_classes_included() { | ||
| File looseXml = new File('build/testBuilds/multi-module-loose-ear-ejb-dependency-test/ear/build/wlp/usr/servers/testServer/apps/ejb-dependency-ear-1.0.ear.xml') | ||
| FileInputStream input = new FileInputStream(looseXml) | ||
|
|
||
| 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) | ||
|
|
||
| XPath xPath = XPathFactory.newInstance().newXPath() | ||
|
|
||
| String expression = "/archive/archive[@targetInArchive='/ejb-dependency-ejb-jar-1.0.jar']/dir[contains(@sourceOnDisk, 'ejb-jar') and contains(@sourceOnDisk, 'classes')]" | ||
| NodeList ejbModuleOwnClasses = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET) | ||
|
|
||
| Assert.assertTrue("EJB module should include its own classes directory", ejbModuleOwnClasses.getLength() > 0) | ||
|
|
||
| // Verify it targets root of JAR | ||
| Node dirNode = ejbModuleOwnClasses.item(0) | ||
| String targetInArchive = dirNode.getAttributes().getNamedItem("targetInArchive").getNodeValue() | ||
| Assert.assertEquals("EJB module's own classes should be at root of JAR", "/", targetInArchive) | ||
| } | ||
| } | ||
113 changes: 113 additions & 0 deletions
113
src/test/groovy/io/openliberty/tools/gradle/TestMultiModuleLooseEarMixedDependency.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| package io.openliberty.tools.gradle | ||
|
|
||
| import org.junit.AfterClass | ||
| import org.junit.BeforeClass | ||
| import org.junit.Test | ||
| import org.junit.FixMethodOrder | ||
| import org.junit.runners.MethodSorters | ||
|
|
||
| import java.io.File | ||
| import java.io.FileInputStream | ||
| import java.io.IOException | ||
|
|
||
| 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.apache.commons.io.FileUtils | ||
| import org.junit.Assert | ||
| import org.w3c.dom.Document | ||
| import org.w3c.dom.NodeList | ||
| import org.w3c.dom.Node | ||
|
|
||
| @FixMethodOrder(MethodSorters.NAME_ASCENDING) | ||
| public class TestMultiModuleLooseEarMixedDependency extends AbstractIntegrationTest { | ||
| static File resourceDir = new File("build/resources/test/multi-module-loose-ear-mixed-test") | ||
| static File buildDir = new File(integTestDir, "/multi-module-loose-ear-mixed-test") | ||
|
|
||
| @BeforeClass | ||
| public static void setup() { | ||
| createDir(buildDir) | ||
| // Inline createTestProject logic | ||
| if (!resourceDir.exists()){ | ||
| throw new AssertionError("The source file '${resourceDir.canonicalPath}' doesn't exist.", null) | ||
| } | ||
| try { | ||
| // Copy all resources | ||
| FileUtils.copyDirectory(resourceDir, buildDir) | ||
| // Copy gradle.properties | ||
| copyFile(new File("build/gradle.properties"), new File(buildDir, "gradle.properties")) | ||
| } catch (IOException e) { | ||
| throw new AssertionError("Unable to copy directory '${buildDir.canonicalPath}'.", e) | ||
| } | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDown() throws Exception { | ||
| runTasks(buildDir, 'libertyStop') | ||
| } | ||
|
|
||
| @Test | ||
| public void test_loose_config_file_exists() { | ||
| try { | ||
| runTasks(buildDir, 'deploy') | ||
| } catch (Exception e) { | ||
| throw new AssertionError("Fail on task deploy.", e) | ||
| } | ||
|
|
||
| File looseXml = new File('build/testBuilds/multi-module-loose-ear-mixed-test/ear/build/wlp/usr/servers/testServer/apps/ejb-mixed-dependency-ear-1.0.ear.xml') | ||
| assert looseXml.exists() : 'Loose application config file was not created' | ||
| } | ||
|
|
||
| @Test | ||
| public void test_project_dependencies_included() { | ||
| File looseXml = new File('build/testBuilds/multi-module-loose-ear-mixed-test/ear/build/wlp/usr/servers/testServer/apps/ejb-mixed-dependency-ear-1.0.ear.xml') | ||
| FileInputStream input = new FileInputStream(looseXml) | ||
|
|
||
| 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) | ||
|
|
||
| XPath xPath = XPathFactory.newInstance().newXPath() | ||
|
|
||
| String expression = "/archive/archive[@targetInArchive='/ejb-mixed-dependency-ejb-jar-1.0.jar']" | ||
| NodeList ejbModuleNodes = (NodeList) xPath.compile(expression).evaluate(inputDoc, XPathConstants.NODESET) | ||
| Assert.assertEquals("Should have exactly one EJB module archive", 1, ejbModuleNodes.getLength()) | ||
|
|
||
| Node ejbModuleNode = ejbModuleNodes.item(0) | ||
|
|
||
| // Check for <dir> elements (project dependencies) | ||
| expression = "dir" | ||
| NodeList dirNodes = (NodeList) xPath.compile(expression).evaluate(ejbModuleNode, XPathConstants.NODESET) | ||
|
|
||
| // Should have exactly 2 <dir> elements: ejb-jar's own classes + lib-jar classes | ||
| Assert.assertEquals("EJB module should have exactly 2 <dir> elements (own classes + lib-jar project dependency)", | ||
| 2, dirNodes.getLength()) | ||
|
|
||
| // Verify that one of the directories is from lib-jar module | ||
| boolean foundLibJarClasses = false | ||
| boolean foundEjbClasses = false | ||
| for (int i = 0; i < dirNodes.getLength(); i++) { | ||
| Node dirNode = dirNodes.item(i) | ||
| String sourceOnDisk = dirNode.getAttributes().getNamedItem("sourceOnDisk").getNodeValue() | ||
|
|
||
| if (sourceOnDisk.contains("lib-jar") && sourceOnDisk.contains("classes")) { | ||
| foundLibJarClasses = true | ||
| } | ||
| if (sourceOnDisk.contains("ejb-jar") && sourceOnDisk.contains("classes")) { | ||
| foundEjbClasses = true | ||
| } | ||
| } | ||
|
|
||
| Assert.assertTrue("EJB module should include its own classes directory", foundEjbClasses) | ||
| Assert.assertTrue("EJB module should include lib-jar classes directory (project dependency)", foundLibJarClasses) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.