|
46 | 46 | import java.util.zip.ZipEntry; |
47 | 47 | import java.util.zip.ZipFile; |
48 | 48 |
|
| 49 | +import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; |
| 50 | +import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream; |
49 | 51 | import org.apache.maven.artifact.Artifact; |
50 | 52 | import org.apache.maven.artifact.handler.ArtifactHandler; |
51 | 53 | import org.apache.maven.artifact.handler.DefaultArtifactHandler; |
|
70 | 72 | import static org.assertj.core.api.Assertions.assertThat; |
71 | 73 | import static org.assertj.core.api.Assertions.assertThatCode; |
72 | 74 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
| 75 | +import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream; |
| 76 | +import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream; |
| 77 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
73 | 78 | import static org.mockito.Mockito.mock; |
74 | 79 | import static org.mockito.Mockito.when; |
75 | 80 |
|
@@ -1466,4 +1471,50 @@ void testReproducibleJar19700101() throws Exception { |
1466 | 1471 | long entryTime = testReproducibleJarEntryTime("1970", "10"); |
1467 | 1472 | assertThat(entryTime).isGreaterThanOrEqualTo(0); |
1468 | 1473 | } |
| 1474 | + |
| 1475 | + private void checkJar(String name, String timestamp) throws Exception { |
| 1476 | + File jarFile = new File("target/test/dummy-" + name + ".jar"); |
| 1477 | + JarArchiver jarArchiver = getCleanJarArchiver(jarFile); |
| 1478 | + |
| 1479 | + MavenArchiver archiver = getMavenArchiver(jarArchiver); |
| 1480 | + archiver.configureReproducibleBuild(timestamp); |
| 1481 | + |
| 1482 | + MavenSession session = getDummySession(); |
| 1483 | + MavenProject project = getDummyProject(); |
| 1484 | + |
| 1485 | + archiver.createArchive(session, project, new MavenArchiveConfiguration()); |
| 1486 | + assertThat(jarFile).exists(); |
| 1487 | + } |
| 1488 | + |
| 1489 | + @Test |
| 1490 | + void checkJar() throws Exception { |
| 1491 | + checkJar("1970", "10"); |
| 1492 | + checkJar("1970-0h0m10", "1970-01-01T00:00:10Z"); |
| 1493 | + checkJar("1970-2h", "1970-01-01T02:00:00Z"); |
| 1494 | + checkJar("1970-1h59", "1970-01-01T01:59:00Z"); |
| 1495 | + checkJar("1970-1h", "1970-01-01T01:00:00Z"); |
| 1496 | + checkJar("1970-0h59", "1970-01-01T00:59:00Z"); |
| 1497 | + checkJar("2000", "2000-01-01T00:00:00Z"); |
| 1498 | + } |
| 1499 | + |
| 1500 | + @Test |
| 1501 | + void testCompress() throws Exception { |
| 1502 | + File zipFile = new File("target/test/dummy.zip"); |
| 1503 | + ZipArchiveOutputStream zipArchiveOutputStream = |
| 1504 | + new ZipArchiveOutputStream(bufferedOutputStream(fileOutputStream(zipFile, "zip"))); |
| 1505 | + zipArchiveOutputStream.setEncoding("UTF-8"); |
| 1506 | + zipArchiveOutputStream.setCreateUnicodeExtraFields(ZipArchiveOutputStream.UnicodeExtraFieldPolicy.NEVER); |
| 1507 | + zipArchiveOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED); |
| 1508 | + |
| 1509 | + ZipArchiveEntry ze = new ZipArchiveEntry("f.txt"); |
| 1510 | + ze.setTime(0); |
| 1511 | + |
| 1512 | + zipArchiveOutputStream.putArchiveEntry(ze); |
| 1513 | + zipArchiveOutputStream.write(1); |
| 1514 | + zipArchiveOutputStream.closeArchiveEntry(); |
| 1515 | + |
| 1516 | + zipArchiveOutputStream.close(); |
| 1517 | + |
| 1518 | + assertTrue(zipFile.delete()); |
| 1519 | + } |
1469 | 1520 | } |
0 commit comments