You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2019/10/18 05:59:50 UTC

[maven-archiver] branch MSHARED-837 updated: support int representing seconds since the epoch

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch MSHARED-837
in repository https://gitbox.apache.org/repos/asf/maven-archiver.git


The following commit(s) were added to refs/heads/MSHARED-837 by this push:
     new 007ab27  support int representing seconds since the epoch
007ab27 is described below

commit 007ab2754b978a8ae3928f9aff7afd7049c8f0d7
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Fri Oct 18 07:59:45 2019 +0200

    support int representing seconds since the epoch
---
 src/main/java/org/apache/maven/archiver/MavenArchiver.java     | 10 ++++++++--
 src/test/java/org/apache/maven/archiver/MavenArchiverTest.java |  2 ++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/maven/archiver/MavenArchiver.java b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
index c8b9d49..013aacd 100644
--- a/src/main/java/org/apache/maven/archiver/MavenArchiver.java
+++ b/src/main/java/org/apache/maven/archiver/MavenArchiver.java
@@ -763,8 +763,9 @@ public class MavenArchiver
     }
 
     /**
-     * Parse output timestamp configured for Reproducible Builds' archive entries, formatted as ISO 8601
-     * <code>yyyy-MM-dd'T'HH:mm:ssXXX</code>.
+     * Parse output timestamp configured for Reproducible Builds' archive entries, either formatted as ISO 8601
+     * <code>yyyy-MM-dd'T'HH:mm:ssXXX</code> or as an int representing seconds since the epoch (like
+     * <a href="https://reproducible-builds.org/docs/source-date-epoch/">SOURCE_DATE_EPOCH</a>.
      *
      * @param outputTimestamp the value of <code>${project.build.outputTimestamp}</code> (may be <code>null</code>)
      * @return the parsed timestamp, may be <code>null</code> if <code>null</code> input or input contains only 1
@@ -773,6 +774,11 @@ public class MavenArchiver
      */
     public Date parseOutputTimestamp( String outputTimestamp )
     {
+        if ( StringUtils.isNumeric( outputTimestamp ) && StringUtils.isNotEmpty( outputTimestamp ) )
+        {
+            return new Date( Long.parseLong( outputTimestamp ) * 1000 );
+        }
+
         if ( outputTimestamp == null || outputTimestamp.length() < 2 )
         {
             // no timestamp configured (1 character configuration is useful to override a full value during pom
diff --git a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
index 99c6c62..2f5965d 100644
--- a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
+++ b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
@@ -1515,6 +1515,8 @@ public class MavenArchiverTest
         assertNull( archiver.parseOutputTimestamp( " " ) );
         assertNull( archiver.parseOutputTimestamp( "_" ) );
 
+        assertEquals( 1570300662000L, archiver.parseOutputTimestamp( "1570300662" ).getTime() );
+
         assertEquals( 1570300662000L, archiver.parseOutputTimestamp( "2019-10-05T18:37:42Z" ).getTime() );
         assertEquals( 1570300662000L, archiver.parseOutputTimestamp( "2019-10-05T20:37:42+02:00" ).getTime() );
         assertEquals( 1570300662000L, archiver.parseOutputTimestamp( "2019-10-05T16:37:42-02:00" ).getTime() );