This is an automated email from the ASF dual-hosted git repository. slachiewicz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/maven-dependency-plugin.git
commit 7ec57c39f4d988fec1cd4f334a26c1156b66087c Author: Sylwester Lachiewicz <[email protected]> AuthorDate: Thu Nov 5 00:52:42 2026 +0000 Test copy with destFileName and unpack markers with includes --- .../dependency/fromConfiguration/TestCopyMojo.java | 13 ++++++++ .../fromConfiguration/TestUnpackMojo.java | 36 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestCopyMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestCopyMojo.java index 8f06fb01..ec5abca6 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestCopyMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestCopyMojo.java @@ -369,6 +369,19 @@ class TestCopyMojo { assertFilesExist(list); } + @Test + @InjectMojo(goal = "copy") + void testCopyWithDestFileName(CopyMojo mojo) throws Exception { + stubFactory.createArtifact("groupId", "artifact", "1.0", null, "jar", null); + mojo.setLocalRepositoryDirectory(stubFactory.getWorkingDir()); + mojo.setArtifact("groupId:artifact:1.0:jar::renamed.jar"); + + mojo.execute(); + + assertTrue(new File(mojo.getOutputDirectory(), "renamed.jar").isFile()); + assertFalse(new File(mojo.getOutputDirectory(), "artifact-1.0.jar").exists()); + } + @Test @InjectMojo(goal = "copy") void testCopyStripVersionSetInMojo(CopyMojo mojo) throws Exception { diff --git a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java index a6ccbfb6..3b5dc13c 100644 --- a/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java +++ b/src/test/java/org/apache/maven/plugins/dependency/fromConfiguration/TestUnpackMojo.java @@ -52,6 +52,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -413,6 +414,41 @@ class TestUnpackMojo { assertTrue(new File(mojo.getOutputDirectory(), "hello.txt").isFile()); } + @Test + @InjectMojo(goal = "unpack") + void testUnpackWithIncludesFindsTheMarkerOfThePreviousRun(UnpackMojo mojo) throws Exception { + File repo = new File(tempDir, "remote-repo"); + File dir = new File(repo, "remote/only/1.0"); + Files.createDirectories(dir.toPath()); + try (ZipOutputStream zip = new ZipOutputStream(Files.newOutputStream(new File(dir, "only-1.0.jar").toPath()))) { + for (String name : new String[] {"hello.txt", "other.txt"}) { + zip.putNextEntry(new ZipEntry(name)); + zip.write(name.getBytes(StandardCharsets.UTF_8)); + zip.closeEntry(); + } + } + + ArtifactItem item = new ArtifactItem(); + item.setGroupId("remote"); + item.setArtifactId("only"); + item.setVersion("1.0"); + mojo.setArtifactItems(Collections.singletonList(item)); + mojo.setRemoteRepositories(Collections.singletonList("remote-repo::default::" + repo.toURI())); + mojo.setIncludes("hello.txt"); + + mojo.execute(); + + File hello = new File(mojo.getOutputDirectory(), "hello.txt"); + assertTrue(hello.isFile()); + assertFalse(new File(mojo.getOutputDirectory(), "other.txt").exists()); + + // the second execution must find the marker written by the first one and skip the unpack + assertTrue(hello.delete()); + mojo.execute(); + + assertFalse(hello.exists()); + } + @Test @InjectMojo(goal = "unpack") void testArtifactNotFound(UnpackMojo mojo) throws Exception {
