Bug#914278: openjdk-11: Reproducible properties file header when SOURCE_DATE_EPOCH is specified

2018-11-21 Thread Holger Levsen
clone 914278 -1 
reassign -1 strip-nondeterminism
block -1 by 914278
retitle -1 strip-nondeterminism: disable javadoc handler
# thanks Emmanuel


-- 
cheers,
Holger

---
   holger@(debian|reproducible-builds|layer-acht).org
   PGP fingerprint: B8BF 5413 7B09 D35C F026 FE9D 091A B856 069A AA1C


signature.asc
Description: PGP signature


Bug#914278: openjdk-11: Reproducible properties file header when SOURCE_DATE_EPOCH is specified

2018-11-21 Thread Chris Lamb
Hi,

> openjdk-11: Reproducible properties file header when
> SOURCE_DATE_EPOCH is specified

Thanks for this patch! I've updated the reference to the
corresponding "issue" in our Git repository here:

  
https://salsa.debian.org/reproducible-builds/reproducible-notes/commit/6e9c5774bfc3f16f5bb03f1563af058dc3d733e2


Regards,

-- 
  ,''`.
 : :'  : Chris Lamb
 `. `'`  la...@debian.org / chris-lamb.co.uk
   `-



Bug#914278: openjdk-11: Reproducible properties file header when SOURCE_DATE_EPOCH is specified

2018-11-21 Thread Emmanuel Bourg
Source: openjdk-11
Severity: normal
User: reproducible-bui...@lists.alioth.debian.org
Usertags: timestamps toolchain

When writing a properties file using the java.util.Properties class, a header
containing the current date is automatically added. This renders the output non
reproducible.

Here is a patch for java.util.Properties checking if the SOURCE_DATE_EPOCH
environment variable is specified and using it instead of the current date
for the timestamp.
Description: Makes the timestamp in the properties files header reproducible 
when SOURCE_DATE_EPOCH is specified
Author: Emmanuel Bourg 
Forwarded: no
--- a/src/java.base/share/classes/java/util/Properties.java
+++ b/src/java.base/share/classes/java/util/Properties.java
@@ -905,7 +905,7 @@
 if (comments != null) {
 writeComments(bw, comments);
 }
-bw.write("#" + new Date().toString());
+bw.write("#" + getFormattedTimestamp());
 bw.newLine();
 synchronized (this) {
 for (Map.Entry e : entrySet()) {
@@ -1555,4 +1555,22 @@
 }
 this.map = map;
 }
+
+/**
+ * Returns a formatted timestamp to be used in the properties file header.
+ * The date used is the current date, unless the SOURCE_DATE_EPOCH
+ * environment variable is specified. In this case the format used is
+ * locale and timezone insensitive to ensure the output is reproducible.
+ */
+private String getFormattedTimestamp() {
+if (System.getenv("SOURCE_DATE_EPOCH") == null) {
+return new Date().toString();
+} else {
+// Use the SOURCE_DATE_EPOCH timestamp and make the format 
locale/timezone insensitive
+java.text.SimpleDateFormat fmt = new 
java.text.SimpleDateFormat("-MM-dd HH:mm:ss z", java.util.Locale.ENGLISH);
+fmt.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
+Date date = new Date(1000 * 
Long.parseLong(System.getenv("SOURCE_DATE_EPOCH")));
+return fmt.format(date);
+}
+}
 }