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 2019/09/06 22:12:04 UTC
[maven-source-plugin] 01/01: MSOURCES-120 tweak entry time to
ensure reproducible value in zip
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to branch MSOURCES-120
in repository https://gitbox.apache.org/repos/asf/maven-source-plugin.git
commit 67ca2da612ef3e0ee061e2075292aae72376d95e
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Fri Sep 6 23:59:44 2019 +0200
MSOURCES-120 tweak entry time to ensure reproducible value in zip
---
src/it/reproducible/verify.groovy | 6 +++---
.../java/org/apache/maven/plugins/source/AbstractSourceJarMojo.java | 6 +++++-
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/it/reproducible/verify.groovy b/src/it/reproducible/verify.groovy
index c9c8e7c..40a864c 100644
--- a/src/it/reproducible/verify.groovy
+++ b/src/it/reproducible/verify.groovy
@@ -39,7 +39,7 @@ ZipFile zipFile = new ZipFile( jarFile );
r.append( 'encoding: ' + zipFile.getEncoding() + '\n' )
r.append( 'timezone offset (minutes): ' + new Date().getTimezoneOffset() + '\n' )
-r.append( 'M size (cmp) crc java time date time zip time mode name -comment; extra\n' )
+r.append( 'M size (cmp) crc java time date time zip time mode name -comment; extra\n' )
String describeExtra( ZipExtraField[] extras )
{
@@ -66,13 +66,13 @@ long javaToDosTime( Date d )
for ( ZipArchiveEntry zae : zipFile.getEntries() )
{
- r.append( sprintf( "%d %4d (%3d) %8x %d %<tF %<tT %d %6o %s %s; %s\n", zae.getMethod(), zae.getSize(), zae.getCompressedSize(), zae.getCrc(), zae.getTime(), javaToDosTime( zae.getLastModifiedDate() ), zae.getUnixMode(), zae.getName(), ( zae.getComment() == null ) ? '-' : zae.getComment(), describeExtra( zae.getExtraFields() ) ) )
+ r.append( sprintf( "%d %4d (%3d) %8x %d %<tF %<tT %<tz %d %6o %s %s; %s\n", zae.getMethod(), zae.getSize(), zae.getCompressedSize(), zae.getCrc(), zae.getTime(), javaToDosTime( zae.getLastModifiedDate() ), zae.getUnixMode(), zae.getName(), ( zae.getComment() == null ) ? '-' : zae.getComment(), describeExtra( zae.getExtraFields() ) ) )
}
zipFile.close();
String buf = r.toString()
println buf
-String expectedSha1 = System.properties['os.name'].toLowerCase().contains( 'windows' ) ? 'c1a0f57e19f6f400da66bee06084a4bdb0d2fc00' : '7bd062f9b45afb7423f3c004c8080ebad4e98754'
+String expectedSha1 = System.properties['os.name'].toLowerCase().contains( 'windows' ) ? 'b2c3895976027f203f2a08610fc28bbe7dbc7a9e' : 'acf461ff37ddc3c44c620770a73d9cf42f7ca429'
assert buf.startsWith( "reproducible-1.0-sources.jar sha1 = $expectedSha1" )
diff --git a/src/main/java/org/apache/maven/plugins/source/AbstractSourceJarMojo.java b/src/main/java/org/apache/maven/plugins/source/AbstractSourceJarMojo.java
index 0fa2f79..13bd352 100644
--- a/src/main/java/org/apache/maven/plugins/source/AbstractSourceJarMojo.java
+++ b/src/main/java/org/apache/maven/plugins/source/AbstractSourceJarMojo.java
@@ -23,6 +23,7 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
@@ -284,7 +285,10 @@ public abstract class AbstractSourceJarMojo
if ( sourceDateEpoch != 0 )
{
JarArchiver j = archiver.getArchiver();
- j.setLastModifiedDate( new Date( 1000L * sourceDateEpoch ) );
+ Calendar cal = Calendar.getInstance();
+ long zipTime =
+ 1000L * sourceDateEpoch - ( cal.get( Calendar.ZONE_OFFSET ) + cal.get( Calendar.DST_OFFSET ) );
+ j.setLastModifiedDate( new Date( zipTime ) );
j.setFilenameComparator( new Comparator<String>()
{
@Override