Search in sources :

Example 71 with ImmutableMap

use of org.apache.beam.vendor.calcite.v1_28_0.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();
    }
}
Also used : CustomZipEntry(com.facebook.buck.zip.CustomZipEntry) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 72 with ImmutableMap

use of org.apache.beam.vendor.calcite.v1_28_0.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;
            }
        }
    }
}
Also used : Optional(java.util.Optional) AutoCloseableLock(com.facebook.buck.util.concurrent.AutoCloseableLock) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 73 with ImmutableMap

use of org.apache.beam.vendor.calcite.v1_28_0.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();
}
Also used : Logger(com.facebook.buck.log.Logger) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BuildTargetException(com.facebook.buck.model.BuildTargetException) AutoCloseableReadWriteUpdateLock(com.facebook.buck.util.concurrent.AutoCloseableReadWriteUpdateLock) HashMap(java.util.HashMap) GuardedBy(javax.annotation.concurrent.GuardedBy) BuildTarget(com.facebook.buck.model.BuildTarget) Maps(com.google.common.collect.Maps) AtomicReference(java.util.concurrent.atomic.AtomicReference) SetMultimap(com.google.common.collect.SetMultimap) ConcurrentMap(java.util.concurrent.ConcurrentMap) MapDifference(com.google.common.collect.MapDifference) AutoCloseableLock(com.facebook.buck.util.concurrent.AutoCloseableLock) HashMultimap(com.google.common.collect.HashMultimap) Map(java.util.Map) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) Cell(com.facebook.buck.rules.Cell) Path(java.nio.file.Path) Optional(java.util.Optional) AutoCloseableLock(com.facebook.buck.util.concurrent.AutoCloseableLock) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 74 with ImmutableMap

use of org.apache.beam.vendor.calcite.v1_28_0.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();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) BuildRule(com.facebook.buck.rules.BuildRule) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 75 with ImmutableMap

use of org.apache.beam.vendor.calcite.v1_28_0.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();
}
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)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1262 Map (java.util.Map)662 Test (org.junit.Test)309 ImmutableList (com.google.common.collect.ImmutableList)300 List (java.util.List)288 HashMap (java.util.HashMap)269 ImmutableSet (com.google.common.collect.ImmutableSet)211 IOException (java.io.IOException)202 Optional (java.util.Optional)190 Set (java.util.Set)168 ArrayList (java.util.ArrayList)158 Path (java.nio.file.Path)151 Collectors (java.util.stream.Collectors)133 File (java.io.File)117 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)102 Collection (java.util.Collection)93 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)85 Test (org.testng.annotations.Test)85 HashSet (java.util.HashSet)83 Collections (java.util.Collections)78