Use a different date time when normalizing zip entries Fixes #4614 PiperOrigin-RevId: 185474153
diff --git a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarHelper.java b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarHelper.java index 04a3248..719fcdb 100644 --- a/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarHelper.java +++ b/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarHelper.java
@@ -18,6 +18,8 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.util.HashSet; import java.util.Set; import java.util.jar.JarEntry; @@ -29,7 +31,7 @@ * A simple helper class for creating Jar files. All Jar entries are sorted alphabetically. Allows * normalization of Jar entries by setting the timestamp of non-.class files to the DOS epoch. * Timestamps of .class files are set to the DOS epoch + 2 seconds (The zip timestamp granularity) - * Adjusting the timestamp for .class files is neccessary since otherwise javac will recompile java + * Adjusting the timestamp for .class files is necessary since otherwise javac will recompile java * files if both the java file and its .class file are present. */ public class JarHelper { @@ -38,7 +40,12 @@ public static final String MANIFEST_NAME = JarFile.MANIFEST_NAME; public static final String SERVICES_DIR = "META-INF/services/"; - public static final long DOS_EPOCH_IN_JAVA_TIME = 315561600000L; + /** Normalize timestamps. */ + public static final long DEFAULT_TIMESTAMP = + LocalDateTime.of(2010, 1, 1, 0, 0, 0) + .atZone(ZoneId.systemDefault()) + .toInstant() + .toEpochMilli(); // ZIP timestamps have a resolution of 2 seconds. // see http://www.info-zip.org/FAQ.html#limits @@ -97,15 +104,15 @@ */ private long normalizedTimestamp(String name) { if (name.endsWith(".class")) { - return DOS_EPOCH_IN_JAVA_TIME + MINIMUM_TIMESTAMP_INCREMENT; + return DEFAULT_TIMESTAMP + MINIMUM_TIMESTAMP_INCREMENT; } else { - return DOS_EPOCH_IN_JAVA_TIME; + return DEFAULT_TIMESTAMP; } } /** * Returns the time for a new Jar file entry in milliseconds since the epoch. Uses {@link - * JarCreator#DOS_EPOCH_IN_JAVA_TIME} for normalized entries, {@link System#currentTimeMillis()} + * JarCreator#DEFAULT_TIMESTAMP} for normalized entries, {@link System#currentTimeMillis()} * otherwise. * * @param filename The name of the file for which we are entering the time