File: reproducible-javadoc-timestamp.diff

package info (click to toggle)
openjdk-11 11.0.26%2B4-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 780,552 kB
  • sloc: java: 5,205,794; xml: 1,192,267; cpp: 1,138,332; ansic: 462,135; javascript: 162,416; sh: 16,722; objc: 13,719; python: 4,757; asm: 3,570; makefile: 2,953; perl: 357; awk: 351; sed: 172; jsp: 24; csh: 3
file content (41 lines) | stat: -rw-r--r-- 1,873 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Description: Makes the timestamp in the javadoc files reproducible when SOURCE_DATE_EPOCH is specified
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: no
--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Head.java
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/markup/Head.java
@@ -256,6 +256,9 @@
      */
     public Content toContent() {
         Date now = showTimestamp ? calendar.getTime() : null;
+        if (now != null && System.getenv("SOURCE_DATE_EPOCH") != null) {
+            now = new Date(1000 * Long.parseLong(System.getenv("SOURCE_DATE_EPOCH")));
+        }
 
         HtmlTree tree = new HtmlTree(HtmlTag.HEAD);
         if (showGeneratedBy) {
@@ -269,6 +272,9 @@
 
         if (showMetaCreated) {
             SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+            if (System.getenv("SOURCE_DATE_EPOCH") != null) {
+                dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+            }
             tree.add(HtmlTree.META(
                     (htmlVersion == HtmlVersion.HTML5) ? "dc.created" : "date",
                     dateFormat.format(now)));
@@ -298,7 +304,14 @@
     private Comment getGeneratedBy(boolean timestamp, Date now) {
         String text = "Generated by javadoc"; // marker string, deliberately not localized
         if (timestamp) {
-            text += " ("+ docletVersion + ") on " + now;
+            text += " ("+ docletVersion + ") on ";
+            if (System.getenv("SOURCE_DATE_EPOCH") == null) {
+                text += now;
+            } else {
+                SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
+                fmt.setTimeZone(TimeZone.getTimeZone("UTC"));
+                text += fmt.format(now);
+            }
         }
         return new Comment(text);
     }