|
41 | 41 | import java.util.jar.Manifest; |
42 | 42 | import java.util.stream.Stream; |
43 | 43 | import java.util.zip.ZipEntry; |
| 44 | +import java.util.zip.ZipFile; |
44 | 45 |
|
45 | 46 | import org.apache.maven.api.Dependency; |
46 | 47 | import org.apache.maven.api.DependencyCoordinates; |
@@ -1385,4 +1386,33 @@ public void setPath(Path path) { |
1385 | 1386 | this.path = path; |
1386 | 1387 | } |
1387 | 1388 | } |
| 1389 | + |
| 1390 | + private long testReproducibleJarEntryTime(String name, String timestamp) throws Exception { |
| 1391 | + File jarFile = new File("target/test/dummy-" + name + ".jar"); |
| 1392 | + |
| 1393 | + MavenArchiver archiver = getMavenArchiver(getCleanJarArchiver(jarFile)); |
| 1394 | + archiver.configureReproducibleBuild(timestamp); |
| 1395 | + archiver.createArchive(getDummySession(), getDummyProject(), new MavenArchiveConfiguration()); |
| 1396 | + |
| 1397 | + assertThat(jarFile).exists(); |
| 1398 | + ZipFile zf = new ZipFile(jarFile); |
| 1399 | + ZipEntry ze = zf.getEntry("META-INF/MANIFEST.MF"); |
| 1400 | + return ze.getTime(); |
| 1401 | + } |
| 1402 | + |
| 1403 | + /** |
| 1404 | + * before upgrading plexus archiver to 4.10.2 to benefit from https://github.com/codehaus-plexus/plexus-archiver/pull/388 |
| 1405 | + * $ zipdetails target/test/dummy-1970.jar |
| 1406 | + * gives negative Extended Timestamp in Java, that is seen as some point in time in 2106 (zip spec is unsigned) |
| 1407 | + * 0027 Extra ID #0001 5455 'UT: Extended Timestamp' |
| 1408 | + * 0029 Length 0005 |
| 1409 | + * 002B Flags '01 mod' |
| 1410 | + * 002C Mod Time FFFFF1FA 'Sun Feb 7 06:28:26 2106' |
| 1411 | + * @throws Exception |
| 1412 | + */ |
| 1413 | + @Test |
| 1414 | + void testReproducibleJar19700101() throws Exception { |
| 1415 | + long entryTime = testReproducibleJarEntryTime("1970", "10"); |
| 1416 | + assertThat(entryTime).isGreaterThanOrEqualTo(0); |
| 1417 | + } |
1388 | 1418 | } |
0 commit comments