-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[maven-release-plugin] Allow to override build date with SOURCE_DATE_…
…EPOCH in order to make builds reproducible. See https://reproducible-builds.org/ for why this is good and https://reproducible-builds.org/specs/source-date-epoch/ for the definition of this variable. Based on https://salsa.debian.org/java-team/maven-bundle-plugin/blob/master/debian/patches/use-changelog-date-as-pom.properties-timestamp.patch by Emmanuel Bourg <[email protected]>
- Loading branch information
1 parent
cefcb13
commit 7ece2fe
Showing
2 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...aven-bundle-plugin/src/main/java/org/apache/felix/bundleplugin/TimestampedProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.apache.felix.bundleplugin; | ||
|
||
import java.io.*; | ||
import java.text.*; | ||
import java.util.*; | ||
import java.util.regex.*; | ||
|
||
/** | ||
* Properties file timestamped with a specified date. | ||
*/ | ||
class TimestampedProperties extends Properties | ||
{ | ||
private Date date; | ||
|
||
public TimestampedProperties(Date date) { | ||
this.date = date; | ||
} | ||
|
||
@Override | ||
public void store(OutputStream out, String comments) throws IOException { | ||
store(new OutputStreamWriter(out, "ISO-8859-1"), comments); | ||
} | ||
|
||
@Override | ||
public void store(Writer out, String comments) throws IOException { | ||
// store the properties file in memory | ||
StringWriter buffer = new StringWriter(); | ||
super.store(buffer, comments); | ||
|
||
// Replace the date on the second line of the file | ||
SimpleDateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH); | ||
fmt.setTimeZone(TimeZone.getTimeZone("UTC")); | ||
String[] lines = buffer.toString().split(Pattern.quote(System.getProperty("line.separator"))); | ||
lines[1] = "#" + fmt.format(date); | ||
|
||
// write the file | ||
BufferedWriter writer = new BufferedWriter(out); | ||
try { | ||
for (String line : lines) { | ||
writer.write(line); | ||
writer.newLine(); | ||
} | ||
writer.flush(); | ||
} finally { | ||
writer.close(); | ||
} | ||
} | ||
} |