This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch maven-archiver-3.x
in repository https://gitbox.apache.org/repos/asf/maven-archiver.git
The following commit(s) were added to refs/heads/maven-archiver-3.x by this
push:
new 10b1a57 Add more timestamp tests
10b1a57 is described below
commit 10b1a57a6b5443c0991e4d263696818dca732f64
Author: Hervé Boutemy <[email protected]>
AuthorDate: Wed Sep 24 13:38:24 2025 +0200
Add more timestamp tests
---
.../apache/maven/archiver/MavenArchiverTest.java | 51 ++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
index b018c68..9e06e2e 100644
--- a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
+++ b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
@@ -46,6 +46,8 @@ import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+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;
@@ -70,6 +72,9 @@ import static
org.apache.maven.archiver.MavenArchiver.parseBuildOutputTimestamp;
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.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -1466,4 +1471,50 @@ class MavenArchiverTest {
long entryTime = testReproducibleJarEntryTime("1970", "10");
assertThat(entryTime).isGreaterThanOrEqualTo(0);
}
+
+ private void checkJar(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 checkJar() throws Exception {
+ checkJar("1970", "10");
+ checkJar("1970-0h0m10", "1970-01-01T00:00:10Z");
+ checkJar("1970-2h", "1970-01-01T02:00:00Z");
+ checkJar("1970-1h59", "1970-01-01T01:59:00Z");
+ checkJar("1970-1h", "1970-01-01T01:00:00Z");
+ checkJar("1970-0h59", "1970-01-01T00:59:00Z");
+ checkJar("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();
+
+ assertTrue(zipFile.delete());
+ }
}