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