You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2022/12/10 19:47:54 UTC

[GitHub] [maven] cstamas opened a new pull request, #907: Maven Transformation

cstamas opened a new pull request, #907:
URL: https://github.com/apache/maven/pull/907

   This plugins does the "half" of the job: on lifecycle begin a transformed POM is added to project, and everything, even GPG plugin processes it as expected.
   
   Now next step is "swapping" it at the right moment...
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] rfscholte commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by "rfscholte (via GitHub)" <gi...@apache.org>.
rfscholte commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1084022171


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.function.BiConsumer;
+
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.DefaultBuildPomXMLFilterFactory;
+import org.apache.maven.model.building.TransformerContext;
+import org.apache.maven.model.transform.RawToConsumerPomXMLFilterFactory;
+import org.apache.maven.model.transform.pull.XmlUtils;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.ProjectArtifact;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
+import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
+import org.codehaus.plexus.util.xml.pull.MXParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM transformer.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named("consumer-pom")
+public final class ConsumerPomArtifactTransformer {
+
+    private static final String CONSUMER_POM_CLASSIFIER = "maven-consumer-pom";
+
+    public void injectTransformedArtifacts(MavenProject project, RepositorySystemSession session) throws IOException {
+        if (isActive(session)) {
+            Path generatedFile;
+            String buildDirectory =
+                    project.getBuild() != null ? project.getBuild().getDirectory() : null;
+            if (buildDirectory == null) {
+                generatedFile = Files.createTempFile(CONSUMER_POM_CLASSIFIER, "pom");
+            } else {
+                Path buildDir = Paths.get(buildDirectory);
+                Files.createDirectories(buildDir);
+                generatedFile = Files.createTempFile(buildDir, CONSUMER_POM_CLASSIFIER, "pom");
+            }
+            project.addAttachedArtifact(new ConsumerPomArtifact(project, generatedFile, session));

Review Comment:
   So during the build you could gain access to the consumer-pom via the projects attachments? That doesn't look correct. However, it looks like a required for gpg. For me the moment the FileTransformer kicked in was the preferred moment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1345636848

   This was more to address @rfscholte concerns...


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1045528456


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/TransformedArtifact.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.MessageDigest;
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+
+/**
+ * Transformed artifact is derived with some transformation from source artifact.
+ *
+ * @since TBD
+ */
+public abstract class TransformedArtifact extends DefaultArtifact {
+
+    private final OnChangeTransformer onChangeTransformer;
+
+    public TransformedArtifact(
+            Artifact source,
+            Supplier<Path> sourcePathProvider,
+            String classifier,
+            String extension,
+            Path targetPath,
+            BiConsumer<Path, Path> transformerConsumer) {
+        super(
+                source.getGroupId(),
+                source.getArtifactId(),
+                source.getVersionRange(),
+                source.getScope(),
+                extension,
+                classifier,
+                new TransformedArtifactHandler(
+                        classifier, extension, source.getArtifactHandler().getPackaging()));
+        this.onChangeTransformer =
+                new OnChangeTransformer(sourcePathProvider, targetPath, TransformedArtifact::sha1, transformerConsumer);
+    }
+
+    @Override
+    public boolean isResolved() {
+        return getFile() != null;
+    }
+
+    @Override
+    public void setFile(File file) {
+        throw new IllegalStateException("transformed artifact file cannot be set");
+    }
+
+    @Override
+    public File getFile() {
+        Path result = onChangeTransformer.get();
+        if (result == null) {
+            return null;
+        }
+        return result.toFile();
+    }
+
+    private static final int BUFFER_SIZE = 8192;
+
+    private static String sha1(Path path) {
+        try {
+            MessageDigest md = MessageDigest.getInstance("SHA-1");
+            try (InputStream fis = new BufferedInputStream(Files.newInputStream(path), BUFFER_SIZE)) {

Review Comment:
   Um, I don't think so.... Files.newInputStream returns _unbuffered_ stream, unless am mistaken...



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas merged pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by "cstamas (via GitHub)" <gi...@apache.org>.
cstamas merged PR #907:
URL: https://github.com/apache/maven/pull/907


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] rfscholte commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
rfscholte commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1047135097


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ArtifactTransformer.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import java.io.IOException;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Artifact transformer component.
+ * <p>
+ * Note: this interface is Maven internal component, subject to change or removal without notice.
+ *
+ * @since TBD
+ */
+public interface ArtifactTransformer {

Review Comment:
   Is the pom an artifact or is it the metadata for the artifact and subartifacts? Just wondering if the class has the right name. (hence why i called it FileTransformer to cover both)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1345634598

   And one more thing:
   * while artifact is added early, the content is NOT, content is added on very first consumerPom.getFile() call
   * it is being written to randomized file, so hard to "catch" and possibly rewrite
   * while it is not being deleted, we could do that as well if needed


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] michael-o commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
michael-o commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1346145690

   I think this needs to be turned into a draft.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1045591133


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/TransformedArtifact.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.MessageDigest;
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+
+/**
+ * Transformed artifact is derived with some transformation from source artifact.
+ *
+ * @since TBD
+ */
+public abstract class TransformedArtifact extends DefaultArtifact {
+
+    private final OnChangeTransformer onChangeTransformer;
+
+    public TransformedArtifact(
+            Artifact source,
+            Supplier<Path> sourcePathProvider,
+            String classifier,
+            String extension,
+            Path targetPath,
+            BiConsumer<Path, Path> transformerConsumer) {
+        super(
+                source.getGroupId(),
+                source.getArtifactId(),
+                source.getVersionRange(),
+                source.getScope(),
+                extension,
+                classifier,
+                new TransformedArtifactHandler(
+                        classifier, extension, source.getArtifactHandler().getPackaging()));
+        this.onChangeTransformer =
+                new OnChangeTransformer(sourcePathProvider, targetPath, TransformedArtifact::sha1, transformerConsumer);
+    }
+
+    @Override
+    public boolean isResolved() {
+        return getFile() != null;
+    }
+
+    @Override
+    public void setFile(File file) {
+        throw new IllegalStateException("transformed artifact file cannot be set");
+    }
+
+    @Override
+    public File getFile() {
+        Path result = onChangeTransformer.get();
+        if (result == null) {
+            return null;
+        }
+        return result.toFile();
+    }
+
+    private static final int BUFFER_SIZE = 8192;
+
+    private static String sha1(Path path) {
+        try {
+            MessageDigest md = MessageDigest.getInstance("SHA-1");
+            try (InputStream fis = new BufferedInputStream(Files.newInputStream(path), BUFFER_SIZE)) {

Review Comment:
   Removed buffered input stream



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] gnodet commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
gnodet commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1045541829


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/TransformedArtifact.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.MessageDigest;
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+
+/**
+ * Transformed artifact is derived with some transformation from source artifact.
+ *
+ * @since TBD
+ */
+public abstract class TransformedArtifact extends DefaultArtifact {
+
+    private final OnChangeTransformer onChangeTransformer;
+
+    public TransformedArtifact(
+            Artifact source,
+            Supplier<Path> sourcePathProvider,
+            String classifier,
+            String extension,
+            Path targetPath,
+            BiConsumer<Path, Path> transformerConsumer) {
+        super(
+                source.getGroupId(),
+                source.getArtifactId(),
+                source.getVersionRange(),
+                source.getScope(),
+                extension,
+                classifier,
+                new TransformedArtifactHandler(
+                        classifier, extension, source.getArtifactHandler().getPackaging()));
+        this.onChangeTransformer =
+                new OnChangeTransformer(sourcePathProvider, targetPath, TransformedArtifact::sha1, transformerConsumer);
+    }
+
+    @Override
+    public boolean isResolved() {
+        return getFile() != null;
+    }
+
+    @Override
+    public void setFile(File file) {
+        throw new IllegalStateException("transformed artifact file cannot be set");
+    }
+
+    @Override
+    public File getFile() {
+        Path result = onChangeTransformer.get();
+        if (result == null) {
+            return null;
+        }
+        return result.toFile();
+    }
+
+    private static final int BUFFER_SIZE = 8192;
+
+    private static String sha1(Path path) {
+        try {
+            MessageDigest md = MessageDigest.getInstance("SHA-1");
+            try (InputStream fis = new BufferedInputStream(Files.newInputStream(path), BUFFER_SIZE)) {

Review Comment:
   Yes, but the stream is read using a `read(buffer)` which achieves the same effect than the `BufferedInputStream.  So we end up reading into a buffer, then transferring into another buffer. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] michael-o commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1083987725


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.function.BiConsumer;
+
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.DefaultBuildPomXMLFilterFactory;
+import org.apache.maven.model.building.TransformerContext;
+import org.apache.maven.model.transform.RawToConsumerPomXMLFilterFactory;
+import org.apache.maven.model.transform.pull.XmlUtils;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.ProjectArtifact;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
+import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
+import org.codehaus.plexus.util.xml.pull.MXParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM transformer.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named("consumer-pom")
+public final class ConsumerPomArtifactTransformer {
+
+    private static final String CONSUMER_POM_CLASSIFIER = "maven-consumer-pom";

Review Comment:
   I think this classifer contains at least two redundant elements: `maven` and `pom` since both are already implied. Classifier `consumer` is enough, IMHO.



##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.function.BiConsumer;
+
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.DefaultBuildPomXMLFilterFactory;
+import org.apache.maven.model.building.TransformerContext;
+import org.apache.maven.model.transform.RawToConsumerPomXMLFilterFactory;
+import org.apache.maven.model.transform.pull.XmlUtils;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.ProjectArtifact;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
+import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
+import org.codehaus.plexus.util.xml.pull.MXParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM transformer.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named("consumer-pom")
+public final class ConsumerPomArtifactTransformer {
+
+    private static final String CONSUMER_POM_CLASSIFIER = "maven-consumer-pom";
+
+    public void injectTransformedArtifacts(MavenProject project, RepositorySystemSession session) throws IOException {
+        if (isActive(session)) {
+            Path generatedFile;
+            String buildDirectory =
+                    project.getBuild() != null ? project.getBuild().getDirectory() : null;
+            if (buildDirectory == null) {
+                generatedFile = Files.createTempFile(CONSUMER_POM_CLASSIFIER, "pom");
+            } else {
+                Path buildDir = Paths.get(buildDirectory);
+                Files.createDirectories(buildDir);
+                generatedFile = Files.createTempFile(buildDir, CONSUMER_POM_CLASSIFIER, "pom");
+            }
+            project.addAttachedArtifact(new ConsumerPomArtifact(project, generatedFile, session));

Review Comment:
   Don't forget that the perms are different here. No issues with that?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] michael-o commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
michael-o commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1045275559


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.function.BiConsumer;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.TransformerContext;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.ProjectArtifact;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM transformer.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named("consumer-pom")
+public final class ConsumerPomArtifactTransformer implements ArtifactTransformer {
+    private static final String CLASSIFIER = "maven-consumer-pom";

Review Comment:
   here as well



##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.function.BiConsumer;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.TransformerContext;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.ProjectArtifact;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM transformer.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named("consumer-pom")
+public final class ConsumerPomArtifactTransformer implements ArtifactTransformer {
+    private static final String CLASSIFIER = "maven-consumer-pom";
+
+    private static final String EXTENSION = "pom";
+
+    @Override
+    public void injectTransformedArtifacts(MavenProject project, RepositorySystemSession session) throws IOException {
+        if (isActive(session)) {
+            Path generatedFile;
+            String buildDirectory =
+                    project.getBuild() != null ? project.getBuild().getDirectory() : null;
+            if (buildDirectory == null) {
+                generatedFile = Files.createTempFile(CLASSIFIER, EXTENSION);
+            } else {
+                Path buildDir = Paths.get(buildDirectory);
+                Files.createDirectories(buildDir);
+                generatedFile = Files.createTempFile(buildDir, CLASSIFIER, EXTENSION);
+            }
+            project.addAttachedArtifact(new ConsumerPomArtifact(project, generatedFile, session));
+        }
+    }
+
+    @Override
+    public InstallRequest remapInstallArtifacts(RepositorySystemSession session, InstallRequest request) {
+        if (isActive(session) && consumerPomPresent(request.getArtifacts())) {
+            request.setArtifacts(replacePom(request.getArtifacts()));
+        }
+        return request;
+    }
+
+    @Override
+    public DeployRequest remapDeployArtifacts(RepositorySystemSession session, DeployRequest request) {
+        if (isActive(session) && consumerPomPresent(request.getArtifacts())) {
+            request.setArtifacts(replacePom(request.getArtifacts()));
+        }
+        return request;
+    }
+
+    private boolean isActive(RepositorySystemSession session) {
+        return Features.buildConsumer(session.getUserProperties()).isActive();
+    }
+
+    private boolean consumerPomPresent(Collection<Artifact> artifacts) {
+        return artifacts.stream()
+                .anyMatch(a -> CLASSIFIER.equals(a.getClassifier()) && EXTENSION.equals(a.getExtension()));
+    }
+
+    private Collection<Artifact> replacePom(Collection<Artifact> artifacts) {
+        ArrayList<Artifact> result = new ArrayList<>(artifacts.size());
+        for (Artifact artifact : artifacts) {
+            if (CLASSIFIER.equals(artifact.getClassifier())
+                    && artifact.getExtension().startsWith(EXTENSION)) {
+                DefaultArtifact remapped = new DefaultArtifact(
+                        artifact.getGroupId(),
+                        artifact.getArtifactId(),
+                        "",
+                        artifact.getExtension(),
+                        artifact.getVersion(),
+                        artifact.getProperties(),
+                        artifact.getFile());
+                result.add(remapped);
+            } else if (!("".equals(artifact.getClassifier())

Review Comment:
   why not `isEmpty()`?



##########
maven-core/src/main/java/org/apache/maven/internal/transformation/OnChangeTransformer.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+/**
+ * Keeps transformed file up-to-date relative to its source file. It manages state (i.e. hashing the content) using
+ * passed in stateFunction, and transforms when needed using passed in transformer bi-consumer.
+ * <p>
+ * Covered cases:
+ * <ul>
+ *     <li>when source supplier returns {@code null}, this class will return {@code null}.</li>
+ *     <li>when source supplier returns non existing path, this class will return non existing path.</li>

Review Comment:
   Why not `null` here?



##########
maven-core/src/main/java/org/apache/maven/internal/transformation/OnChangeTransformer.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+/**
+ * Keeps transformed file up-to-date relative to its source file. It manages state (i.e. hashing the content) using
+ * passed in stateFunction, and transforms when needed using passed in transformer bi-consumer.
+ * <p>
+ * Covered cases:
+ * <ul>
+ *     <li>when source supplier returns {@code null}, this class will return {@code null}.</li>
+ *     <li>when source supplier returns non existing path, this class will return non existing path.</li>
+ *     <li>when source supplier returns existing path, this class will ensure transformation is in sync.</li>
+ * </ul>
+ *
+ * @since TBD
+ */
+public final class OnChangeTransformer implements Supplier<Path> {
+    private final Supplier<Path> source;

Review Comment:
   here as well



##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.function.BiConsumer;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.TransformerContext;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.ProjectArtifact;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM transformer.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named("consumer-pom")
+public final class ConsumerPomArtifactTransformer implements ArtifactTransformer {
+    private static final String CLASSIFIER = "maven-consumer-pom";
+
+    private static final String EXTENSION = "pom";
+
+    @Override
+    public void injectTransformedArtifacts(MavenProject project, RepositorySystemSession session) throws IOException {
+        if (isActive(session)) {
+            Path generatedFile;
+            String buildDirectory =
+                    project.getBuild() != null ? project.getBuild().getDirectory() : null;
+            if (buildDirectory == null) {
+                generatedFile = Files.createTempFile(CLASSIFIER, EXTENSION);
+            } else {
+                Path buildDir = Paths.get(buildDirectory);
+                Files.createDirectories(buildDir);
+                generatedFile = Files.createTempFile(buildDir, CLASSIFIER, EXTENSION);
+            }
+            project.addAttachedArtifact(new ConsumerPomArtifact(project, generatedFile, session));
+        }
+    }
+
+    @Override
+    public InstallRequest remapInstallArtifacts(RepositorySystemSession session, InstallRequest request) {
+        if (isActive(session) && consumerPomPresent(request.getArtifacts())) {
+            request.setArtifacts(replacePom(request.getArtifacts()));
+        }
+        return request;
+    }
+
+    @Override
+    public DeployRequest remapDeployArtifacts(RepositorySystemSession session, DeployRequest request) {
+        if (isActive(session) && consumerPomPresent(request.getArtifacts())) {
+            request.setArtifacts(replacePom(request.getArtifacts()));
+        }
+        return request;
+    }
+
+    private boolean isActive(RepositorySystemSession session) {
+        return Features.buildConsumer(session.getUserProperties()).isActive();
+    }
+
+    private boolean consumerPomPresent(Collection<Artifact> artifacts) {
+        return artifacts.stream()
+                .anyMatch(a -> CLASSIFIER.equals(a.getClassifier()) && EXTENSION.equals(a.getExtension()));
+    }
+
+    private Collection<Artifact> replacePom(Collection<Artifact> artifacts) {
+        ArrayList<Artifact> result = new ArrayList<>(artifacts.size());
+        for (Artifact artifact : artifacts) {
+            if (CLASSIFIER.equals(artifact.getClassifier())
+                    && artifact.getExtension().startsWith(EXTENSION)) {
+                DefaultArtifact remapped = new DefaultArtifact(
+                        artifact.getGroupId(),
+                        artifact.getArtifactId(),
+                        "",
+                        artifact.getExtension(),
+                        artifact.getVersion(),
+                        artifact.getProperties(),
+                        artifact.getFile());
+                result.add(remapped);
+            } else if (!("".equals(artifact.getClassifier())
+                    && artifact.getExtension().startsWith("pom"))) {

Review Comment:
   `EXTENSION`?



##########
maven-core/src/main/java/org/apache/maven/internal/transformation/OnChangeTransformer.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
+import java.util.function.Supplier;
+
+/**
+ * Keeps transformed file up-to-date relative to its source file. It manages state (i.e. hashing the content) using
+ * passed in stateFunction, and transforms when needed using passed in transformer bi-consumer.
+ * <p>
+ * Covered cases:
+ * <ul>
+ *     <li>when source supplier returns {@code null}, this class will return {@code null}.</li>
+ *     <li>when source supplier returns non existing path, this class will return non existing path.</li>
+ *     <li>when source supplier returns existing path, this class will ensure transformation is in sync.</li>
+ * </ul>
+ *
+ * @since TBD
+ */
+public final class OnChangeTransformer implements Supplier<Path> {
+    private final Supplier<Path> source;
+
+    private final Path target;
+
+    private final Function<Path, String> stateFunction;
+
+    private final BiConsumer<Path, Path> transformerConsumer;
+
+    private final AtomicReference<String> sourceState;
+
+    public OnChangeTransformer(
+            Supplier<Path> source,
+            Path target,
+            Function<Path, String> stateFunction,
+            BiConsumer<Path, Path> transformerConsumer) {
+        this.source = requireNonNull(source);
+        this.target = requireNonNull(target);
+        this.stateFunction = requireNonNull(stateFunction);
+        this.transformerConsumer = requireNonNull(transformerConsumer);
+        this.sourceState = new AtomicReference<>(null);
+    }
+
+    @Override
+    public synchronized Path get() {
+        String state = mayUpdate();
+        if (state == null) {
+            return null;
+        }
+        return target;
+    }
+
+    private String mayUpdate() {
+        String result;
+        try {
+            Path src = source.get();
+            if (src == null) {
+                Files.deleteIfExists(target);
+                result = null;
+            } else if (!Files.exists(src)) {
+                Files.deleteIfExists(target);
+                result = "";
+            } else {
+                String current = stateFunction.apply(src);
+                String existing = sourceState.get();
+                if (!Objects.equals(current, existing)) {
+                    transformerConsumer.accept(src, target);
+                    Files.setLastModifiedTime(target, Files.getLastModifiedTime(src));

Review Comment:
   Would it make sense to copy all attributes?



##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ArtifactTransformer.java:
##########
@@ -0,0 +1,44 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import java.io.IOException;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Artifact transformer component.
+ * <p>
+ * Note: this interface is Maven internal component, subject to change or removal without notice.
+ *
+ * @since TBD
+ */
+public interface ArtifactTransformer {
+    void injectTransformedArtifacts(MavenProject project, RepositorySystemSession session) throws IOException;

Review Comment:
   Add an empty line for readability.



##########
maven-core/src/main/java/org/apache/maven/internal/transformation/TransformedArtifact.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.MessageDigest;
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+
+/**
+ * Transformed artifact is derived with some transformation from source artifact.
+ *
+ * @since TBD
+ */
+public abstract class TransformedArtifact extends DefaultArtifact {
+    private final OnChangeTransformer onChangeTransformer;
+
+    public TransformedArtifact(
+            Artifact source,
+            Supplier<Path> sourcePathProvider,
+            String classifier,
+            String extension,
+            Path targetPath,
+            BiConsumer<Path, Path> transformerConsumer) {
+        super(
+                source.getGroupId(),
+                source.getArtifactId(),
+                source.getVersionRange(),
+                source.getScope(),
+                extension,
+                classifier,
+                new TransformedArtifactHandler(
+                        classifier, extension, source.getArtifactHandler().getPackaging()));
+        this.onChangeTransformer =
+                new OnChangeTransformer(sourcePathProvider, targetPath, TransformedArtifact::sha1, transformerConsumer);
+    }
+
+    @Override
+    public boolean isResolved() {
+        return getFile() != null;
+    }
+
+    @Override
+    public void setFile(File file) {
+        throw new IllegalStateException("transformed artifact file cannot be set");
+    }
+
+    @Override
+    public File getFile() {
+        Path result = onChangeTransformer.get();
+        if (result == null) {
+            return null;
+        }
+        return result.toFile();
+    }
+
+    private static final int BUFFER_SIZE = 8192;
+
+    private static String sha1(Path path) {
+        try {
+            MessageDigest md = MessageDigest.getInstance("SHA-1");
+            try (InputStream fis = new BufferedInputStream(Files.newInputStream(path), BUFFER_SIZE)) {
+                byte[] buffer = new byte[BUFFER_SIZE];
+                int read;
+                while ((read = fis.read(buffer)) != -1) {
+                    md.update(buffer, 0, read);
+                }
+            }
+            StringBuilder result = new StringBuilder();
+            for (byte b : md.digest()) {
+                result.append(String.format("%02x", b));
+            }
+            return result.toString();

Review Comment:
   Ouch, we have done this over and over :-(



##########
maven-core/src/main/java/org/apache/maven/lifecycle/internal/builder/BuilderCommon.java:
##########
@@ -110,24 +107,6 @@ public MavenExecutionPlan resolveBuildPlan(
 
         lifecycleDebugLogger.debugProjectPlan(project, executionPlan);
 
-        // With Maven 4's build/consumer the POM will always rewrite during distribution.
-        // The maven-gpg-plugin uses the original POM, causing an invalid signature.
-        // Fail as long as there's no solution available yet
-        Properties userProperties = session.getUserProperties();
-        if (Features.buildConsumer(userProperties).isActive()) {
-            Optional<MojoExecution> gpgMojo = executionPlan.getMojoExecutions().stream()
-                    .filter(m -> "maven-gpg-plugin".equals(m.getArtifactId())
-                            && "org.apache.maven.plugins".equals(m.getGroupId()))
-                    .findAny();
-
-            if (gpgMojo.isPresent()) {
-                throw new LifecycleExecutionException("The maven-gpg-plugin is not supported by Maven 4."
-                        + " Verify if there is a compatible signing solution,"
-                        + " add -D" + Features.buildConsumer(userProperties).propertyName() + "=false"
-                        + " or use Maven 3.");
-            }
-        }

Review Comment:
   This now works because it uses a temp file which GPG can use?



##########
maven-core/src/main/java/org/apache/maven/internal/transformation/TransformedArtifact.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.MessageDigest;
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+
+/**
+ * Transformed artifact is derived with some transformation from source artifact.
+ *
+ * @since TBD
+ */
+public abstract class TransformedArtifact extends DefaultArtifact {
+    private final OnChangeTransformer onChangeTransformer;

Review Comment:
   here as well



##########
maven-core/src/main/java/org/apache/maven/internal/transformation/TransformedArtifact.java:
##########
@@ -0,0 +1,145 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.MessageDigest;
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+
+/**
+ * Transformed artifact is derived with some transformation from source artifact.
+ *
+ * @since TBD
+ */
+public abstract class TransformedArtifact extends DefaultArtifact {
+    private final OnChangeTransformer onChangeTransformer;
+
+    public TransformedArtifact(
+            Artifact source,
+            Supplier<Path> sourcePathProvider,
+            String classifier,
+            String extension,
+            Path targetPath,
+            BiConsumer<Path, Path> transformerConsumer) {
+        super(
+                source.getGroupId(),
+                source.getArtifactId(),
+                source.getVersionRange(),
+                source.getScope(),
+                extension,
+                classifier,
+                new TransformedArtifactHandler(
+                        classifier, extension, source.getArtifactHandler().getPackaging()));
+        this.onChangeTransformer =
+                new OnChangeTransformer(sourcePathProvider, targetPath, TransformedArtifact::sha1, transformerConsumer);
+    }
+
+    @Override
+    public boolean isResolved() {
+        return getFile() != null;
+    }
+
+    @Override
+    public void setFile(File file) {
+        throw new IllegalStateException("transformed artifact file cannot be set");
+    }
+
+    @Override
+    public File getFile() {
+        Path result = onChangeTransformer.get();
+        if (result == null) {
+            return null;
+        }
+        return result.toFile();
+    }
+
+    private static final int BUFFER_SIZE = 8192;
+
+    private static String sha1(Path path) {
+        try {
+            MessageDigest md = MessageDigest.getInstance("SHA-1");
+            try (InputStream fis = new BufferedInputStream(Files.newInputStream(path), BUFFER_SIZE)) {
+                byte[] buffer = new byte[BUFFER_SIZE];
+                int read;
+                while ((read = fis.read(buffer)) != -1) {
+                    md.update(buffer, 0, read);
+                }
+            }
+            StringBuilder result = new StringBuilder();
+            for (byte b : md.digest()) {
+                result.append(String.format("%02x", b));
+            }
+            return result.toString();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private static class TransformedArtifactHandler implements ArtifactHandler {
+        private final String classifier;

Review Comment:
   here as well



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1345627596

   One addendum: "at the end it will replace the actual POM wioth the consumer POM quite same as maven-shade-plugin"... a bit more: it intentionally use `startsWith` for extension, as it not replaces _only the POM_ but all the "whistle and bells" (signature, checksum, whatever) it may have more....


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] michael-o commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
michael-o commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1045299177


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java:
##########
@@ -144,4 +152,17 @@ private static BiConsumer<Path, Path> transformer(RepositorySystemSession sessio
             };
         }
     }
+
+    /**
+     * The actual transformation: visible for testing.
+     */
+    static InputStream transform(Path pomFile, TransformerContext context) throws IOException, XmlPullParserException {
+        XmlStreamReader reader = ReaderFactory.newXmlReader(Files.newInputStream(pomFile));
+        XmlPullParser parser = new MXParser( EntityReplacementMap.defaultEntityReplacementMap);

Review Comment:
   whitespace



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] michael-o commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
michael-o commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1345628665

   > One addendum: "at the end it will replace the actual POM with the consumer POM quite same as maven-shade-plugin"... a bit more: it intentionally use `startsWith` for extension, as it not replaces _only the POM_ but all the "whistle and bells" (signature, checksum, whatever) it may have more.... and that _is the key_ thing here, and that enables today's m-gpg-p to function.
   
   Then it would also replace `.pompom` which is not what you want, no? I guess you want either exact `.pom` or starts with `.pom.`, on?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1045564744


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ArtifactTransformer.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import java.io.IOException;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Artifact transformer component.
+ * <p>
+ * Note: this interface is Maven internal component, subject to change or removal without notice.
+ *
+ * @since TBD
+ */
+public interface ArtifactTransformer {

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by "cstamas (via GitHub)" <gi...@apache.org>.
cstamas commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1086449496


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.function.BiConsumer;
+
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.DefaultBuildPomXMLFilterFactory;
+import org.apache.maven.model.building.TransformerContext;
+import org.apache.maven.model.transform.RawToConsumerPomXMLFilterFactory;
+import org.apache.maven.model.transform.pull.XmlUtils;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.ProjectArtifact;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
+import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
+import org.codehaus.plexus.util.xml.pull.MXParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM transformer.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named("consumer-pom")
+public final class ConsumerPomArtifactTransformer {
+
+    private static final String CONSUMER_POM_CLASSIFIER = "maven-consumer-pom";

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1345629202

   > Then it would also replace `.pompom` which is not what you want, no? I guess you want either exact `.pom` or starts with `.pom.`, on?
   
   Yes, I bet there are some rough edges we need to clear up (like inlined sha1, the CLASSIFIER/EXTENSION), but in general, it places consumer pom under CLASSIFIER, so IMHO -- unsure, just tinkering -- what it should do is:
   * remove all artifacts that has no classifier and extension "pom" (or starts with, like "pom.asc")
   * "relocated" all artifact with CLASSIFIER into "no classifier" (so if there is "pompom" under CLASSIFIER, that too).
   
   Is like moving a "group", whatever artifact has classifier CLASSIFIER should have CLASSIFIER removed, that's all.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] michael-o commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
michael-o commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1345626511

   > Several "global" remarks:
   > 
   >     * re empty line: you are arguing with our new code formatter, not me ๐Ÿ˜„
   
   Darn!
   
   >     * re EXTENSION/"pom" - I did it intentionally like this to make clear that we attach CLASSIFIER/EXTENSION transformed artifact (CLASSIFIER and EXTENSION could be really ANYTHING), while we REPLACE always the POM (so classifier "" and extension "pom"). So I consider your remark as wrong, as EXTENSION currently "just happens" to be same as "pom", we could make it "consumer-super-duper-pom" as well if needed.
   
   I accept this, then the code requires a single line comment to make the intent clear.
   
   >     * re null vs non existent file: as we need and do same as "source" artifact do, we really mimic what it does return, and non-null file but not existing backing file on disk is one of the cases we need to cover.
   
   Hmm, but returning `""` will give `new File("")` which is valid, no?
   
   >     * re sha1: yes, I just inlined it in here but it can be really anything (or just some guava util, but I did not want to use guava, while i did not find anything suitable for this case...)
   
   Yeah, just wanted to express that we did it again.
   
   >     * "it now works".... yes, ITs pass _unmodified_, so this PR achieves same functionality as existing code on master, but it does not use FileTransformer API. OTOH, it "works" with m-gpg-p for reason that "consumer POM" _is present_ as attached artifact from earliest moment, and gpg just finds it and signs it (same for checksum-m-p or whatever other use case). At the end, we "remap" the consumer POM as "main" POM
   
   Ah ok, at the end it will replace the actual POM wioth the consumer POM quite same as maven-shade-plugin can do with the main artifact?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1345625479

   Several "global" remarks:
   * re empty line: you are arguing with our new code formatter, not me :smile:
   * re EXTENSION/"pom" - I did it intentionally like this to make clear that we attach CLASSIFIER/EXTENSION transformed artifact (CLASSIFIER and EXTENSION could be really ANYTHING), while we REPLACE always the POM (so classifier "" and extension "pom"). So I consider your remark as wrong, as EXTENSION currently "just happens" to be same as "pom", we could make it "consumer-super-duper-pom" as well if needed.
   * re null vs non existent file: as we need and do same as "source" artifact do, we really mimic what it does return, and non-null file but not existing backing file on disk is one of the cases we need to cover.
   * re sha1: yes, I just inlined it in here but it can be really anything (or just some guava util, but I did not want to use guava, while i did not find anything suitable for this case...)
   * "it now works".... yes, ITs pass _unmodified_, so this PR achieves same functionality as existing code on master, but it does not use FileTransformer API. OTOH, it "works" with m-gpg-p for reason that "consumer POM" _is present_ as attached artifact from earliest moment, and gpg just finds it and signs it (same for checksum-m-p or whatever other use case). At the end, we "remap" the consumer POM as "main" POM


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] michael-o commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
michael-o commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1346244136

   > > I think this needs to be turned into a draft.
   > 
   > Why? I don't get it what would make that different?
   
   Because it seems to me that you are still working on it, no?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1346245435

   Well, all I do is applying PR comments, no?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] rfscholte commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by "rfscholte (via GitHub)" <gi...@apache.org>.
rfscholte commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1399226079

   Although I don't prefer writing temporary files just for distribution, it would solve the issue for gpg. That buys the team time to spend on other blocking issues.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1398620400

   @michael-o pls review


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] gnodet commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
gnodet commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1045525901


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/TransformedArtifact.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import static java.util.Objects.requireNonNull;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.MessageDigest;
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+
+/**
+ * Transformed artifact is derived with some transformation from source artifact.
+ *
+ * @since TBD
+ */
+public abstract class TransformedArtifact extends DefaultArtifact {
+
+    private final OnChangeTransformer onChangeTransformer;
+
+    public TransformedArtifact(
+            Artifact source,
+            Supplier<Path> sourcePathProvider,
+            String classifier,
+            String extension,
+            Path targetPath,
+            BiConsumer<Path, Path> transformerConsumer) {
+        super(
+                source.getGroupId(),
+                source.getArtifactId(),
+                source.getVersionRange(),
+                source.getScope(),
+                extension,
+                classifier,
+                new TransformedArtifactHandler(
+                        classifier, extension, source.getArtifactHandler().getPackaging()));
+        this.onChangeTransformer =
+                new OnChangeTransformer(sourcePathProvider, targetPath, TransformedArtifact::sha1, transformerConsumer);
+    }
+
+    @Override
+    public boolean isResolved() {
+        return getFile() != null;
+    }
+
+    @Override
+    public void setFile(File file) {
+        throw new IllegalStateException("transformed artifact file cannot be set");
+    }
+
+    @Override
+    public File getFile() {
+        Path result = onChangeTransformer.get();
+        if (result == null) {
+            return null;
+        }
+        return result.toFile();
+    }
+
+    private static final int BUFFER_SIZE = 8192;
+
+    private static String sha1(Path path) {
+        try {
+            MessageDigest md = MessageDigest.getInstance("SHA-1");
+            try (InputStream fis = new BufferedInputStream(Files.newInputStream(path), BUFFER_SIZE)) {

Review Comment:
   No need for a `BufferedInputStream` as the stream is already read using a buffer.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1047185218


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ArtifactTransformer.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import java.io.IOException;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Artifact transformer component.
+ * <p>
+ * Note: this interface is Maven internal component, subject to change or removal without notice.
+ *
+ * @since TBD
+ */
+public interface ArtifactTransformer {

Review Comment:
   POM is attached as Artifact (but this interface was removed since)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] michael-o commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
michael-o commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1345635241

   > And one more thing:
   > 
   >     * while artifact is added early, the content is NOT, content is added on very first consumerPom.getFile() call
   > 
   >     * it is being written to randomized file, so hard to "catch" and possibly rewrite
   > 
   >     * while it is not being deleted, we could do that as well if needed
   
   I don't expect any ephemeral files to be retained after completion. WDYT?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on pull request #907: Maven Transformation

Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1345378471

   Re IT failures:
    Tests run: 886, Failures: 3, Errors: 0, Skipped: 33
   
   As expected: two consumer POM ITs failed (as "swap in" is not done yet), and MavenITmng1021EqualAttachmentBuildNumberTest.testitMNG1021 fails that is surprised by attached new POM.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1345666091

   Um, unsure what this is:
   ```
   Error:  Errors: 
   Error:    MavenITmng4162ReportingMigrationTest.testit:66 NullPointer
   Warning: Tmng6189SiteReportPluginsWarningTest.testit:54 ยป Verification Text not found in log: [WARNING] Reporting configuration should be done in <reporting> section
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] michael-o commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by "michael-o (via GitHub)" <gi...@apache.org>.
michael-o commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1398939255

   Will schedule for next week. I'd like to hear a final word from @rfscholte.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by "cstamas (via GitHub)" <gi...@apache.org>.
cstamas commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1084058207


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ConsumerPomArtifactTransformer.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.function.BiConsumer;
+
+import org.apache.maven.feature.Features;
+import org.apache.maven.model.building.DefaultBuildPomXMLFilterFactory;
+import org.apache.maven.model.building.TransformerContext;
+import org.apache.maven.model.transform.RawToConsumerPomXMLFilterFactory;
+import org.apache.maven.model.transform.pull.XmlUtils;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.ProjectArtifact;
+import org.codehaus.plexus.util.ReaderFactory;
+import org.codehaus.plexus.util.xml.XmlStreamReader;
+import org.codehaus.plexus.util.xml.pull.EntityReplacementMap;
+import org.codehaus.plexus.util.xml.pull.MXParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParser;
+import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.artifact.DefaultArtifact;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Consumer POM transformer.
+ *
+ * @since TBD
+ */
+@Singleton
+@Named("consumer-pom")
+public final class ConsumerPomArtifactTransformer {
+
+    private static final String CONSUMER_POM_CLASSIFIER = "maven-consumer-pom";
+
+    public void injectTransformedArtifacts(MavenProject project, RepositorySystemSession session) throws IOException {
+        if (isActive(session)) {
+            Path generatedFile;
+            String buildDirectory =
+                    project.getBuild() != null ? project.getBuild().getDirectory() : null;
+            if (buildDirectory == null) {
+                generatedFile = Files.createTempFile(CONSUMER_POM_CLASSIFIER, "pom");
+            } else {
+                Path buildDir = Paths.get(buildDirectory);
+                Files.createDirectories(buildDir);
+                generatedFile = Files.createTempFile(buildDir, CONSUMER_POM_CLASSIFIER, "pom");
+            }
+            project.addAttachedArtifact(new ConsumerPomArtifact(project, generatedFile, session));

Review Comment:
   @michael-o fixed in resolver 1.9.4, that's not the case anymore.
   @rfscholte yes, as intention here is to make pgp plugin (and any other, like checksum) in unchanged way



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] michael-o commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
michael-o commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1345658760

   > @michael-o so ultimately, what changes did you request on this PR?
   
   The only the comment.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on pull request #907: Maven Transformation

Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1345378189

   To make this "complete", maven should wrap resolver installer/deployer like here https://github.com/apache/maven/pull/712 that should "swap in" the auto-attached POM (along with all related stuff like signatures or hashes) to main POM and done.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1345658118

   @michael-o so ultimately, what changes did you request on this PR?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] gnodet commented on a diff in pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
gnodet commented on code in PR #907:
URL: https://github.com/apache/maven/pull/907#discussion_r1045534915


##########
maven-core/src/main/java/org/apache/maven/internal/transformation/ArtifactTransformer.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+package org.apache.maven.internal.transformation;
+
+import java.io.IOException;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.RepositorySystemSession;
+import org.eclipse.aether.deployment.DeployRequest;
+import org.eclipse.aether.installation.InstallRequest;
+
+/**
+ * Artifact transformer component.
+ * <p>
+ * Note: this interface is Maven internal component, subject to change or removal without notice.
+ *
+ * @since TBD
+ */
+public interface ArtifactTransformer {

Review Comment:
   If we don't foresee any additional usage of this interface, I'd rather simply remove it and simply inject the `ConsumerPomArtifactTransformer`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [maven] cstamas commented on pull request #907: [MNG-7622] Maven Transformation and Consumer POM

Posted by GitBox <gi...@apache.org>.
cstamas commented on PR #907:
URL: https://github.com/apache/maven/pull/907#issuecomment-1346210555

   > I think this needs to be turned into a draft.
   
   Why? I don't get it what would make that different?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org