From 7a7307bc999be080c99412b1c67d111af1366ef7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jan=20Mat=C3=A8rne?=
Since Ant 1.10.2 the magic
- property ant.tstamp.now
can be used to specify a fixed
- date value in order to create reproducible builds. Its value must be
- a number and is interpreted as seconds since the epoch (midnight
- 1970-01-01).
ant.tstamp.now
can be used to specify a fixed
+date value in order to create reproducible builds. Its value must be
+a number and is interpreted as seconds since the epoch (midnight
+1970-01-01). With ant.tstamp.now.iso
you could also specify that
+value in ISO-8601 format (1972-04-17T08:07:00Z
). If you specify a value
+in an invalid format an INFO message will be logged and the value will be ignored.
number, seconds since the epoch (midnight 1970-01-01) | The value to use as current time and date for <tstamp> | +
ant.tstamp.now.iso |
+ ISO-8601 timestamp string like 1972-04-17T08:07:00Z |
+
diff --git a/src/main/org/apache/tools/ant/MagicNames.java b/src/main/org/apache/tools/ant/MagicNames.java index 5f6aec9ca..cfd4cc769 100644 --- a/src/main/org/apache/tools/ant/MagicNames.java +++ b/src/main/org/apache/tools/ant/MagicNames.java @@ -308,5 +308,18 @@ public final class MagicNames { * @since Ant 1.10.2 */ public static final String TSTAMP_NOW = "ant.tstamp.now"; + + /** + * Magic property that can be set to contain a value for tstamp's + * "now" in order to make builds that use the task create + * reproducible results. + * + *
The value is expected to be in ISO time format + * (1972-04-17T08:07)
+ * + * Value: {@value} + * @since Ant 1.10.2 + */ + public static final String TSTAMP_NOW_ISO = "ant.tstamp.now.iso"; } diff --git a/src/main/org/apache/tools/ant/taskdefs/Tstamp.java b/src/main/org/apache/tools/ant/taskdefs/Tstamp.java index 98dd77927..3f5c172f4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Tstamp.java +++ b/src/main/org/apache/tools/ant/taskdefs/Tstamp.java @@ -19,6 +19,7 @@ package org.apache.tools.ant.taskdefs; import java.text.SimpleDateFormat; +import java.time.Instant; import java.util.Calendar; import java.util.Date; import java.util.HashMap; @@ -26,9 +27,12 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.NoSuchElementException; +import java.util.Optional; import java.util.StringTokenizer; import java.util.TimeZone; import java.util.Vector; +import java.util.function.BiFunction; +import java.util.function.Function; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Location; @@ -111,16 +115,45 @@ public class Tstamp extends Task { * Return the {@link Date} instance to use as base for DSTAMP, TSTAMP and TODAY. */ protected Date getNow() { - String magicNow = getProject().getProperty(MagicNames.TSTAMP_NOW); - if (magicNow != null && magicNow.length() > 0) { + Optional