Search in sources :

Example 1 with HashingDeterministicJarWriter

use of com.facebook.buck.io.HashingDeterministicJarWriter in project buck by facebook.

the class DefaultFileHashCacheTest method whenJarMemberWithEmptyManifestIsQueriedThenThrow.

@Test(expected = NoSuchFileException.class)
public void whenJarMemberWithEmptyManifestIsQueriedThenThrow() throws IOException {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    DefaultFileHashCache cache = new DefaultFileHashCache(filesystem, Optional.empty());
    Path abiJarPath = Paths.get("empty-manifest.jar");
    Path memberPath = Paths.get("Empty.class");
    try (HashingDeterministicJarWriter jar = new HashingDeterministicJarWriter(new JarOutputStream(filesystem.newFileOutputStream(abiJarPath)))) {
        jar.writeUnhashedEntry(JarFile.MANIFEST_NAME, new ByteArrayInputStream(new byte[0])).writeUnhashedEntry(memberPath.toString(), new ByteArrayInputStream("Contents".getBytes(StandardCharsets.UTF_8)));
    }
    cache.get(ArchiveMemberPath.of(abiJarPath, memberPath));
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) HashingDeterministicJarWriter(com.facebook.buck.io.HashingDeterministicJarWriter) JarOutputStream(java.util.jar.JarOutputStream) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 2 with HashingDeterministicJarWriter

use of com.facebook.buck.io.HashingDeterministicJarWriter in project buck by facebook.

the class DefaultFileHashCacheTest method whenJarMemberWithoutHashInManifestIsQueriedThenThrow.

@Test(expected = NoSuchFileException.class)
public void whenJarMemberWithoutHashInManifestIsQueriedThenThrow() throws IOException {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    DefaultFileHashCache cache = new DefaultFileHashCache(filesystem, Optional.empty());
    Path abiJarPath = Paths.get("test-abi.jar");
    Path memberPath = Paths.get("Unhashed.txt");
    String memberContents = "Some contents";
    try (HashingDeterministicJarWriter jar = new HashingDeterministicJarWriter(new JarOutputStream(filesystem.newFileOutputStream(abiJarPath)))) {
        jar.writeEntry("SomeClass.class", new ByteArrayInputStream(memberContents.getBytes(StandardCharsets.UTF_8))).writeUnhashedEntry(memberPath.toString(), new ByteArrayInputStream(memberContents.getBytes(StandardCharsets.UTF_8)));
    }
    cache.get(ArchiveMemberPath.of(abiJarPath, memberPath));
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) ByteArrayInputStream(java.io.ByteArrayInputStream) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) HashingDeterministicJarWriter(com.facebook.buck.io.HashingDeterministicJarWriter) JarOutputStream(java.util.jar.JarOutputStream) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 3 with HashingDeterministicJarWriter

use of com.facebook.buck.io.HashingDeterministicJarWriter in project buck by facebook.

the class DefaultFileHashCacheTest method whenJarMemberWithHashInManifestIsQueriedThenCacheCorrectlyObtainsIt.

@Test
public void whenJarMemberWithHashInManifestIsQueriedThenCacheCorrectlyObtainsIt() throws IOException {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    DefaultFileHashCache cache = new DefaultFileHashCache(filesystem, Optional.empty());
    Path abiJarPath = Paths.get("test-abi.jar");
    Path memberPath = Paths.get("SomeClass.class");
    String memberContents = "Some contents";
    try (HashingDeterministicJarWriter jar = new HashingDeterministicJarWriter(new JarOutputStream(filesystem.newFileOutputStream(abiJarPath)))) {
        jar.writeEntry(memberPath.toString(), new ByteArrayInputStream(memberContents.getBytes(StandardCharsets.UTF_8)));
    }
    HashCode actual = cache.get(ArchiveMemberPath.of(abiJarPath, memberPath));
    HashCode expected = Hashing.murmur3_128().hashString(memberContents, StandardCharsets.UTF_8);
    assertEquals(expected, actual);
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) ByteArrayInputStream(java.io.ByteArrayInputStream) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) HashingDeterministicJarWriter(com.facebook.buck.io.HashingDeterministicJarWriter) JarOutputStream(java.util.jar.JarOutputStream) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Aggregations

ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)3 HashingDeterministicJarWriter (com.facebook.buck.io.HashingDeterministicJarWriter)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)3 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Path (java.nio.file.Path)3 JarOutputStream (java.util.jar.JarOutputStream)3 Test (org.junit.Test)3 HashCode (com.google.common.hash.HashCode)1