Skip to content

Commit

Permalink
Fix non-reproducible archives (bazelbuild#304)
Browse files Browse the repository at this point in the history
Fix non-reproducible archives by creating a fixed GregorianCalendar on a given date (slightly later than Jan 1 1980, since Java 7 and 8 have different special casing there).
  • Loading branch information
benjaminRomano committed Apr 7, 2020
1 parent 484f116 commit 5efac99
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/main/kotlin/io/bazel/kotlin/builder/utils/jars/JarHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,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.Calendar
import java.util.GregorianCalendar
import java.util.HashSet
import java.util.jar.Attributes
import java.util.jar.JarEntry
Expand Down Expand Up @@ -245,11 +245,10 @@ open class JarHelper internal constructor(
const val SERVICES_DIR = "META-INF/services/"
internal val EMPTY_BYTEARRAY = ByteArray(0)

/** Normalize timestamps. */
val DEFAULT_TIMESTAMP = LocalDateTime.of(1980, 1, 1, 0, 0, 0)
.atZone(ZoneId.systemDefault())
.toInstant()
.toEpochMilli()
// Normalized timestamp for zip entries
// We do not include the system's default timezone and locale and additionally avoid the unix epoch
// to ensure Java's zip implementation does not add the System's timezone into the extra field of the zip entry
val DEFAULT_TIMESTAMP = GregorianCalendar(1980, Calendar.FEBRUARY, 1, 0, 0, 0).getTimeInMillis()

// These attributes are used by JavaBuilder, Turbine, and ijar.
// They must all be kept in sync.
Expand Down

0 comments on commit 5efac99

Please sign in to comment.