use of com.google.common.collect.ImmutableMap in project buck by facebook.
the class DefaultDefectReporter method addStringsAsFilesToArchive.
private void addStringsAsFilesToArchive(CustomZipOutputStream out, ImmutableMap<String, String> files) throws IOException {
for (Map.Entry<String, String> file : files.entrySet()) {
out.putNextEntry(new CustomZipEntry(file.getKey()));
out.write(file.getValue().getBytes(Charsets.UTF_8));
out.closeEntry();
}
}
use of com.google.common.collect.ImmutableMap in project buck by facebook.
the class DaemonicCellState method invalidateIfBuckConfigHasChanged.
void invalidateIfBuckConfigHasChanged(Cell cell, Path buildFile) {
// TODO(mzlee): Check whether usedConfigs includes the buildFileName
ImmutableMap<String, ImmutableMap<String, Optional<String>>> usedConfigs;
try (AutoCloseableLock readLock = rawAndComputedNodesLock.readLock()) {
usedConfigs = buildFileConfigs.get(buildFile);
}
if (usedConfigs == null) {
// TODO(mzlee): Figure out when/how we can safely update this
this.cell.set(cell);
return;
}
for (Map.Entry<String, ImmutableMap<String, Optional<String>>> keyEnt : usedConfigs.entrySet()) {
for (Map.Entry<String, Optional<String>> valueEnt : keyEnt.getValue().entrySet()) {
Optional<String> value = cell.getBuckConfig().getValue(keyEnt.getKey(), valueEnt.getKey());
if (!value.equals(valueEnt.getValue())) {
invalidatePath(buildFile);
this.cell.set(cell);
return;
}
}
}
}
use of com.google.common.collect.ImmutableMap in project buck by facebook.
the class DaemonicCellState method invalidateIfEnvHasChanged.
Optional<MapDifference<String, String>> invalidateIfEnvHasChanged(Cell cell, Path buildFile) {
// Invalidate if env vars have changed.
ImmutableMap<String, Optional<String>> usedEnv;
try (AutoCloseableLock readLock = rawAndComputedNodesLock.readLock()) {
usedEnv = buildFileEnv.get(buildFile);
}
if (usedEnv == null) {
this.cell.set(cell);
return Optional.empty();
}
for (Map.Entry<String, Optional<String>> ent : usedEnv.entrySet()) {
Optional<String> value = Optional.ofNullable(cell.getBuckConfig().getEnvironment().get(ent.getKey()));
if (!value.equals(ent.getValue())) {
invalidatePath(buildFile);
this.cell.set(cell);
return Optional.of(Maps.difference(value.map(v -> ImmutableMap.of(ent.getKey(), v)).orElse(ImmutableMap.of()), ent.getValue().map(v -> ImmutableMap.of(ent.getKey(), v)).orElse(ImmutableMap.of())));
}
}
return Optional.empty();
}
use of com.google.common.collect.ImmutableMap in project buck by facebook.
the class SwiftLibrary method getSharedLibraries.
@Override
public ImmutableMap<String, SourcePath> getSharedLibraries(CxxPlatform cxxPlatform) throws NoSuchBuildTargetException {
if (!isPlatformSupported(cxxPlatform)) {
return ImmutableMap.of();
}
ImmutableMap.Builder<String, SourcePath> libs = ImmutableMap.builder();
BuildRule sharedLibraryBuildRule = requireSwiftLinkRule(cxxPlatform.getFlavor());
String sharedLibrarySoname = CxxDescriptionEnhancer.getSharedLibrarySoname(Optional.empty(), sharedLibraryBuildRule.getBuildTarget(), cxxPlatform);
libs.put(sharedLibrarySoname, sharedLibraryBuildRule.getSourcePathToOutput());
return libs.build();
}
use of com.google.common.collect.ImmutableMap 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();
}
Aggregations