Skip to content

Commit

Permalink
Support for Maven reproducible builds
Browse files Browse the repository at this point in the history
  • Loading branch information
basil committed Apr 12, 2024
1 parent e33d6fc commit 0930bde
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void afterSessionStart(MavenSession session) throws MavenExecutionExcepti
long start = System.nanoTime();
File dir = session.getRequest().getMultiModuleProjectDirectory();
log.debug("running in " + dir);
String fullHash, hash;
String fullHash, hash, timestamp;
int count;
try (Git git = Git.open(dir)) {
Status status = git.status().call();
Expand All @@ -100,6 +100,7 @@ public void afterSessionStart(MavenSession session) throws MavenExecutionExcepti
hash = head.abbreviate(ABBREV_LENGTH).name();
try (RevWalk walk = new RevWalk(repo)) {
RevCommit headC = walk.parseCommit(head);
timestamp = DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochSecond(headC.getCommitTime()));
count = revCount(walk, headC);
{ // Look for repository commits reachable from HEAD that would clash.
Map<String,List<RevCommit>> encountered = new HashMap<>();
Expand Down Expand Up @@ -133,9 +134,10 @@ public void afterSessionStart(MavenSession session) throws MavenExecutionExcepti
}
log.debug("Spent " + (System.nanoTime() - start) / 1000 / 1000 + "ms on calculations");
String value = String.format(props.getProperty("changelist.format", "-rc%d.%s"), count, sanitize(hash));
log.info("Setting: -Dchangelist=" + value + " -DscmTag=" + fullHash);
log.info("Setting: -Dchangelist=" + value + " -DscmTag=" + fullHash + " -Dproject.build.outputTimestamp=" + timestamp);
props.setProperty("changelist", value);
props.setProperty("scmTag", fullHash);
props.setProperty("project.build.outputTimestamp", timestamp);
} else {
log.info("Declining to override the `changelist` or `scmTag` properties");
}
Expand Down

0 comments on commit 0930bde

Please sign in to comment.