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 42 43 44 45 46 47 48 49 50
|
Description: Set the maven.build.timestamp variable to the date defined by
the SOURCE_DATE_EPOCH environment variable to make the Maven builds reproducible.
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: no
--- a/maven-compat/src/main/java/org/apache/maven/project/interpolation/BuildTimestampValueSource.java
+++ b/maven-compat/src/main/java/org/apache/maven/project/interpolation/BuildTimestampValueSource.java
@@ -51,7 +51,15 @@
{
if ( formattedDate == null && startTime != null )
{
- formattedDate = new SimpleDateFormat( format ).format( startTime );
+ if ( System.getenv( "SOURCE_DATE_EPOCH" ) == null ) {
+ formattedDate = new SimpleDateFormat( format ).format( startTime );
+ } else {
+ // Use the SOURCE_DATE_EPOCH timestamp and make the format locale insensitive
+ SimpleDateFormat fmt = new SimpleDateFormat( format, java.util.Locale.ENGLISH );
+ fmt.setTimeZone( java.util.TimeZone.getTimeZone( "UTC" ) );
+ Date date = new Date( 1000 * Long.parseLong( System.getenv( "SOURCE_DATE_EPOCH" ) ) );
+ formattedDate = fmt.format( date );
+ }
}
return formattedDate;
--- a/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/MavenBuildTimestamp.java
+++ b/maven-model-builder/src/main/java/org/apache/maven/model/interpolation/MavenBuildTimestamp.java
@@ -22,6 +22,7 @@
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
+import java.util.Locale;
import java.util.Properties;
import java.util.TimeZone;
@@ -64,7 +65,15 @@
{
time = new Date();
}
- SimpleDateFormat dateFormat = new SimpleDateFormat( timestampFormat );
+
+ Locale locale = Locale.getDefault();
+ if ( System.getenv( "SOURCE_DATE_EPOCH" ) != null )
+ {
+ time = new Date( 1000 * Long.parseLong( System.getenv( "SOURCE_DATE_EPOCH" ) ) );
+ locale = Locale.ENGLISH;
+ }
+
+ SimpleDateFormat dateFormat = new SimpleDateFormat( timestampFormat, locale );
dateFormat.setCalendar( new GregorianCalendar() );
dateFormat.setTimeZone( DEFAULT_BUILD_TIME_ZONE );
formattedTimestamp = dateFormat.format( time );
|