Search in sources :

Example 1 with ArtifactStateProtoConverter

use of com.google.idea.blaze.base.filecache.ArtifactStateProtoConverter in project intellij by bazelbuild.

the class JdepsState method fromProto.

private static JdepsState fromProto(ProjectData.JdepsState proto) {
    if (proto.getFileToTargetCount() == 0) {
        return fromNewProto(proto.getTargetToJdeps());
    }
    // migrate from the old proto format
    ImmutableMap<TargetKey, String> targetToArtifactKey = proto.getFileToTargetMap().entrySet().stream().collect(toImmutableMap(e -> TargetKey.fromProto(e.getValue()), Map.Entry::getKey, (a, b) -> a));
    ImmutableMap<String, ArtifactState> artifacts = proto.getJdepsFilesList().stream().map(ArtifactStateProtoConverter::fromProto).filter(Objects::nonNull).collect(toImmutableMap(ArtifactState::getKey, s -> s, (a, b) -> a));
    ImmutableList.Builder<JdepsData> data = ImmutableList.builder();
    for (ProjectData.TargetToJdepsMap.Entry e : proto.getTargetToJdeps().getEntriesList()) {
        TargetKey key = TargetKey.fromProto(e.getKey());
        ImmutableList<String> jdeps = ProtoWrapper.internStrings(e.getValueList());
        String artifactKey = targetToArtifactKey.get(key);
        ArtifactState file = artifactKey != null ? artifacts.get(artifactKey) : null;
        if (file != null) {
            data.add(JdepsData.create(key, jdeps, file));
        }
    }
    return new JdepsState(data.build());
}
Also used : ProjectData(com.google.devtools.intellij.model.ProjectData) ProtoWrapper(com.google.idea.blaze.base.ideinfo.ProtoWrapper) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) Set(java.util.Set) SyncData(com.google.idea.blaze.base.model.SyncData) ArrayList(java.util.ArrayList) Objects(java.util.Objects) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ArtifactState(com.google.idea.blaze.base.filecache.ArtifactState) Map(java.util.Map) AutoValue(com.google.auto.value.AutoValue) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Nullable(javax.annotation.Nullable) ArtifactStateProtoConverter(com.google.idea.blaze.base.filecache.ArtifactStateProtoConverter) ArtifactState(com.google.idea.blaze.base.filecache.ArtifactState) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) ArtifactStateProtoConverter(com.google.idea.blaze.base.filecache.ArtifactStateProtoConverter) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Map(java.util.Map)

Aggregations

AutoValue (com.google.auto.value.AutoValue)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 ProjectData (com.google.devtools.intellij.model.ProjectData)1 ArtifactState (com.google.idea.blaze.base.filecache.ArtifactState)1 ArtifactStateProtoConverter (com.google.idea.blaze.base.filecache.ArtifactStateProtoConverter)1 ProtoWrapper (com.google.idea.blaze.base.ideinfo.ProtoWrapper)1 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)1 SyncData (com.google.idea.blaze.base.model.SyncData)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Nullable (javax.annotation.Nullable)1