You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2021/10/13 20:48:32 UTC

[maven-artifact-plugin] branch master updated: [MARTIFACT-25] check pom.xml against reference .pom

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 584a72e  [MARTIFACT-25] check pom.xml against reference .pom
584a72e is described below

commit 584a72e2e85c74d0e521036cf21c1b06faed39bb
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Wed Oct 13 22:48:29 2021 +0200

    [MARTIFACT-25] check pom.xml against reference .pom
---
 src/it/buildinfo-mono/verify.groovy                |  3 +-
 src/it/buildinfo-multi/verify.groovy               |  6 +-
 src/it/buildinfo-skip-install-deploy/verify.groovy |  6 +-
 src/it/compare-mono/invoker.properties             | 19 ++++++
 src/it/compare-mono/pom.xml                        | 71 ++++++++++++++++++++++
 src/it/compare-mono/verify.groovy                  | 33 ++++++++++
 .../artifact/buildinfo/BuildInfoWriter.java        | 16 +++--
 .../plugins/artifact/buildinfo/CompareMojo.java    |  9 ++-
 .../artifact/buildinfo/ReferenceBuildinfoUtil.java |  4 +-
 9 files changed, 153 insertions(+), 14 deletions(-)

diff --git a/src/it/buildinfo-mono/verify.groovy b/src/it/buildinfo-mono/verify.groovy
index ff2d6e8..f1e35a1 100644
--- a/src/it/buildinfo-mono/verify.groovy
+++ b/src/it/buildinfo-mono/verify.groovy
@@ -25,7 +25,8 @@ assert buildinfoFile.isFile()
 // check generated buildinfo content
 String buildinfo = buildinfoFile.text
 
-assert buildinfo.contains( "outputs.0.filename=mono-1.0-SNAPSHOT.jar" )
+assert buildinfo.contains( "outputs.0.filename=mono-1.0-SNAPSHOT.pom" )
+assert buildinfo.contains( "outputs.1.filename=mono-1.0-SNAPSHOT.jar" )
 assert buildinfo.contains( "mvn.minimum.version=3.0.5" )
 
 // check existence of buildinfo in local repository
diff --git a/src/it/buildinfo-multi/verify.groovy b/src/it/buildinfo-multi/verify.groovy
index a0778a9..81e47b1 100644
--- a/src/it/buildinfo-multi/verify.groovy
+++ b/src/it/buildinfo-multi/verify.groovy
@@ -37,9 +37,11 @@ assert buildinfo.contains( "group-id=org.apache.maven.plugins.it" )
 assert buildinfo.contains( "artifact-id=multi" )
 assert buildinfo.contains( "version=1.0-SNAPSHOT" )
 assert buildinfo.contains( "outputs.1.coordinates=org.apache.maven.plugins.it:multi-modA" )
-assert buildinfo.contains( "outputs.1.0.filename=multi-modA-1.0-SNAPSHOT.jar" )
+assert buildinfo.contains( "outputs.1.0.filename=multi-modA-1.0-SNAPSHOT.pom" )
+assert buildinfo.contains( "outputs.1.1.filename=multi-modA-1.0-SNAPSHOT.jar" )
 assert buildinfo.contains( "outputs.2.coordinates=org.apache.maven.plugins.it:multi-modB" )
-assert buildinfo.contains( "outputs.2.0.filename=multi-modB-1.0-SNAPSHOT.jar" )
+assert buildinfo.contains( "outputs.2.0.filename=multi-modB-1.0-SNAPSHOT.pom" )
+assert buildinfo.contains( "outputs.2.1.filename=multi-modB-1.0-SNAPSHOT.jar" )
 assert !buildinfo.contains( ".buildinfo" )
 assert buildinfo.contains( "mvn.aggregate.artifact-id=multi-modB" )
 
diff --git a/src/it/buildinfo-skip-install-deploy/verify.groovy b/src/it/buildinfo-skip-install-deploy/verify.groovy
index bd814e1..2e4a479 100644
--- a/src/it/buildinfo-skip-install-deploy/verify.groovy
+++ b/src/it/buildinfo-skip-install-deploy/verify.groovy
@@ -34,9 +34,11 @@ assert buildinfo.contains( "group-id=org.apache.maven.plugins.it" )
 assert buildinfo.contains( "artifact-id=multi" )
 assert buildinfo.contains( "version=1.0-SNAPSHOT" )
 assert buildinfo.contains( "outputs.1.coordinates=org.apache.maven.plugins.it:multi-modA" )
-assert buildinfo.contains( "outputs.1.0.filename=multi-modA-1.0-SNAPSHOT.jar" )
+assert buildinfo.contains( "outputs.1.0.filename=multi-modA-1.0-SNAPSHOT.pom" )
+assert buildinfo.contains( "outputs.1.1.filename=multi-modA-1.0-SNAPSHOT.jar" )
 assert buildinfo.contains( "outputs.2.coordinates=org.apache.maven.plugins.it:multi-modB" )
-assert buildinfo.contains( "outputs.2.0.filename=multi-modB-1.0-SNAPSHOT.jar" )
+assert buildinfo.contains( "outputs.2.0.filename=multi-modB-1.0-SNAPSHOT.pom" )
+assert buildinfo.contains( "outputs.2.1.filename=multi-modB-1.0-SNAPSHOT.jar" )
 assert !buildinfo.contains( ".buildinfo" )
 assert !buildinfo.contains( "outputs.3" )
 
diff --git a/src/it/compare-mono/invoker.properties b/src/it/compare-mono/invoker.properties
new file mode 100644
index 0000000..339a145
--- /dev/null
+++ b/src/it/compare-mono/invoker.properties
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals.1=clean install
+invoker.goals.2=clean package artifact:compare
diff --git a/src/it/compare-mono/pom.xml b/src/it/compare-mono/pom.xml
new file mode 100644
index 0000000..5cef77e
--- /dev/null
+++ b/src/it/compare-mono/pom.xml
@@ -0,0 +1,71 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements. See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership. The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License. You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied. See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.it.compare</groupId>
+  <artifactId>mono</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <description>A simple IT verifying the basic use case of artifact:compare for mono-module build.</description>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.build.outputTimestamp>2019-12-03T10:04:00Z</project.build.outputTimestamp>
+  </properties>
+
+  <prerequisites>
+    <maven>3.0.5</maven>
+  </prerequisites>
+
+  <scm>
+    <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-studies.git</connection>
+    <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-studies.git</developerConnection>
+    <url>https://github.com/apache/maven-studies/tree/${project.scm.tag}</url>
+    <tag>maven-buildinfo-plugin</tag>
+  </scm>
+
+  <distributionManagement>
+    <snapshotRepository>
+      <id>local-snapshots</id>
+      <url>file://${basedir}/target/remote-repo</url>
+      <uniqueVersion>false</uniqueVersion>
+    </snapshotRepository>
+  </distributionManagement>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <artifactId>maven-jar-plugin</artifactId>
+          <version>2.4</version><!-- intentionally non-reproducible -->
+        </plugin>
+        <plugin>
+          <groupId>@project.groupId@</groupId>
+          <artifactId>@project.artifactId@</artifactId>
+          <version>@project.version@</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+  </build>
+</project>
diff --git a/src/it/compare-mono/verify.groovy b/src/it/compare-mono/verify.groovy
new file mode 100644
index 0000000..93f0bbf
--- /dev/null
+++ b/src/it/compare-mono/verify.groovy
@@ -0,0 +1,33 @@
+
+/*
+ * 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.
+ */
+
+// check existence of generated compare in target
+File compareFile = new File( basedir, "target/mono-1.0-SNAPSHOT.compare" );
+assert compareFile.isFile()
+
+// check generated compare content
+String compare = compareFile.text
+
+assert compare.contains( "version=1.0-SNAPSHOT" )
+assert compare.contains( "ok=1" )
+assert compare.contains( "ko=1" )
+assert compare.contains( 'okFiles="mono-1.0-SNAPSHOT.pom"' )
+assert compare.contains( 'koFiles="mono-1.0-SNAPSHOT.jar"' )
+assert compare.contains( '# diffoscope target/reference/mono-1.0-SNAPSHOT.jar target/mono-1.0-SNAPSHOT.jar' )
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java
index 9293ba4..4269831 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java
@@ -27,6 +27,7 @@ import java.util.Properties;
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.artifact.handler.ArtifactHandler;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.logging.Log;
@@ -160,11 +161,6 @@ class BuildInfoWriter
     void printArtifacts( MavenProject project )
         throws MojoExecutionException
     {
-        if ( project.getArtifact() == null )
-        {
-            return;
-        }
-
         String prefix = "outputs.";
         if ( !mono )
         {
@@ -176,6 +172,16 @@ class BuildInfoWriter
         }
 
         int n = 0;
+        artifacts.put( new DefaultArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), null,
+                                            "pom", "", null ),
+                       prefix + n );
+        printFile( prefix + n++, project.getFile(), project.getArtifactId() + '-' + project.getVersion() + ".pom" );
+
+        if ( project.getArtifact() == null )
+        {
+            return;
+        }
+
         if ( project.getArtifact().getFile() != null )
         {
             printArtifact( prefix, n++, project.getArtifact() );
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java
index adb07e1..0e77292 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java
@@ -151,15 +151,18 @@ public class CompareMojo
             Artifact artifact = entry.getKey();
             String prefix = entry.getValue();
 
-            String diffoscope = checkArtifact( artifact, prefix, reference, actual, referenceDir ); 
+            String diffoscope = checkArtifact( artifact, prefix, reference, actual, referenceDir );
+            String filename =
+                ( artifact.getFile() == null ) ? ( artifact.getArtifactId() + '-' + artifact.getVersion() + ".pom" )
+                                : artifact.getFile().getName();
             if ( diffoscope == null )
             {
                 ok++;
-                okFilenames.add( artifact.getFile().getName() );
+                okFilenames.add( filename );
             }
             else
             {
-                koFilenames.add( artifact.getFile().getName() );
+                koFilenames.add( filename );
                 diffoscopes.add( diffoscope );
             }
         }
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/ReferenceBuildinfoUtil.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/ReferenceBuildinfoUtil.java
index a7f9de6..c67e357 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/ReferenceBuildinfoUtil.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/ReferenceBuildinfoUtil.java
@@ -317,7 +317,9 @@ class ReferenceBuildinfoUtil
             ArtifactRequest request = new ArtifactRequest();
             request.setArtifact( new DefaultArtifact( artifact.getGroupId(), artifact.getArtifactId(),
                                                       artifact.getClassifier(),
-                                                      artifact.getArtifactHandler().getExtension(),
+                                                      ( artifact.getArtifactHandler() != null )
+                                                                      ? artifact.getArtifactHandler().getExtension()
+                                                                      : artifact.getType(),
                                                       artifact.getVersion() ) );
             request.setRepositories( Collections.singletonList( repo ) );