|
44 | 44 | import java.util.jar.Manifest; |
45 | 45 | import java.util.stream.Stream; |
46 | 46 | import java.util.zip.ZipEntry; |
| 47 | +import java.util.zip.ZipFile; |
47 | 48 |
|
48 | 49 | import org.apache.maven.artifact.Artifact; |
49 | 50 | import org.apache.maven.artifact.handler.ArtifactHandler; |
@@ -1436,4 +1437,33 @@ void testThrownParseOutputTimestampInstant(String outputTimestamp) { |
1436 | 1437 | void testShortOffset(String value, long expected) { |
1437 | 1438 | assertThat(parseBuildOutputTimestamp(value)).contains(Instant.ofEpochSecond(expected)); |
1438 | 1439 | } |
| 1440 | + |
| 1441 | + private long testReproducibleJarEntryTime(String name, String timestamp) throws Exception { |
| 1442 | + File jarFile = new File("target/test/dummy-" + name + ".jar"); |
| 1443 | + |
| 1444 | + MavenArchiver archiver = getMavenArchiver(getCleanJarArchiver(jarFile)); |
| 1445 | + archiver.configureReproducibleBuild(timestamp); |
| 1446 | + archiver.createArchive(getDummySession(), getDummyProject(), new MavenArchiveConfiguration()); |
| 1447 | + |
| 1448 | + assertThat(jarFile).exists(); |
| 1449 | + ZipFile zf = new ZipFile(jarFile); |
| 1450 | + ZipEntry ze = zf.getEntry("META-INF/MANIFEST.MF"); |
| 1451 | + return ze.getTime(); |
| 1452 | + } |
| 1453 | + |
| 1454 | + /** |
| 1455 | + * before upgrading plexus archiver to 4.10.2 to benefit from https://github.com/codehaus-plexus/plexus-archiver/pull/388 |
| 1456 | + * $ zipdetails target/test/dummy-1970.jar |
| 1457 | + * gives negative Extended Timestamp in Java, that is seen as some point in time in 2106 (zip spec is unsigned) |
| 1458 | + * 0027 Extra ID #0001 5455 'UT: Extended Timestamp' |
| 1459 | + * 0029 Length 0005 |
| 1460 | + * 002B Flags '01 mod' |
| 1461 | + * 002C Mod Time FFFFF1FA 'Sun Feb 7 06:28:26 2106' |
| 1462 | + * @throws Exception |
| 1463 | + */ |
| 1464 | + @Test |
| 1465 | + void testReproducibleJar19700101() throws Exception { |
| 1466 | + long entryTime = testReproducibleJarEntryTime("1970", "10"); |
| 1467 | + assertThat(entryTime).isGreaterThanOrEqualTo(0); |
| 1468 | + } |
1439 | 1469 | } |
0 commit comments