From aac4d9a5bb235593f18522c0348a5ad584f9e4b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Sun, 10 Mar 2024 09:24:02 +0100 Subject: [PATCH] MNG-8072 - add ConsumerPomFile methods Currently there is some vague definition of a "build pom" versus a "consumer pom": https://maven.apache.org/studies/consumer-pom/ https://cwiki.apache.org/confluence/display/MAVEN/Build+vs+Consumer+POM there are also some plugins around to work with this e.g. https://tycho.eclipseprojects.io/doc/latest/tycho-packaging-plugin/update-consumer-pom-mojo.html https://www.mojohaus.org/flatten-maven-plugin/plugin-info.html but there are some issues: Maven makes some assumptions about its "file", e.g setting the file changes the basedir Even though there is a setPomFile method that do not change the basedir e.g. a parent ref by default would be broken once we change the file, there is a mismatch between the pom on disk and the model it is not possible for a plugin to know the original file and the consumer file, e.g. if I want to deploy the original file e.g. with classifier "pom-build" because of this usually "consumer pom plugins" generate the the new pom to a new file in the project root, where it actually not belongs to and leaves the file even after mvn clean if no special actions are taken. This enhance the MavenProject with one more method set/getConsumerPom that fills this gap, then plugins working on the consumer pom can set the file there and where it then is used by other plugins. --- .../org/apache/maven/project/MavenProject.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java index 97d595291e1a..11ba4f8a4f3b 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProject.java @@ -103,6 +103,8 @@ public class MavenProject implements Cloneable { private File file; + private File consumerPomFile; + private File basedir; private Set resolvedArtifacts; @@ -256,6 +258,17 @@ public void setPomFile(File file) { this.file = file; } + public void setConsumerPomFile(File file) { + this.consumerPomFile = file; + } + + public File getConsumerPomFile() { + if (consumerPomFile == null) { + return getFile(); + } + return consumerPomFile; + } + public File getBasedir() { return basedir; } @@ -784,6 +797,7 @@ public Map> getInjectedProfileIds() { * @deprecated Please use {@link MavenProjectHelper} * @throws DuplicateArtifactAttachmentException will never happen but leave it for backward compatibility */ + @Deprecated public void addAttachedArtifact(Artifact artifact) throws DuplicateArtifactAttachmentException { // if already there we remove it and add again int index = attachedArtifacts.indexOf(artifact); @@ -1026,6 +1040,7 @@ private void deepCopy(MavenProject project) { // copy fields file = project.file; + this.consumerPomFile = project.consumerPomFile; basedir = project.basedir; // don't need a deep copy, they don't get modified or added/removed to/from - but make them unmodifiable to be