6666 *
6767 * @author <a href="[email protected] ">Emmanuel Venisse</a> 6868 * @author kama
69- * @version $Id: $Id
7069 */
7170public class MavenArchiver {
7271
@@ -745,6 +744,9 @@ public Date configureReproducible(String outputTimestamp) {
745744 * <p>Either as {@link java.time.format.DateTimeFormatter#ISO_OFFSET_DATE_TIME} or as a number representing seconds
746745 * since the epoch (like <a href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>).
747746 *
747+ * <p>Since 3.6.4, if not configured or disabled, the {@code SOURCE_DATE_EPOCH} environment variable is used as
748+ * a fallback value, to ease forcing Reproducible Build externally when the build has not enabled it natively in POM.
749+ *
748750 * @param outputTimestamp the value of {@code ${project.build.outputTimestamp}} (may be {@code null})
749751 * @return the parsed timestamp as an {@code Optional<Instant>}, {@code empty} if input is {@code null} or input
750752 * contains only 1 character (not a number)
@@ -753,16 +755,17 @@ public Date configureReproducible(String outputTimestamp) {
753755 * the valid range 1980-01-01T00:00:02Z to 2099-12-31T23:59:59Z as defined by
754756 * <a href="https://pkwaredownloads.blob.core.windows.net/pem/APPNOTE.txt">ZIP application note</a>,
755757 * section 4.4.6.
758+ * @see <a href="https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=74682318">Maven Wiki "Reproducible/Verifiable
759+ * Builds"</a>
756760 */
757761 public static Optional <Instant > parseBuildOutputTimestamp (String outputTimestamp ) {
758- final String sourceDateEpoch = System .getenv ("SOURCE_DATE_EPOCH" );
759762 // Fail fast on null and no timestamp configured (1 character configuration is useful to override
760763 // a full value during pom inheritance)
761764 if (outputTimestamp == null || (outputTimestamp .length () < 2 && !isNumeric (outputTimestamp ))) {
762- if (sourceDateEpoch == null ) {
765+ // Reproducible Builds not configured or disabled => fallback to SOURCE_DATE_EPOCH env
766+ outputTimestamp = System .getenv ("SOURCE_DATE_EPOCH" );
767+ if (outputTimestamp == null ) {
763768 return Optional .empty ();
764- } else {
765- outputTimestamp = sourceDateEpoch ;
766769 }
767770 }
768771
@@ -796,7 +799,6 @@ public static Optional<Instant> parseBuildOutputTimestamp(String outputTimestamp
796799 }
797800
798801 private static boolean isNumeric (String str ) {
799-
800802 if (str .isEmpty ()) {
801803 return false ;
802804 }
0 commit comments