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();
}
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);
}
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()));
}
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());
}
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());
}
Aggregations