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 c8f4e8b [MARTIFACT-29] add support for flatten-maven-plugin generated
poms
c8f4e8b is described below
commit c8f4e8b93ad548d375dec4985daafad7aa108b79
Author: Hervé Boutemy <[email protected]>
AuthorDate: Sun Nov 14 18:37:04 2021 +0100
[MARTIFACT-29] add support for flatten-maven-plugin generated poms
---
src/it/flatten/invoker.properties | 19 +++++
src/it/flatten/modA/pom.xml | 34 ++++++++
src/it/flatten/modB/pom.xml | 46 ++++++++++
src/it/flatten/pom.xml | 97 ++++++++++++++++++++++
src/it/flatten/verify.groovy | 31 +++++++
.../artifact/buildinfo/BuildInfoWriter.java | 9 +-
.../plugins/artifact/buildinfo/CompareMojo.java | 15 ++--
7 files changed, 241 insertions(+), 10 deletions(-)
diff --git a/src/it/flatten/invoker.properties
b/src/it/flatten/invoker.properties
new file mode 100644
index 0000000..339a145
--- /dev/null
+++ b/src/it/flatten/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/flatten/modA/pom.xml b/src/it/flatten/modA/pom.xml
new file mode 100644
index 0000000..1fffb85
--- /dev/null
+++ b/src/it/flatten/modA/pom.xml
@@ -0,0 +1,34 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache.maven.plugins.it</groupId>
+ <artifactId>flatten</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>flatten-modA</artifactId>
+ <packaging>pom</packaging>
+ <name>flatten module A</name>
+</project>
diff --git a/src/it/flatten/modB/pom.xml b/src/it/flatten/modB/pom.xml
new file mode 100644
index 0000000..e5bdf0d
--- /dev/null
+++ b/src/it/flatten/modB/pom.xml
@@ -0,0 +1,46 @@
+<?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>
+
+ <parent>
+ <groupId>org.apache.maven.plugins.it</groupId>
+ <artifactId>flatten</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>flatten-modB</artifactId>
+ <packaging>pom</packaging>
+ <name>flatten module B, updatePomFile = false</name>
+
+ <properties>
+ <updatePomFile>false</updatePomFile>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.plugins.it</groupId>
+ <artifactId>multi-modA</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/src/it/flatten/pom.xml b/src/it/flatten/pom.xml
new file mode 100644
index 0000000..0c3c784
--- /dev/null
+++ b/src/it/flatten/pom.xml
@@ -0,0 +1,97 @@
+<?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</groupId>
+ <artifactId>flatten</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <description>An IT verifying results when flatten-maven-plugin is
used.</description>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <updatePomFile>true</updatePomFile>
+ </properties>
+
+ <prerequisites>
+ <maven>3.0.5</maven>
+ </prerequisites>
+
+ <distributionManagement>
+ <snapshotRepository>
+ <id>local-snapshots</id>
+ <url>file://${basedir}/target/remote-repo</url>
+ <uniqueVersion>false</uniqueVersion>
+ </snapshotRepository>
+ </distributionManagement>
+
+ <modules>
+ <module>modB</module>
+ <module>modA</module>
+ </modules>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>@project.groupId@</groupId>
+ <artifactId>@project.artifactId@</artifactId>
+ <version>@project.version@</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compare</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>flatten-maven-plugin</artifactId>
+ <version>1.2.2</version>
+ <configuration>
+ <flattenedPomFilename>flattened-pom.xml</flattenedPomFilename>
+ </configuration>
+ <executions>
+ <!-- enable flattening -->
+ <execution>
+ <id>flatten</id>
+ <phase>process-resources</phase>
+ <goals>
+ <goal>flatten</goal>
+ </goals>
+ </execution>
+ <!-- ensure proper cleanup -->
+ <execution>
+ <id>flatten.clean</id>
+ <phase>clean</phase>
+ <goals>
+ <goal>clean</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/it/flatten/verify.groovy b/src/it/flatten/verify.groovy
new file mode 100644
index 0000000..7c3c393
--- /dev/null
+++ b/src/it/flatten/verify.groovy
@@ -0,0 +1,31 @@
+
+/*
+ * 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.
+ */
+
+String compare = new File( basedir, 'target/flatten-1.0-SNAPSHOT.buildcompare'
).text
+assert compare.contains( 'okFiles="flatten-1.0-SNAPSHOT.pom
flatten-modB-1.0-SNAPSHOT.pom flatten-modA-1.0-SNAPSHOT.pom"' )
+
+assert new File( basedir, 'flattened-pom.xml' ).text == new File( basedir,
'target/reference/flatten-1.0-SNAPSHOT.pom' ).text
+assert new File( basedir, 'modA/flattened-pom.xml' ).text == new File(
basedir, 'target/reference/flatten-modA-1.0-SNAPSHOT.pom' ).text
+assert new File( basedir, 'modB/pom.xml' ).text == new File( basedir,
'target/reference/flatten-modB-1.0-SNAPSHOT.pom' ).text
+
+String buildinfo = new File( basedir, 'target/flatten-1.0-SNAPSHOT.buildinfo'
).text
+assert buildinfo.contains( "outputs.0.0.length=" + new File( basedir,
'flattened-pom.xml' ).size() )
+assert buildinfo.contains( "outputs.1.0.length=" + new File( basedir,
'modB/pom.xml' ).size() )
+assert buildinfo.contains( "outputs.2.0.length=" + new File( basedir,
'modA/flattened-pom.xml' ).size() )
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 77e1ce3..6169418 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
@@ -175,9 +175,12 @@ class BuildInfoWriter
}
int n = 0;
- artifacts.put( new DefaultArtifact( project.getGroupId(),
project.getArtifactId(), project.getVersion(), null,
- "pom", "",
artifactHandlerManager.getArtifactHandler( "pom" ) ),
- prefix + n );
+ Artifact pomArtifact =
+ new DefaultArtifact( project.getGroupId(),
project.getArtifactId(), project.getVersion(), null, "pom", "",
+ artifactHandlerManager.getArtifactHandler(
"pom" ) );
+ pomArtifact.setFile( project.getFile() );
+
+ artifacts.put( pomArtifact, prefix + n );
printFile( prefix + n++, project.getFile(), project.getArtifactId() +
'-' + project.getVersion() + ".pom" );
if ( project.getArtifact() == null )
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 42a754d..fe9ed7b 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
@@ -152,10 +152,10 @@ public class CompareMojo
Artifact artifact = entry.getKey();
String prefix = entry.getValue();
- String diffoscope = checkArtifact( artifact, prefix, reference,
actual, referenceDir );
- String filename =
- ( artifact.getFile() == null ) ? ( artifact.getArtifactId() +
'-' + artifact.getVersion() + ".pom" )
- : artifact.getFile().getName();
+ String[] checkResult = checkArtifact( artifact, prefix, reference,
actual, referenceDir );
+ String filename = checkResult[0];
+ String diffoscope = checkResult[1];
+
if ( diffoscope == null )
{
ok++;
@@ -224,7 +224,8 @@ public class CompareMojo
copyAggregateToRoot( buildcompare );
}
- private String checkArtifact( Artifact artifact, String prefix, Properties
reference, Properties actual,
+ // { filename, diffoscope }
+ private String[] checkArtifact( Artifact artifact, String prefix,
Properties reference, Properties actual,
File referenceDir )
{
String actualFilename = (String) actual.remove( prefix + ".filename" );
@@ -250,9 +251,9 @@ public class CompareMojo
String diffoscope = diffoscope( artifact, referenceDir );
getLog().warn( issue + " mismatch " +
MessageUtils.buffer().strong( actualFilename ) + ": investigate with "
+ MessageUtils.buffer().project( diffoscope ) );
- return diffoscope;
+ return new String[] { actualFilename, diffoscope };
}
- return null;
+ return new String[] { actualFilename, null };
}
private String diffoscope( Artifact a, File referenceDir )