Search in sources :

Example 6 with ArtifactState

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

the class EmptyLibrary method getUpdatedEmptyJarTracker.

/**
 * Takes the current set of artifacts and artifacts known from previous sync to calculate which of
 * new artifacts are empty. Stores the status of each artifact in {@link EmptyJarTracker}.
 *
 * <p>Artifacts that have changed are fetched and passed to {@link EmptyLibraryFilter} to check if
 * they are empty or not.
 *
 * <p>NOTE: This method does Network IO and File IO, keep an eye on performance
 */
private static EmptyJarTracker getUpdatedEmptyJarTracker(Project project, BlazeContext context, Collection<OutputArtifact> newArtifacts, EmptyJarTracker oldTracker) {
    ImmutableMap<String, ArtifactState> oldState = oldTracker.getState();
    try {
        // Calculate artifacts that have changed or been removed since last sync
        ArtifactsDiff diff = ArtifactsDiff.diffArtifacts(oldState, newArtifacts);
        ImmutableList<OutputArtifact> updated = diff.getUpdatedOutputs();
        ImmutableSet<ArtifactState> removed = diff.getRemovedOutputs();
        // Copy over tracking data from previous sync, and remove entries which are no longer valid.
        EmptyJarTracker.Builder builder = EmptyJarTracker.builder();
        builder.addAllEntries(oldTracker);
        builder.removeEntries(removed);
        // Prefetch updated artifacts
        ListenableFuture<?> future = RemoteArtifactPrefetcher.getInstance().downloadArtifacts(project.getName(), BlazeArtifact.getRemoteArtifacts(updated));
        FutureUtil.waitForFuture(context, future).timed("FetchJarsForEmptyStatusTracking", EventType.Prefetching).withProgressMessage("Fetching JARs to track empty status..").run();
        // Evaluate if the updated artifacts are empty or not
        Map<ArtifactState, Boolean> updatedStatuses = getEmptyStatusInParallel(updated, new EmptyLibraryFilter(), FetchExecutor.EXECUTOR);
        builder.addAllEntries(updatedStatuses);
        if (!updated.isEmpty()) {
            context.output(PrintOutput.log(String.format("[Empty JAR Filter] Calculated empty status of %d JARs", updated.size())));
        }
        if (!removed.isEmpty()) {
            context.output(PrintOutput.log(String.format("[Empty JAR Filter] Removed %d JARs", removed.size())));
        }
        return builder.build();
    } catch (InterruptedException e) {
        String message = "Updating EmptyJarTracker failed.";
        logger.warn(message, e);
        IssueOutput.warn(message).submit(context);
    } catch (ExecutionException e) {
        Thread.currentThread().interrupt();
        context.setCancelled();
    }
    // Something went wrong, return old tracking data
    return oldTracker;
}
Also used : ArtifactsDiff(com.google.idea.blaze.base.filecache.ArtifactsDiff) ArtifactState(com.google.idea.blaze.base.filecache.ArtifactState) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) ExecutionException(java.util.concurrent.ExecutionException)

Example 7 with ArtifactState

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

the class ArtifactMetadata method forArtifact.

/**
 * Returns the relevant metadata for an {@code artifact} that needs to be persisted.
 *
 * @throws ArtifactNotFoundException if the artifact is not present.
 */
public static ArtifactMetadata forArtifact(OutputArtifact artifact) throws ArtifactNotFoundException {
    ArtifactState artifactState = artifact.toArtifactState();
    if (artifactState == null) {
        throw new ArtifactNotFoundException(artifact);
    }
    // Serialize to proto to make grabbing the fields easier
    LocalFileOrOutputArtifact serializedArtifact = artifactState.serializeToProto();
    if (serializedArtifact.hasArtifact()) {
        ProjectData.OutputArtifact o = serializedArtifact.getArtifact();
        return new ArtifactMetadata(o.getRelativePath(), o.getId());
    } else {
        LocalFile o = serializedArtifact.getLocalFile();
        String relativePath = o.getRelativePath().isEmpty() ? o.getPath() : o.getRelativePath();
        return new ArtifactMetadata(relativePath, Long.toString(o.getTimestamp()));
    }
}
Also used : LocalFile(com.google.devtools.intellij.model.ProjectData.LocalFile) ArtifactState(com.google.idea.blaze.base.filecache.ArtifactState) LocalFileOrOutputArtifact(com.google.devtools.intellij.model.ProjectData.LocalFileOrOutputArtifact) ProjectData(com.google.devtools.intellij.model.ProjectData)

Example 8 with ArtifactState

use of com.google.idea.blaze.base.filecache.ArtifactState 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

ArtifactState (com.google.idea.blaze.base.filecache.ArtifactState)8 ImmutableMap (com.google.common.collect.ImmutableMap)4 OutputArtifact (com.google.idea.blaze.base.command.buildresult.OutputArtifact)4 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ExecutionException (java.util.concurrent.ExecutionException)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 ProjectData (com.google.devtools.intellij.model.ProjectData)2 LocalFileOrOutputArtifact (com.google.devtools.intellij.model.ProjectData.LocalFileOrOutputArtifact)2 BlazeArtifact (com.google.idea.blaze.base.command.buildresult.BlazeArtifact)2 ArtifactsDiff (com.google.idea.blaze.base.filecache.ArtifactsDiff)2 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)2 HashSet (java.util.HashSet)2 Nullable (javax.annotation.Nullable)2 AutoValue (com.google.auto.value.AutoValue)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1