From c2b340474188bfcd2731348cdddd5e6b1ad3f624 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 11 Jul 2023 11:02:11 +0200 Subject: [PATCH] [MNG-7838] Add IT --- ...ng3043BestEffortReactorResolutionTest.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3043BestEffortReactorResolutionTest.java b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3043BestEffortReactorResolutionTest.java index 246f662b2..a2aff1cb9 100644 --- a/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3043BestEffortReactorResolutionTest.java +++ b/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng3043BestEffortReactorResolutionTest.java @@ -152,6 +152,73 @@ public void testitPackagePhase() throws Exception { assertContains(classpath, new String[] {prefix + "tests.jar"}); } + /** + * Test that dependency resolution still uses the actual artifact files once these have been + * assembled/attached in the "package" phase. This ensures the class path is accurate and not locked to + * the output directories of the best effort model from above. + * + * @throws Exception in case of failure + */ + @Test + public void testitPackagePhasesSlitted() throws Exception { + requiresMavenVersion("[4.0.0-beta-4,)"); + + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-3043"); + + Verifier verifier = newVerifier(testDir.getAbsolutePath()); + verifier.setAutoclean(false); + verifier.deleteDirectory("target"); + verifier.deleteDirectory("consumer-a/target"); + verifier.deleteDirectory("consumer-b/target"); + verifier.deleteDirectory("consumer-c/target"); + verifier.deleteArtifacts("org.apache.maven.its.mng3043"); + verifier.setLogFileName("log-package-pre.txt"); + verifier.addCliArguments("--also-make", "--projects", ":dependency", "package"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + verifier = newVerifier(testDir.getAbsolutePath()); + verifier.setAutoclean(false); + verifier.setLogFileName("log-package-pre.txt"); + verifier.addCliArguments("--projects", ":consumer-a,:consumer-b,:consumer-c", "package"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + String prefix = "dependency-0.1-SNAPSHOT-"; + + List classpath; + + classpath = verifier.loadLines("consumer-a/target/compile.txt", "UTF-8"); + assertContains(classpath, new String[] {prefix + "tests.jar"}); + assertNotContains(classpath, new String[] {prefix + "client.jar"}); + classpath = verifier.loadLines("consumer-a/target/runtime.txt", "UTF-8"); + assertContains(classpath, new String[] {prefix + "tests.jar"}); + assertNotContains(classpath, new String[] {prefix + "client.jar"}); + classpath = verifier.loadLines("consumer-a/target/test.txt", "UTF-8"); + assertContains(classpath, new String[] {prefix + "tests.jar"}); + assertNotContains(classpath, new String[] {prefix + "client.jar"}); + + classpath = verifier.loadLines("consumer-b/target/compile.txt", "UTF-8"); + assertContains(classpath, new String[] {prefix + "client.jar"}); + assertNotContains(classpath, new String[] {prefix + "tests.jar"}); + classpath = verifier.loadLines("consumer-b/target/runtime.txt", "UTF-8"); + assertContains(classpath, new String[] {prefix + "client.jar"}); + assertNotContains(classpath, new String[] {prefix + "tests.jar"}); + classpath = verifier.loadLines("consumer-b/target/test.txt", "UTF-8"); + assertContains(classpath, new String[] {prefix + "client.jar"}); + assertNotContains(classpath, new String[] {prefix + "tests.jar"}); + + classpath = verifier.loadLines("consumer-c/target/compile.txt", "UTF-8"); + assertContains(classpath, new String[] {prefix + "client.jar"}); + assertContains(classpath, new String[] {prefix + "tests.jar"}); + classpath = verifier.loadLines("consumer-c/target/runtime.txt", "UTF-8"); + assertContains(classpath, new String[] {prefix + "client.jar"}); + assertContains(classpath, new String[] {prefix + "tests.jar"}); + classpath = verifier.loadLines("consumer-c/target/test.txt", "UTF-8"); + assertContains(classpath, new String[] {prefix + "client.jar"}); + assertContains(classpath, new String[] {prefix + "tests.jar"}); + } + private void assertContains(List collection, String[] items) { for (String item : items) { assertContains(collection, item);