This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to branch maven-buildinfo-plugin
in repository https://gitbox.apache.org/repos/asf/maven-studies.git
The following commit(s) were added to refs/heads/maven-buildinfo-plugin by this
push:
new 46915c2 generate aggregate buildinfo only in multi-module build
46915c2 is described below
commit 46915c2816edef8939520e505d8802116e081060
Author: Hervé Boutemy <[email protected]>
AuthorDate: Mon Feb 17 08:20:46 2020 +0100
generate aggregate buildinfo only in multi-module build
---
src/it/multi/verify.groovy | 75 +++---------
.../apache/maven/plugins/buildinfo/SaveMojo.java | 132 +++++++--------------
2 files changed, 63 insertions(+), 144 deletions(-)
diff --git a/src/it/multi/verify.groovy b/src/it/multi/verify.groovy
index 50b2e6b..5c3c583 100644
--- a/src/it/multi/verify.groovy
+++ b/src/it/multi/verify.groovy
@@ -18,80 +18,43 @@
* under the License.
*/
-// check existence of generated buildinfos in target (1 per module + 1
aggregate in the last)
+// check existence of generated aggregate buildinfo in target
File buildinfoFile = new File( basedir, "target/multi-1.0-SNAPSHOT.buildinfo"
);
-assert buildinfoFile.isFile()
+assert !buildinfoFile.isFile()
File modA = new File( basedir, "modA/target/multi-modA-1.0-SNAPSHOT.buildinfo")
-assert modA.isFile()
+assert !modA.isFile()
File modB = new File( basedir, "modB/target/multi-modB-1.0-SNAPSHOT.buildinfo")
assert modB.isFile()
-File aggregate = new File( basedir,
"modB/target/multi-modB-1.0-SNAPSHOT-aggregate.buildinfo")
-assert modB.isFile()
-
-// check generated buildinfo content
-String buildinfo = buildinfoFile.text
-assert buildinfo.contains( "mvn.rebuild-args=-DskipTests verify" )
-assert buildinfo.contains(
"mvn.aggregate-buildinfo=org.apache.maven.plugins.it:multi-modB:1.0-SNAPSHOT" )
-
-buildinfo = modA.text
-assert buildinfo.contains(
"mvn.build-root=org.apache.maven.plugins.it:multi:1.0-SNAPSHOT" )
-assert buildinfo.contains( "outputs.0.filename=multi-modA-1.0-SNAPSHOT.jar" )
-
-buildinfo = modB.text
-assert buildinfo.contains(
"mvn.build-root=org.apache.maven.plugins.it:multi:1.0-SNAPSHOT" )
-assert buildinfo.contains( "outputs.0.filename=multi-modB-1.0-SNAPSHOT.jar" )
-
-buildinfo = aggregate.text
-assert buildinfo.contains( "mvn.rebuild-args=-DskipTests verify" )
-assert buildinfo.contains(
"mvn.build-root=org.apache.maven.plugins.it:multi:1.0-SNAPSHOT" )
+// check generated aggregate buildinfo content
+String buildinfo = modB.text
+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.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( ".buildinfo" )
-// check existence of buildinfos in local repository
-File local = new File( basedir,
"../../local-repo/org/apache/maven/plugins/it/multi/1.0-SNAPSHOT/multi-1.0-SNAPSHOT.buildinfo")
-assert local.isFile()
-
-File localModA = new File( basedir,
"../../local-repo/org/apache/maven/plugins/it/multi-modA/1.0-SNAPSHOT/multi-modA-1.0-SNAPSHOT.buildinfo")
-assert localModA.isFile()
-
+// check existence of buildinfo in local repository
File localModB = new File( basedir,
"../../local-repo/org/apache/maven/plugins/it/multi-modB/1.0-SNAPSHOT/multi-modB-1.0-SNAPSHOT.buildinfo")
assert localModB.isFile()
-File localAggregate = new File( basedir,
"../../local-repo/org/apache/maven/plugins/it/multi-modB/1.0-SNAPSHOT/multi-modB-1.0-SNAPSHOT-aggregate.buildinfo")
-assert localAggregate.isFile()
-
-// check existence of buildinfos in remote repository
-void checkBuildinfo( String root, String artifactId, boolean aggregate )
+// check existence of buildinfo in remote repository
+File remoteDir = new File( basedir,
"modB/target/remote-repo/org/apache/maven/plugins/it/multi-modB/1.0-SNAPSHOT" )
+assert remoteDir.isDirectory()
+for ( File f : remoteDir.listFiles() )
{
- File remoteDir = new File( basedir, root +
"target/remote-repo/org/apache/maven/plugins/it/" + artifactId +
"/1.0-SNAPSHOT" )
- assert remoteDir.isDirectory()
- int count = 0;
- for ( File f : remoteDir.listFiles() )
+ if ( f.getName().endsWith( ".pom" ) )
{
- if ( f.getName().endsWith( ".pom" ) )
- {
- File b = new File( remoteDir, f.getName().replace( ".pom", ".buildinfo"
) )
- println b
- assert b.isFile()
- count++
- if ( aggregate )
- {
- File a = new File( remoteDir, f.getName().replace( ".pom",
"-aggregate.buildinfo" ) )
- println a
- assert a.isFile()
- count++
- }
- }
+ File b = new File( remoteDir, f.getName().replace( ".pom", ".buildinfo" ) )
+ println b
+ assert b.isFile()
+ return
}
- assert count >= ( aggregate ? 2 : 1 )
}
-checkBuildinfo( "", "multi", false )
-checkBuildinfo( "modA/", "multi-modA", false )
-checkBuildinfo( "modB/", "multi-modB", true )
+// issue: buildinfo not found
\ No newline at end of file
diff --git a/src/main/java/org/apache/maven/plugins/buildinfo/SaveMojo.java
b/src/main/java/org/apache/maven/plugins/buildinfo/SaveMojo.java
index 8a157ac..16c35b0 100644
--- a/src/main/java/org/apache/maven/plugins/buildinfo/SaveMojo.java
+++ b/src/main/java/org/apache/maven/plugins/buildinfo/SaveMojo.java
@@ -41,7 +41,8 @@ import java.util.List;
/**
* Save buildinfo file, as specified in
- * <a href="https://reproducible-builds.org/docs/jvm/">Reproducible Builds for
the JVM</a>.
+ * <a href="https://reproducible-builds.org/docs/jvm/">Reproducible Builds for
the JVM</a>
+ * for mono-module build, and exended for multi-module build.
*/
@Mojo( name = "save", defaultPhase = LifecyclePhase.VERIFY )
public class SaveMojo
@@ -67,13 +68,6 @@ public class SaveMojo
private File buildinfoFile;
/**
- * Location of the eventually generated aggregate buildinfo file.
- */
- @Parameter( defaultValue =
"${project.build.directory}/${project.artifactId}-${project.version}"
- + "-aggregate.buildinfo", required = true, readonly = true )
- private File aggregateBuildinfoFile;
-
- /**
* Specifies whether to attach the generated buildinfo file to the project.
*/
@Parameter( property = "buildinfo.attach", defaultValue = "true" )
@@ -82,8 +76,8 @@ public class SaveMojo
/**
* Rebuild arguments.
*/
- @Parameter( property = "buildinfo.rebuild-args", defaultValue =
"-DskipTests verify" )
- private String rebuildArgs;
+ //@Parameter( property = "buildinfo.rebuild-args", defaultValue =
"-DskipTests verify" )
+ //private String rebuildArgs;
/**
* Used for attaching the buildinfo file in the project.
@@ -93,7 +87,19 @@ public class SaveMojo
public void execute() throws MojoExecutionException
{
- generateBuildinfo();
+ boolean mono = reactorProjects.size() == 1;
+
+ if ( !mono )
+ {
+ MavenProject aggregate = reactorProjects.get(
reactorProjects.size() - 1 );
+ if ( project != aggregate )
+ {
+ getLog().info( "Skip intermediate buildinfo, aggregate will be
" + aggregate.getArtifactId() );
+ return;
+ }
+ }
+
+ generateBuildinfo( mono );
if ( attach )
{
@@ -103,53 +109,44 @@ public class SaveMojo
{
getLog().info( "NOT adding buildinfo to the list of attached
artifacts." );
}
-
- if ( ( reactorProjects.size() > 1 ) && ( project ==
reactorProjects.get( reactorProjects.size() - 1 ) ) )
- {
- File aggregate = generateAggregateBuildinfo();
-
- if ( attach )
- {
- projectHelper.attachArtifact( project, "buildinfo",
"aggregate", aggregate );
- }
- else
- {
- getLog().info( "NOT adding buildinfo to the list of attached
artifacts." );
- }
- }
}
- private void generateBuildinfo()
+ private void generateBuildinfo( boolean mono )
throws MojoExecutionException
{
+ MavenProject root = mono ? project : getExecutionRoot();
+
buildinfoFile.getParentFile().mkdirs();
+
try ( PrintWriter p = new PrintWriter( new BufferedWriter(
new OutputStreamWriter( new FileOutputStream( buildinfoFile ),
Charsets.ISO_8859_1 ) ) ) )
{
- printHeader( p, project );
- p.println();
- if ( project.isExecutionRoot() )
+ printHeader( p, root );
+
+ // artifact(s) fingerprints
+ if ( mono )
{
- printRootInformation( p, project );
+ if ( project.getArtifact() != null )
+ {
+ p.println();
+ p.println( "# output" );
+ printOutput( p, project, -1 );
+ }
}
else
{
- // multi-module non execution root
- p.println( "# build instructions" );
- p.println( "build-tool=mvn" );
- MavenProject root = getExecutionRoot();
- p.println( "mvn.build-root=" + root.getGroupId() + ':' +
root.getArtifactId() + ':'
- + root.getVersion() );
- }
-
- if ( project.getArtifact() != null )
- {
- p.println();
- p.println( "# output" );
- printOutput( p, project, -1 );
+ int n = 0;
+ for ( MavenProject project : reactorProjects )
+ {
+ if ( project.getArtifact() != null )
+ {
+ p.println();
+ printOutput( p, project, n++ );
+ }
+ }
}
- getLog().info( "Saved info on build to " + buildinfoFile );
+ getLog().info( "Saved " + ( mono ? "" : "aggregate " ) + "info on
build to " + buildinfoFile );
}
catch ( IOException e )
{
@@ -166,10 +163,7 @@ public class SaveMojo
p.println( "group-id=" + project.getGroupId() );
p.println( "artifact-id=" + project.getArtifactId() );
p.println( "version=" + project.getVersion() );
- }
-
- private void printRootInformation( PrintWriter p, MavenProject project )
- {
+ p.println();
printSourceInformation( p, project );
p.println();
p.println( "# build instructions" );
@@ -182,26 +176,20 @@ public class SaveMojo
p.println( "os.name=" + System.getProperty( "os.name" ) );
p.println();
p.println( "# Maven rebuild instructions and effective environment" );
- p.println( "mvn.rebuild-args=" + rebuildArgs );
+ //p.println( "mvn.rebuild-args=" + rebuildArgs );
p.println( "mvn.version=" + MavenVersion.createMavenVersionString() );
if ( ( project.getPrerequisites() != null ) && (
project.getPrerequisites().getMaven() != null ) )
{
// TODO wrong algorithm, should reuse algorithm written in
versions-maven-plugin
p.println( "mvn.minimum.version=" +
project.getPrerequisites().getMaven() );
}
- if ( reactorProjects.size() > 1 )
- {
- MavenProject aggregate = reactorProjects.get(
reactorProjects.size() - 1 );
- p.println( "mvn.aggregate-buildinfo=" + aggregate.getGroupId() +
':' + aggregate.getArtifactId() + ':'
- + aggregate.getVersion() );
- }
}
private void printSourceInformation( PrintWriter p, MavenProject project )
{
boolean sourceAvailable = false;
p.println( "# source information" );
- p.println( "# TBD source.* artifact, url should be parameters" );
+ //p.println( "# TBD source.* artifact, url should be parameters" );
if ( project.getScm() != null )
{
sourceAvailable = true;
@@ -282,36 +270,4 @@ public class SaveMojo
}
return null;
}
-
- private File generateAggregateBuildinfo()
- throws MojoExecutionException
- {
- MavenProject root = getExecutionRoot();
- try ( PrintWriter p =
- new PrintWriter( new BufferedWriter( new OutputStreamWriter( new
FileOutputStream( aggregateBuildinfoFile ),
-
Charsets.ISO_8859_1 ) ) ) )
- {
- printHeader( p, root );
- p.println();
- printRootInformation( p, root );
- p.println( "mvn.build-root=" + root.getGroupId() + ':' +
root.getArtifactId() + ':' + root.getVersion() );
-
- int n = 0;
- for ( MavenProject project : reactorProjects )
- {
- if ( project.getArtifact() != null )
- {
- p.println();
- printOutput( p, project, n++ );
- }
- }
-
- getLog().info( "Saved aggregate info on build to " +
aggregateBuildinfoFile );
- }
- catch ( IOException e )
- {
- throw new MojoExecutionException( "Error creating file " +
aggregateBuildinfoFile, e );
- }
- return aggregateBuildinfoFile;
- }
}