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 7917267  Fix 315: pom-packaged project installs JAR instead of POM 
when jar:jar runs first (#457)
7917267 is described below

commit 791726707e5b3adf2d73458426457c7b5c211c50
Author: Guillaume Nodet <[email protected]>
AuthorDate: Sat Nov 21 13:17:22 2026 +0100

    Fix 315: pom-packaged project installs JAR instead of POM when jar:jar runs 
first (#457)
    
    * Fix MINSTALL-315: pom-packaged project installs JAR instead of POM when 
jar:jar runs first
    
    When jar:jar is invoked on a pom-packaged project, it sets 
project.getArtifact().getFile()
    to the produced JAR. In InstallMojo.processProject(), when pomArtifact and 
projectArtifact
    have the same coordinates (pom packaging), the code was replacing 
pomArtifact with
    projectArtifact, which carried the JAR file — causing install:install to 
install the JAR
    instead of the POM.
    
    The fix removes the substitution: pomArtifact (built from ProjectArtifact) 
already wraps
    project.getFile() (the POM file), which is always the correct artifact to 
install.
    
    Regression test: src/it/minstall-315 runs jar:jar then install:install on a 
pom-packaged
    project and verifies that the installed artifact is XML (POM), not a JAR 
(ZIP).
    
    * Address review: simplify verify.groovy — ZIP check is sufficient
    
    * Fix: add missing ASL license header to invoker.properties (RAT check)
    
    ---------
    
    Co-authored-by: Guillaume Nodet <[email protected]>
---
 src/it/minstall-315/invoker.properties             | 18 ++++++++
 src/it/minstall-315/pom.xml                        | 51 ++++++++++++++++++++++
 src/it/minstall-315/setup.groovy                   | 26 +++++++++++
 src/it/minstall-315/verify.groovy                  | 41 +++++++++++++++++
 .../apache/maven/plugins/install/InstallMojo.java  |  8 ++--
 5 files changed, 140 insertions(+), 4 deletions(-)

diff --git a/src/it/minstall-315/invoker.properties 
b/src/it/minstall-315/invoker.properties
new file mode 100644
index 0000000..cf6fed7
--- /dev/null
+++ b/src/it/minstall-315/invoker.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals = jar:jar install:install
diff --git a/src/it/minstall-315/pom.xml b/src/it/minstall-315/pom.xml
new file mode 100644
index 0000000..dccff36
--- /dev/null
+++ b/src/it/minstall-315/pom.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<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/xsd/maven-4.0.0.xsd";>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.install.minstall315</groupId>
+  <artifactId>test</artifactId>
+  <version>1.0</version>
+  <packaging>pom</packaging>
+
+  <description>
+    MINSTALL-315: Verifies that install:install on a pom-packaged project 
installs the POM, not any
+    JAR produced by a preceding jar:jar invocation.
+  </description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>@mavenJarPluginVersion@</version>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-install-plugin</artifactId>
+        <version>@project.version@</version>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/minstall-315/setup.groovy b/src/it/minstall-315/setup.groovy
new file mode 100644
index 0000000..bb1ec95
--- /dev/null
+++ b/src/it/minstall-315/setup.groovy
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.codehaus.plexus.util.*
+
+File dir = new File( localRepositoryPath, 
"org/apache/maven/its/install/minstall315" )
+System.out.println( "Deleting " + dir )
+FileUtils.deleteDirectory( dir )
+
+return true
diff --git a/src/it/minstall-315/verify.groovy 
b/src/it/minstall-315/verify.groovy
new file mode 100644
index 0000000..8215b68
--- /dev/null
+++ b/src/it/minstall-315/verify.groovy
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+// MINSTALL-315: jar:jar on a pom-packaged project sets 
project.getArtifact().getFile() to the produced JAR.
+// A subsequent install:install must install the POM, not that JAR.
+
+File installed = new File( localRepositoryPath,
+    "org/apache/maven/its/install/minstall315/test/1.0/test-1.0.pom" )
+
+if ( !installed.isFile() ) {
+    throw new FileNotFoundException( "Installed file not found: " + installed )
+}
+
+// The installed file must not be a JAR (ZIP). Check the magic bytes: 
PK\x03\x04 = 0x50 0x4B 0x03 0x04.
+byte[] magic = new byte[4]
+new FileInputStream( installed ).with { stream ->
+    stream.read( magic )
+}
+
+if ( magic[0] == 0x50 && magic[1] == 0x4B ) {
+    throw new Exception(
+        "MINSTALL-315 regression: install:install installed a JAR (ZIP) 
instead of the POM for a pom-packaged project" )
+}
+
+return true
diff --git a/src/main/java/org/apache/maven/plugins/install/InstallMojo.java 
b/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
index 96f40c7..ebae751 100644
--- a/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
+++ b/src/main/java/org/apache/maven/plugins/install/InstallMojo.java
@@ -202,11 +202,11 @@ public class InstallMojo extends AbstractMojo {
         // incomplete project: is not pom project and projectArtifact has no 
file
 
         // we must compare coordinates ONLY (as projectArtifact may not have 
file, and Artifact.equals factors it in)
-        // BUT if projectArtifact has file set, use that one
+        // For pom-packaged projects, pomArtifact and projectArtifact have the 
same coordinates: they represent the
+        // same artifact. In that case, another plugin (e.g. jar:jar) may have 
set a non-POM file on
+        // project.getArtifact() (MINSTALL-315). We must NOT use that file: 
pomArtifact already wraps
+        // project.getFile() (the actual POM) via ProjectArtifact, which is 
the correct artifact to install.
         if (ArtifactIdUtils.equalsId(pomArtifact, projectArtifact)) {
-            if (isFile(projectArtifact.getFile())) {
-                pomArtifact = projectArtifact;
-            }
             projectArtifact = null;
         }
 

Reply via email to