Search in sources :

Example 16 with HashCode

use of com.google.common.hash.HashCode in project buck by facebook.

the class JarContentHasher method getContentHashes.

public ImmutableMap<Path, HashCodeAndFileType> getContentHashes() throws IOException {
    Manifest manifest = filesystem.getJarManifest(jarRelativePath);
    if (manifest == null) {
        throw new UnsupportedOperationException("Cache does not know how to return hash codes for archive members except " + "when the archive contains a META-INF/MANIFEST.MF with " + HashingDeterministicJarWriter.DIGEST_ATTRIBUTE_NAME + " attributes for each file.");
    }
    ImmutableMap.Builder<Path, HashCodeAndFileType> builder = ImmutableMap.builder();
    for (Map.Entry<String, Attributes> nameAttributesEntry : manifest.getEntries().entrySet()) {
        Path memberPath = Paths.get(nameAttributesEntry.getKey());
        Attributes attributes = nameAttributesEntry.getValue();
        String hashStringValue = attributes.getValue(HashingDeterministicJarWriter.DIGEST_ATTRIBUTE_NAME);
        if (hashStringValue == null) {
            continue;
        }
        HashCode memberHash = HashCode.fromString(hashStringValue);
        HashCodeAndFileType memberHashCodeAndFileType = HashCodeAndFileType.ofFile(memberHash);
        builder.put(memberPath, memberHashCodeAndFileType);
    }
    return builder.build();
}
Also used : Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 17 with HashCode

use of com.google.common.hash.HashCode in project buck by facebook.

the class EdenMountTest method getSha1DelegatesToThriftClient.

@Test
public void getSha1DelegatesToThriftClient() throws EdenError, TException {
    List<MountInfo> mountInfos = ImmutableList.of(new MountInfo("/home/mbolin/src/buck", /* edenClientPath */
    ""));
    EdenService.Client thriftClient = createMock(EdenService.Client.class);
    expect(thriftClient.listMounts()).andReturn(mountInfos);
    FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
    Path entry = fs.getPath("LICENSE");
    HashCode hash = HashCode.fromString("2b8b815229aa8a61e483fb4ba0588b8b6c491890");
    SHA1Result sha1Result = new SHA1Result();
    sha1Result.setSha1(hash.asBytes());
    expect(thriftClient.getSHA1("/home/mbolin/src/buck", ImmutableList.of("LICENSE"))).andReturn(ImmutableList.of(sha1Result));
    replay(thriftClient);
    EdenClient client = new EdenClient(thriftClient);
    Path pathToBuck = fs.getPath("/home/mbolin/src/buck");
    EdenMount mount = client.getMountFor(pathToBuck);
    assertNotNull("Should find mount for path.", mount);
    assertEquals(Sha1HashCode.fromHashCode(hash), mount.getSha1(entry));
    verify(thriftClient);
}
Also used : Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) Sha1HashCode(com.facebook.buck.util.sha1.Sha1HashCode) FileSystem(java.nio.file.FileSystem) MountInfo(com.facebook.eden.thrift.MountInfo) EdenService(com.facebook.eden.thrift.EdenService) SHA1Result(com.facebook.eden.thrift.SHA1Result) Test(org.junit.Test)

Example 18 with HashCode

use of com.google.common.hash.HashCode in project buck by facebook.

the class RemoteFileTest method shouldNotMakeDownloadedFileExecutableWhenTypeIsData.

@Test
public void shouldNotMakeDownloadedFileExecutableWhenTypeIsData() throws Exception {
    assumeThat(Platform.detect(), is(not(WINDOWS)));
    String value = "I like cake";
    HashCode hashCode = Hashing.sha1().hashBytes(value.getBytes(UTF_8));
    Path output = runTheMagic(null, value, hashCode, RemoteFile.Type.DATA);
    assertThat(output, exists());
    assertThat(output, not(isExecutable()));
}
Also used : Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) Test(org.junit.Test)

Example 19 with HashCode

use of com.google.common.hash.HashCode in project buck by facebook.

the class RemoteFileTest method shouldSaveToFinalLocationAfterSha1IsVerified.

@Test
public void shouldSaveToFinalLocationAfterSha1IsVerified() throws Exception {
    String value = "I like cake";
    HashCode hashCode = Hashing.sha1().hashBytes(value.getBytes(UTF_8));
    Path output = runTheMagic(null, value, hashCode);
    assertThat(output, exists());
}
Also used : Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) Test(org.junit.Test)

Example 20 with HashCode

use of com.google.common.hash.HashCode in project buck by facebook.

the class RemoteFileTest method shouldMakeDownloadedFileExecutableIfRequested.

@Test
public void shouldMakeDownloadedFileExecutableIfRequested() throws Exception {
    assumeThat(Platform.detect(), is(not(WINDOWS)));
    String value = "I like cake";
    HashCode hashCode = Hashing.sha1().hashBytes(value.getBytes(UTF_8));
    Path output = runTheMagic(null, value, hashCode, RemoteFile.Type.EXECUTABLE);
    assertThat(output, exists());
    assertThat(output, isExecutable());
}
Also used : Path(java.nio.file.Path) HashCode(com.google.common.hash.HashCode) Test(org.junit.Test)

Aggregations

HashCode (com.google.common.hash.HashCode)120 Path (java.nio.file.Path)40 Test (org.junit.Test)39 BuildTarget (com.facebook.buck.model.BuildTarget)19 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)13 IOException (java.io.IOException)13 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)12 PathSourcePath (com.facebook.buck.rules.PathSourcePath)11 FileHashCache (com.facebook.buck.util.cache.FileHashCache)11 ImmutableMap (com.google.common.collect.ImmutableMap)11 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)10 Sha1HashCode (com.facebook.buck.util.sha1.Sha1HashCode)10 Hasher (com.google.common.hash.Hasher)9 Map (java.util.Map)9 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)7 SourcePath (com.facebook.buck.rules.SourcePath)7 File (java.io.File)7 BuckEventBus (com.facebook.buck.event.BuckEventBus)6 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)6 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5