From 3b0176d1af91005c0304bc51754a2cdcd1658ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Wed, 24 Sep 2025 13:38:24 +0200 Subject: [PATCH 1/2] test non-MS DOS timestamp --- .../maven/archiver/MavenArchiverTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java index 4f0e8ea..7a3a871 100644 --- a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java +++ b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java @@ -1436,4 +1436,24 @@ void testThrownParseOutputTimestampInstant(String outputTimestamp) { void testShortOffset(String value, long expected) { assertThat(parseBuildOutputTimestamp(value)).contains(Instant.ofEpochSecond(expected)); } + + private void testJar(String name, String timestamp) throws Exception { + File jarFile = new File("target/test/dummy-" + name + ".jar"); + JarArchiver jarArchiver = getCleanJarArchiver(jarFile); + + MavenArchiver archiver = getMavenArchiver(jarArchiver); + archiver.configureReproducibleBuild(timestamp); + + MavenSession session = getDummySession(); + MavenProject project = getDummyProject(); + + archiver.createArchive(session, project, new MavenArchiveConfiguration()); + assertThat(jarFile).exists(); + } + + @Test + void testJar() throws Exception { + testJar("1970", "10"); + testJar("2000", "2000-01-01T00:00:00Z"); + } } From 88ac8071ab2fe8b023d2f417f1621c6748bf18f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Fri, 26 Sep 2025 00:18:27 +0200 Subject: [PATCH 2/2] add more timestamps --- .../maven/archiver/MavenArchiverTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java index 7a3a871..ac196d7 100644 --- a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java +++ b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java @@ -45,6 +45,8 @@ import java.util.stream.Stream; import java.util.zip.ZipEntry; +import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; +import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.DefaultArtifactHandler; @@ -69,6 +71,8 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream; +import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -1454,6 +1458,30 @@ private void testJar(String name, String timestamp) throws Exception { @Test void testJar() throws Exception { testJar("1970", "10"); + testJar("1970-0h0m10", "1970-01-01T00:00:10Z"); + testJar("1970-2h", "1970-01-01T02:00:00Z"); + testJar("1970-1h59", "1970-01-01T01:59:00Z"); + testJar("1970-1h", "1970-01-01T01:00:00Z"); + testJar("1970-0h59", "1970-01-01T00:59:00Z"); testJar("2000", "2000-01-01T00:00:00Z"); } + + @Test + void testCompress() throws Exception { + File zipFile = new File("target/test/dummy.zip"); + ZipArchiveOutputStream zipArchiveOutputStream = + new ZipArchiveOutputStream(bufferedOutputStream(fileOutputStream(zipFile, "zip"))); + zipArchiveOutputStream.setEncoding("UTF-8"); + zipArchiveOutputStream.setCreateUnicodeExtraFields(ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NEVER); + zipArchiveOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED); + + ZipArchiveEntry ze = new ZipArchiveEntry("f.txt"); + ze.setTime(0); + + zipArchiveOutputStream.putArchiveEntry(ze); + zipArchiveOutputStream.write(1); + zipArchiveOutputStream.closeArchiveEntry(); + + zipArchiveOutputStream.close(); + } }