diff --git a/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java b/src/test/java/org/apache/maven/archiver/MavenArchiverTest.java index 4f0e8ea..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; @@ -1436,4 +1440,48 @@ 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("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(); + } }