java-17-openjdk/reproducible-javadoc-timestamp.patch

61 lines
2.4 KiB
Diff

--- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java
+++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlConfiguration.java
@@ -213,6 +213,12 @@ public class HtmlConfiguration extends BaseConfiguration {
}
docletVersion = v;
+ if (System.getenv("SOURCE_DATE_EPOCH") != null) {
+ startTime = new Date(1000 * Long.parseLong(System.getenv("SOURCE_DATE_EPOCH")));
+ } else {
+ startTime = new Date();
+ }
+
conditionalPages = EnumSet.noneOf(ConditionalPage.class);
}
protected void initConfiguration(DocletEnvironment docEnv,
@@ -223,7 +229,7 @@ public class HtmlConfiguration extends BaseConfiguration {
}
private final Runtime.Version docletVersion;
- public final Date startTime = new Date();
+ public final Date startTime;
@Override
public Runtime.Version getDocletVersion() {
--- 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
@@ -33,6 +33,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
+import java.util.TimeZone;
import jdk.javadoc.internal.doclets.toolkit.Content;
import jdk.javadoc.internal.doclets.toolkit.util.DocPath;
@@ -265,6 +266,9 @@ public class Head extends Content {
if (showTimestamp) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ if (System.getenv("SOURCE_DATE_EPOCH") != null) {
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ }
tree.add(HtmlTree.META("dc.created", dateFormat.format(generatedDate)));
}
@@ -298,7 +302,14 @@ public class Head extends Content {
String text = "Generated by javadoc"; // marker string, deliberately not localized
text += " (" + docletVersion.feature() + ")";
if (timestamp) {
- text += " on " + now;
+ text += " 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);
}