Description: add support SOURCE_DATE_EPOCH
 See: https://reproducible-builds.org/specs/source-date-epoch/
Author: tony mancill <tmancill@debian.org>
Last-Update: 2017-08-13

--- a/org.mangosdk.spi/src/main/java/org/mangosdk/spi/processor/Persistence.java
+++ b/org.mangosdk.spi/src/main/java/org/mangosdk/spi/processor/Persistence.java
@@ -131,8 +131,10 @@
 		FileObject output = filer.createResource(StandardLocation.CLASS_OUTPUT, "", path + serviceName);
 		Writer writer = output.openWriter();
 		try {
+			SimpleDateFormat fmt = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US);
+			fmt.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
 			writer.write("# Generated by " + name + "\n");
-			writer.write("# " + new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US).format(new Date()) + "\n");
+			writer.write("# " + fmt.format(getBuildDate()) + "\n");
 			writer.write(value);
 		}
 		finally {
@@ -144,4 +146,17 @@
 			}
 		}
 	}
+
+	// return build timestamp, either the value of SOURCE_DATE_EPOCH
+	// in milliseconds or the current system time in milliseconds
+	// see: https://reproducible-builds.org/specs/source-date-epoch/
+	private long getBuildDate() {
+		try {
+			return Long.valueOf(System.getenv("SOURCE_DATE_EPOCH")) * 1000L;
+		}
+		catch (Exception e) {
+			// ignore any problems retrieving or casting SOURCE_DATE_EPOCH
+		}
+		return System.currentTimeMillis();
+	}
 }
