diff options
author | cushon <cushon@google.com> | 2018-02-12 19:44:21 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-02-12 19:46:22 -0800 |
commit | bcefd9833cb5620fef8a27c37c2808a66b57c7e6 (patch) | |
tree | 05d713cf2c58a373fe30c9442a1b9a3967e32514 /src/java_tools/buildjar | |
parent | 26761d7258f0751c9a5f69a1fe7b889a54333652 (diff) |
Use a different date time when normalizing zip entries
Fixes #4614
PiperOrigin-RevId: 185474153
Diffstat (limited to 'src/java_tools/buildjar')
-rw-r--r-- | src/java_tools/buildjar/java/com/google/devtools/build/buildjar/jarhelper/JarHelper.java | 17 |
1 files changed, 12 insertions, 5 deletions
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 04a3248297..719fcdbee5 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.FileNotFoundException; 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 @@ import java.util.zip.CRC32; * 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 class JarHelper { 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 @@ public class JarHelper { */ 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 |