Skip to content

Commit

Permalink
Fix non-reproducible archives
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciogg committed Feb 25, 2022
1 parent 93386fb commit bf58683
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions private/tools/java/rules/jvm/external/jar/AddJarManifestEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar
import java.util.Enumeration;
import java.util.GregorianCalendar
import java.util.List;
import java.util.Objects;
import java.util.jar.Attributes;
Expand All @@ -34,12 +34,24 @@
# times of the jar entries.
*/
public class AddJarManifestEntry {

public static final long DEFAULT_TIMESTAMP =
LocalDateTime.of(2010, 1, 1, 0, 0, 0)
.atZone(ZoneId.systemDefault())
.toInstant()
.toEpochMilli();

/**
* Note that setting the January 1st 1980 (or even worse, "0", as time) won't work due
* to Java 8 doing some interesting time processing: It checks if this date is before January 1st 1980
* and if it is it starts setting some extra fields in the zip. Java 7 does not do that - but in the
* zip not the milliseconds are saved but values for each of the date fields - but no time zone. And
* 1980 is the first year which can be saved.
* If you use January 1st 1980 then it is treated as a special flag in Java 8.
* Moreover, only even seconds can be stored in the zip file. Java 8 uses the upper half of
* some other long to store the remaining millis while Java 7 doesn't do that. So make sure
* that your seconds are even.
* Moreover, parsing happens via `new Date(millis)` in {@link java.util.zip.ZipUtils}#javaToDosTime() so we
* must use default timezone and locale.
*
* The date is 1980 February 1st CET.
*/
public static final long DEFAULT_TIMESTAMP = (
new GregorianCalendar(1980, Calendar.FEBRUARY, 1, 0, 0, 0)).getTimeInMillis();

public static void verboseLog(String logline) {
// To make this work you need to add 'use_default_shell_env = True' to the
Expand Down

0 comments on commit bf58683

Please sign in to comment.