From 2459e1905e1868fea73257b220811f13685eb371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Wed, 1 Oct 2025 17:17:54 +0200 Subject: [PATCH] avoid negative entry time: upgrade plexus-archiver benefit from https://github.com/codehaus-plexus/plexus-archiver/pull/388 --- pom.xml | 2 +- .../maven/archiver/MavenArchiverTest.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f8ced57..1fba6a5 100644 --- a/pom.xml +++ b/pom.xml @@ -76,7 +76,7 @@ org.codehaus.plexus plexus-archiver - 4.10.1 + 4.10.2 org.codehaus.plexus diff --git a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java index 4f0e8ea..b018c68 100644 --- a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java +++ b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java @@ -44,6 +44,7 @@ import java.util.jar.Manifest; import java.util.stream.Stream; import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; @@ -1436,4 +1437,33 @@ void testThrownParseOutputTimestampInstant(String outputTimestamp) { void testShortOffset(String value, long expected) { assertThat(parseBuildOutputTimestamp(value)).contains(Instant.ofEpochSecond(expected)); } + + private long testReproducibleJarEntryTime(String name, String timestamp) throws Exception { + File jarFile = new File("target/test/dummy-" + name + ".jar"); + + MavenArchiver archiver = getMavenArchiver(getCleanJarArchiver(jarFile)); + archiver.configureReproducibleBuild(timestamp); + archiver.createArchive(getDummySession(), getDummyProject(), new MavenArchiveConfiguration()); + + assertThat(jarFile).exists(); + ZipFile zf = new ZipFile(jarFile); + ZipEntry ze = zf.getEntry("META-INF/MANIFEST.MF"); + return ze.getTime(); + } + + /** + * before upgrading plexus archiver to 4.10.2 to benefit from https://github.com/codehaus-plexus/plexus-archiver/pull/388 + * $ zipdetails target/test/dummy-1970.jar + * gives negative Extended Timestamp in Java, that is seen as some point in time in 2106 (zip spec is unsigned) + * 0027 Extra ID #0001 5455 'UT: Extended Timestamp' + * 0029 Length 0005 + * 002B Flags '01 mod' + * 002C Mod Time FFFFF1FA 'Sun Feb 7 06:28:26 2106' + * @throws Exception + */ + @Test + void testReproducibleJar19700101() throws Exception { + long entryTime = testReproducibleJarEntryTime("1970", "10"); + assertThat(entryTime).isGreaterThanOrEqualTo(0); + } }