From 0930bdec13b95170aee33053e916e9b2637a48c9 Mon Sep 17 00:00:00 2001 From: Basil Crow Date: Fri, 12 Apr 2024 12:03:24 -0700 Subject: [PATCH] Support for Maven reproducible builds --- .../incrementals/git_changelist_maven_extension/Main.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/git-changelist-maven-extension/src/main/java/io/jenkins/tools/incrementals/git_changelist_maven_extension/Main.java b/git-changelist-maven-extension/src/main/java/io/jenkins/tools/incrementals/git_changelist_maven_extension/Main.java index 106b330..89f794a 100644 --- a/git-changelist-maven-extension/src/main/java/io/jenkins/tools/incrementals/git_changelist_maven_extension/Main.java +++ b/git-changelist-maven-extension/src/main/java/io/jenkins/tools/incrementals/git_changelist_maven_extension/Main.java @@ -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(); @@ -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> encountered = new HashMap<>(); @@ -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"); }