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-install-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new 78e8ab3  Restore install test coverage lost in the IT migration
78e8ab3 is described below

commit 78e8ab3cce88d03dea311c4d44953152a8579ca7
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Thu Nov 26 17:04:03 2026 +0000

    Restore install test coverage lost in the IT migration
    
    The output-directory variant of the no-main-artifact test now points the 
main artifact at a directory instead of repeating the null-file case, and 
install-file has tests for a pomFile without packaging.
---
 .../maven/plugins/install/InstallFileMojoTest.java | 49 ++++++++++++++++++++++
 .../maven/plugins/install/InstallMojoTest.java     |  9 ++--
 2 files changed, 54 insertions(+), 4 deletions(-)

diff --git 
a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java 
b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
index c1e21fe..9d34bd2 100644
--- a/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/install/InstallFileMojoTest.java
@@ -747,6 +747,55 @@ public class InstallFileMojoTest {
                 "The installed POM must be the supplied pomFile, not a 
generated one");
     }
 
+    @Test
+    @InjectMojo(goal = "install-file")
+    void installFileWithPomFileAndNoPackagingDefaultsToJar(InstallFileMojo 
mojo) throws Exception {
+        // The POM declares no packaging, so the model default (jar) must give 
the artifact its extension
+        installWithPomFileOnly(mojo, pomXmlWithParent("test"), "test-0.1.jar");
+
+        String versionDir = "org/apache/maven/its/install/121/test/1.0/";
+        assertEquals("jar", getMojoField(mojo, "packaging"));
+        assertInstalled(localRepo, versionDir + "test-1.0.jar");
+        assertInstalled(localRepo, versionDir + "test-1.0.pom");
+        assertInstalled(localRepo, 
"org/apache/maven/its/install/121/test/maven-metadata-local.xml");
+    }
+
+    @Test
+    @InjectMojo(goal = "install-file")
+    void 
installFileWithPomFileAndNoPackagingTakesPackagingFromPom(InstallFileMojo mojo) 
throws Exception {
+        String pom = pomXmlWithParent("test-war").replace("</project>", "  
<packaging>war</packaging>\n</project>");
+        installWithPomFileOnly(mojo, pom, "test-0.1.war");
+
+        String versionDir = "org/apache/maven/its/install/121/test-war/1.0/";
+        assertEquals("war", getMojoField(mojo, "packaging"));
+        assertInstalled(localRepo, versionDir + "test-war-1.0.war");
+        assertInstalled(localRepo, versionDir + "test-war-1.0.pom");
+        assertFalse(new File(localRepo, versionDir + 
"test-war-1.0.jar").exists());
+    }
+
+    /**
+     * Runs the goal with only {@code file} and {@code pomFile}: no 
coordinates and no packaging, as the former
+     * install-file-generated-pom IT did.
+     */
+    private void installWithPomFileOnly(InstallFileMojo mojo, String pom, 
String sourceFileName) throws Exception {
+        File pomFile = tempDir.resolve("test-0.1.pom").toFile();
+        Files.write(pomFile.toPath(), pom.getBytes(StandardCharsets.UTF_8));
+        File sourceFile = tempDir.resolve(sourceFileName).toFile();
+        Files.copy(
+                
MojoExtension.getTestFile("target/maven-install-test-1.0-SNAPSHOT.jar")
+                        .toPath(),
+                sourceFile.toPath());
+
+        setMojoField(mojo, "groupId", null);
+        setMojoField(mojo, "artifactId", null);
+        setMojoField(mojo, "version", null);
+        setMojoField(mojo, "packaging", null);
+        setMojoField(mojo, "pomFile", pomFile);
+        setMojoField(mojo, "file", sourceFile);
+
+        mojo.execute();
+    }
+
     @Test
     @InjectMojo(goal = "install-file")
     @MojoParameter(name = "groupId", value = 
"org.apache.maven.its.install.jsj")
diff --git 
a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java 
b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
index 933100c..bcd35d2 100644
--- a/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/install/InstallMojoTest.java
@@ -599,18 +599,19 @@ class InstallMojoTest {
                 "it",
                 Files.createTempFile(tempDir, "test", "jar").toFile());
 
-        // The two IT variants differ only by the presence of target/classes. 
Mirror that under the temp
-        // directory so the real build output is untouched.
+        // The two IT variants differ only by the presence of target/classes. 
Without it the main artifact has no
+        // file; with it the compiler plugin points the main artifact at that 
directory, which is not a file either.
+        // Mirror both under the temp directory so the real build output is 
untouched.
         Path classesDir = tempDir.resolve("target/classes");
         if (classesDirPresent) {
             Files.createDirectories(classesDir);
             assertTrue(Files.isDirectory(classesDir));
+            mavenProject.getArtifact().setFile(classesDir.toFile());
         } else {
             assertFalse(Files.exists(classesDir));
+            mavenProject.getArtifact().setFile(null);
         }
 
-        mavenProject.getArtifact().setFile(null);
-
         MojoExecutionException e = assertThrows(MojoExecutionException.class, 
mojo::execute);
         assertEquals(
                 "The packaging plugin for project test did not assign a main 
file to the project but it has "

Reply via email to