Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/test/java/org/apache/maven/archiver/MavenArchiverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
}
}
Loading