Skip to content

Commit 67ca2da

Browse files
committed
MSOURCES-120 tweak entry time to ensure reproducible value in zip
1 parent 4ff518f commit 67ca2da

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/it/reproducible/verify.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ ZipFile zipFile = new ZipFile( jarFile );
3939

4040
r.append( 'encoding: ' + zipFile.getEncoding() + '\n' )
4141
r.append( 'timezone offset (minutes): ' + new Date().getTimezoneOffset() + '\n' )
42-
r.append( 'M size (cmp) crc java time date time zip time mode name -comment; extra\n' )
42+
r.append( 'M size (cmp) crc java time date time zip time mode name -comment; extra\n' )
4343

4444
String describeExtra( ZipExtraField[] extras )
4545
{
@@ -66,13 +66,13 @@ long javaToDosTime( Date d )
6666

6767
for ( ZipArchiveEntry zae : zipFile.getEntries() )
6868
{
69-
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() ) ) )
69+
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() ) ) )
7070
}
7171
zipFile.close();
7272

7373
String buf = r.toString()
7474
println buf
7575

76-
String expectedSha1 = System.properties['os.name'].toLowerCase().contains( 'windows' ) ? 'c1a0f57e19f6f400da66bee06084a4bdb0d2fc00' : '7bd062f9b45afb7423f3c004c8080ebad4e98754'
76+
String expectedSha1 = System.properties['os.name'].toLowerCase().contains( 'windows' ) ? 'b2c3895976027f203f2a08610fc28bbe7dbc7a9e' : 'acf461ff37ddc3c44c620770a73d9cf42f7ca429'
7777

7878
assert buf.startsWith( "reproducible-1.0-sources.jar sha1 = $expectedSha1" )

src/main/java/org/apache/maven/plugins/source/AbstractSourceJarMojo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.IOException;
2424
import java.util.ArrayList;
2525
import java.util.Arrays;
26+
import java.util.Calendar;
2627
import java.util.Comparator;
2728
import java.util.Date;
2829
import java.util.List;
@@ -284,7 +285,10 @@ protected void packageSources( List<MavenProject> theProjects )
284285
if ( sourceDateEpoch != 0 )
285286
{
286287
JarArchiver j = archiver.getArchiver();
287-
j.setLastModifiedDate( new Date( 1000L * sourceDateEpoch ) );
288+
Calendar cal = Calendar.getInstance();
289+
long zipTime =
290+
1000L * sourceDateEpoch - ( cal.get( Calendar.ZONE_OFFSET ) + cal.get( Calendar.DST_OFFSET ) );
291+
j.setLastModifiedDate( new Date( zipTime ) );
288292
j.setFilenameComparator( new Comparator<String>()
289293
{
290294
@Override

0 commit comments

Comments
 (0)