Skip to content

Commit 10b1a57

Browse files
hboutemyslachiewicz
authored andcommitted
Add more timestamp tests
1 parent b716b9a commit 10b1a57

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

src/test/java/org/apache/maven/archiver/MavenArchiverTest.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
import java.util.zip.ZipEntry;
4747
import java.util.zip.ZipFile;
4848

49+
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
50+
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
4951
import org.apache.maven.artifact.Artifact;
5052
import org.apache.maven.artifact.handler.ArtifactHandler;
5153
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
@@ -70,6 +72,9 @@
7072
import static org.assertj.core.api.Assertions.assertThat;
7173
import static org.assertj.core.api.Assertions.assertThatCode;
7274
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;
7378
import static org.mockito.Mockito.mock;
7479
import static org.mockito.Mockito.when;
7580

@@ -1466,4 +1471,50 @@ void testReproducibleJar19700101() throws Exception {
14661471
long entryTime = testReproducibleJarEntryTime("1970", "10");
14671472
assertThat(entryTime).isGreaterThanOrEqualTo(0);
14681473
}
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+
}
14691520
}

0 commit comments

Comments
 (0)