You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2023/09/19 16:51:44 UTC

[maven-artifact-plugin] 01/01: [MARTIFACT-49] Supports the build/consumer feature (#18)

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-artifact-plugin.git

commit e5b7f8c39383076a56063938479d823a456ad44e
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Fri Jun 9 09:23:41 2023 +0200

    [MARTIFACT-49] Supports the build/consumer feature (#18)
---
 .../artifact/buildinfo/BuildInfoWriter.java        | 29 ++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java
index 6c09395..cb3d46d 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java
@@ -23,6 +23,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.PrintWriter;
 import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Properties;
@@ -162,6 +165,12 @@ class BuildInfoWriter {
             p.println(prefix + "coordinates=" + project.getGroupId() + ':' + project.getArtifactId());
         }
 
+        // detect Maven 4 consumer POM transient attachment
+        Artifact consumerPom = project.getAttachedArtifacts().stream()
+                .filter(a -> "pom".equals(a.getType()) && "consumer".equals(a.getClassifier()))
+                .findAny()
+                .orElse(null);
+
         int n = 0;
         Artifact pomArtifact = new DefaultArtifact(
                 project.getGroupId(),
@@ -171,13 +180,25 @@ class BuildInfoWriter {
                 "pom",
                 "",
                 artifactHandlerManager.getArtifactHandler("pom"));
-        pomArtifact.setFile(project.getFile());
+        if (consumerPom != null) {
+            // Maven 4 transient consumer POM attachment is published as the POM, overrides build POM, see
+            // https://github.com/apache/maven/blob/c79a7a02721f0f9fd7e202e99f60b593461ba8cc/maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java#L130-L155
+            try {
+                Path pomFile = Files.createTempFile(Paths.get(project.getBuild().getDirectory()), "consumer-", ".pom");
+                Files.copy(consumerPom.getFile().toPath(), pomFile, StandardCopyOption.REPLACE_EXISTING);
+                pomArtifact.setFile(pomFile.toFile());
+            } catch (IOException e) {
+                p.println("Error processing consumer POM: " + e);
+            }
+        } else {
+            pomArtifact.setFile(project.getFile());
+        }
 
         artifacts.put(pomArtifact, prefix + n);
         printFile(
                 prefix + n++,
                 pomArtifact.getGroupId(),
-                project.getFile(),
+                pomArtifact.getFile(),
                 project.getArtifactId() + '-' + project.getVersion() + ".pom");
 
         if (project.getArtifact() == null) {
@@ -189,6 +210,10 @@ class BuildInfoWriter {
         }
 
         for (Artifact attached : project.getAttachedArtifacts()) {
+            if (attached == consumerPom) {
+                // ignore consumer pom
+                continue;
+            }
             if (attached.getType().endsWith(".asc")) {
                 // ignore pgp signatures
                 continue;