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-archetype.git
The following commit(s) were added to refs/heads/master by this push: new 4c403f7 [ARCHETYPE-590] make archetype:jar reproductible 4c403f7 is described below commit 4c403f7b0148f7dc5fd4e17434943b6530da36ad Author: Hervé Boutemy <hbout...@apache.org> AuthorDate: Sun Apr 5 15:27:22 2020 +0200 [ARCHETYPE-590] make archetype:jar reproductible --- archetype-common/pom.xml | 3 +- .../apache/maven/archetype/ArchetypeManager.java | 2 + archetype-models/archetype-catalog/pom.xml | 2 +- archetype-models/archetype-descriptor/pom.xml | 2 +- archetype-models/pom.xml | 27 +++------ archetype-packaging/pom.xml | 2 +- maven-archetype-plugin/pom.xml | 12 +++- .../org/apache/maven/archetype/mojos/JarMojo.java | 70 ++++++++++++++++++---- pom.xml | 2 +- 9 files changed, 83 insertions(+), 39 deletions(-) diff --git a/archetype-common/pom.xml b/archetype-common/pom.xml index e4c714b..6976e9e 100644 --- a/archetype-common/pom.xml +++ b/archetype-common/pom.xml @@ -26,7 +26,7 @@ <parent> <groupId>org.apache.maven.archetype</groupId> <artifactId>maven-archetype</artifactId> - <version>3.1.3-SNAPSHOT</version> + <version>3.2.0-SNAPSHOT</version> </parent> <artifactId>archetype-common</artifactId> @@ -75,7 +75,6 @@ <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-component-annotations</artifactId> - <version>1.5.5</version> </dependency> <dependency> <groupId>jdom</groupId> diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeManager.java b/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeManager.java index 57c58ce..1664ec8 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeManager.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/ArchetypeManager.java @@ -85,7 +85,9 @@ public interface ArchetypeManager * @return The File to the generated jar * @throws org.apache.maven.artifact.DependencyResolutionRequiredException * @throws java.io.IOException + * @deprecated replaced by archetype plugin's JarMojo using maven-archiver component for Reproducible Builds */ + @Deprecated File archiveArchetype( File archetypeDirectory, File outputDirectory, String finalName ) throws DependencyResolutionRequiredException, IOException; diff --git a/archetype-models/archetype-catalog/pom.xml b/archetype-models/archetype-catalog/pom.xml index 1195dce..c166ae1 100644 --- a/archetype-models/archetype-catalog/pom.xml +++ b/archetype-models/archetype-catalog/pom.xml @@ -26,7 +26,7 @@ <parent> <groupId>org.apache.maven.archetype</groupId> <artifactId>archetype-models</artifactId> - <version>3.1.3-SNAPSHOT</version> + <version>3.2.0-SNAPSHOT</version> </parent> <artifactId>archetype-catalog</artifactId> diff --git a/archetype-models/archetype-descriptor/pom.xml b/archetype-models/archetype-descriptor/pom.xml index f5339d9..10ef915 100644 --- a/archetype-models/archetype-descriptor/pom.xml +++ b/archetype-models/archetype-descriptor/pom.xml @@ -26,7 +26,7 @@ <parent> <groupId>org.apache.maven.archetype</groupId> <artifactId>archetype-models</artifactId> - <version>3.1.3-SNAPSHOT</version> + <version>3.2.0-SNAPSHOT</version> </parent> <artifactId>archetype-descriptor</artifactId> diff --git a/archetype-models/pom.xml b/archetype-models/pom.xml index 7b3e6c7..e7d716f 100644 --- a/archetype-models/pom.xml +++ b/archetype-models/pom.xml @@ -1,23 +1,12 @@ <?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. ---> +<!-- 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"> @@ -26,7 +15,7 @@ <parent> <groupId>org.apache.maven.archetype</groupId> <artifactId>maven-archetype</artifactId> - <version>3.1.3-SNAPSHOT</version> + <version>3.2.0-SNAPSHOT</version> </parent> <artifactId>archetype-models</artifactId> diff --git a/archetype-packaging/pom.xml b/archetype-packaging/pom.xml index dafd5c5..dc2f2ac 100644 --- a/archetype-packaging/pom.xml +++ b/archetype-packaging/pom.xml @@ -25,7 +25,7 @@ <parent> <groupId>org.apache.maven.archetype</groupId> <artifactId>maven-archetype</artifactId> - <version>3.1.3-SNAPSHOT</version> + <version>3.2.0-SNAPSHOT</version> </parent> <artifactId>archetype-packaging</artifactId> diff --git a/maven-archetype-plugin/pom.xml b/maven-archetype-plugin/pom.xml index 570e02c..048290a 100644 --- a/maven-archetype-plugin/pom.xml +++ b/maven-archetype-plugin/pom.xml @@ -26,7 +26,7 @@ <parent> <groupId>org.apache.maven.archetype</groupId> <artifactId>maven-archetype</artifactId> - <version>3.1.3-SNAPSHOT</version> + <version>3.2.0-SNAPSHOT</version> </parent> <!-- @@ -67,6 +67,16 @@ <groupId>org.apache.maven.archetype</groupId> <artifactId>archetype-common</artifactId> </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-archiver</artifactId> + <version>3.5.0</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-archiver</artifactId> + <version>4.2.1</version> + </dependency> <!-- Required for the integration tests, dependency is only to define build order --> <dependency> <groupId>org.apache.maven.archetype</groupId> diff --git a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/JarMojo.java b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/JarMojo.java index c40e93a..c950f38 100644 --- a/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/JarMojo.java +++ b/maven-archetype-plugin/src/main/java/org/apache/maven/archetype/mojos/JarMojo.java @@ -24,7 +24,9 @@ import org.apache.maven.archetype.common.ArchetypeArtifactManager; import org.apache.maven.archetype.exception.UnknownArchetype; import org.apache.maven.archetype.metadata.ArchetypeDescriptor; import org.apache.maven.archetype.metadata.RequiredProperty; -import org.apache.maven.artifact.DependencyResolutionRequiredException; +import org.apache.maven.archiver.MavenArchiveConfiguration; +import org.apache.maven.archiver.MavenArchiver; +import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -33,9 +35,11 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.codehaus.plexus.archiver.Archiver; +import org.codehaus.plexus.archiver.jar.JarArchiver; import java.io.File; -import java.io.IOException; +import java.util.Map; /** * Build a JAR from the current Archetype project. @@ -71,6 +75,37 @@ public class JarMojo private MavenProject project; /** + * The {@link MavenSession}. + */ + @Parameter( defaultValue = "${session}", readonly = true, required = true ) + private MavenSession session; + + /** + * The Jar archiver. + */ + @Component + private Map<String, Archiver> archivers; + + /** + * The archive configuration to use. See <a href="https://maven.apache.org/shared/maven-archiver/index.html">Maven + * Archiver Reference</a>. + * + * @since 3.2.0 + */ + @Parameter + private MavenArchiveConfiguration archive = new MavenArchiveConfiguration(); + + /** + * Timestamp for reproducible output archive entries, either formatted as ISO 8601 + * <code>yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like + * <a href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>). + * + * @since 3.2.0 + */ + @Parameter( defaultValue = "${project.build.outputTimestamp}" ) + private String outputTimestamp; + + /** * The archetype manager component. */ @Component @@ -86,24 +121,33 @@ public class JarMojo public void execute() throws MojoExecutionException, MojoFailureException { - try - { - getLog().info( "Building archetype jar: " + new File( outputDirectory, finalName ) ); + File jarFile = new File( outputDirectory, finalName + ".jar" ); + getLog().info( "Building archetype jar: " + jarFile ); - File jarFile = manager.archiveArchetype( archetypeDirectory, outputDirectory, finalName ); + MavenArchiver archiver = new MavenArchiver(); + archiver.setCreatedBy( "Maven Archetype Plugin", "org.apache.maven.plugins", "maven-archetype-plugin" ); - checkArchetypeFile( jarFile ); + archiver.setOutputFile( jarFile ); - project.getArtifact().setFile( jarFile ); - } - catch ( DependencyResolutionRequiredException ex ) + archiver.setArchiver( (JarArchiver) archivers.get( "jar" ) ); + + // configure for Reproducible Builds based on outputTimestamp value + archiver.configureReproducible( outputTimestamp ); + + try { - throw new MojoExecutionException( ex.getMessage(), ex ); + archiver.getArchiver().addDirectory( archetypeDirectory ); + + archiver.createArchive( session, project, archive ); } - catch ( IOException ex ) + catch ( Exception e ) { - throw new MojoExecutionException( ex.getMessage(), ex ); + throw new MojoExecutionException( "Error assembling archetype jar " + jarFile, e ); } + + checkArchetypeFile( jarFile ); + + project.getArtifact().setFile( jarFile ); } private void checkArchetypeFile( File jarFile ) diff --git a/pom.xml b/pom.xml index d3a9af0..568297b 100644 --- a/pom.xml +++ b/pom.xml @@ -153,7 +153,7 @@ <dependency> <groupId>org.codehaus.plexus</groupId> <artifactId>plexus-utils</artifactId> - <version>3.2.0</version> + <version>3.3.0</version> </dependency> <dependency> <groupId>commons-io</groupId>