use of com.google.idea.blaze.base.model.RemoteOutputArtifacts in project intellij by bazelbuild.
the class UnpackedAars method refresh.
private void refresh(BlazeContext context, ProjectViewSet viewSet, BlazeProjectData projectData, RemoteOutputArtifacts previousOutputs, boolean removeMissingFiles) {
try {
aarCache.getOrCreateCacheDir();
} catch (IOException e) {
logger.warn("Could not create unpacked AAR directory", e);
return;
}
ImmutableMap<String, File> cacheFiles = aarCache.readFileState();
ImmutableMap<String, AarLibraryContents> projectState = getArtifactsToCache(viewSet, projectData);
ImmutableMap<String, BlazeArtifact> aarOutputs = projectState.entrySet().stream().collect(toImmutableMap(Map.Entry::getKey, e -> e.getValue().aar()));
try {
Set<String> updatedKeys = FileCacheDiffer.findUpdatedOutputs(aarOutputs, cacheFiles, previousOutputs).keySet();
Set<BlazeArtifact> artifactsToDownload = new HashSet<>();
for (String key : updatedKeys) {
artifactsToDownload.add(projectState.get(key).aar());
BlazeArtifact jar = projectState.get(key).jar();
// separately. Only update jar when we decide that aar need to be updated.
if (jar != null) {
artifactsToDownload.add(jar);
}
}
// Prefetch all libraries to local before reading and copying content
ListenableFuture<?> downloadArtifactsFuture = RemoteArtifactPrefetcher.getInstance().downloadArtifacts(/* projectName= */
project.getName(), /* outputArtifacts= */
BlazeArtifact.getRemoteArtifacts(artifactsToDownload));
FutureUtil.waitForFuture(context, downloadArtifactsFuture).timed("FetchAars", EventType.Prefetching).withProgressMessage("Fetching aar files...").run();
// manually created directory.
if (removeMissingFiles) {
Collection<ListenableFuture<?>> removedFiles = aarCache.retainOnly(/* retainedFiles= */
projectState.keySet());
Futures.allAsList(removedFiles).get();
if (!removedFiles.isEmpty()) {
context.output(PrintOutput.log(String.format("Removed %d AARs", removedFiles.size())));
}
}
// update cache files
Unpacker.unpack(projectState, updatedKeys, aarCache);
if (!updatedKeys.isEmpty()) {
context.output(PrintOutput.log(String.format("Copied %d AARs", updatedKeys.size())));
}
} catch (InterruptedException e) {
context.setCancelled();
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
logger.warn("Unpacked AAR synchronization didn't complete", e);
} finally {
// update the in-memory record of which files are cached
aarCache.readFileState();
}
}
use of com.google.idea.blaze.base.model.RemoteOutputArtifacts in project intellij by bazelbuild.
the class BlazePyResolverUtils method resolveGenfilesPath.
/**
* Resolves a genfiles-relative path to a locally-accessible file.
*/
private static Optional<File> resolveGenfilesPath(Project project, String relativePath) {
BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
if (projectData == null) {
return Optional.empty();
}
// first look for remote output artifacts
// TODO(brendandouglas): add a common solution handling both remote and local outputs
RemoteOutputArtifacts remotes = RemoteOutputArtifacts.fromProjectData(projectData);
RemoteOutputArtifact artifact = remotes.resolveGenfilesPath(relativePath);
if (artifact == null) {
artifact = remotes.resolveGenfilesPath(relativePath + ".py");
}
if (artifact != null) {
return Optional.ofNullable(OutputArtifactResolver.resolve(project, artifact));
}
return Optional.of(new File(projectData.getBlazeInfo().getGenfilesDirectory(), relativePath));
}
use of com.google.idea.blaze.base.model.RemoteOutputArtifacts in project intellij by bazelbuild.
the class ProjectUpdateSyncTask method run.
private void run(BlazeContext context) throws SyncCanceledException, SyncFailedException {
TargetMap targetMap = targetData.targetMap;
RemoteOutputArtifacts oldRemoteState = RemoteOutputArtifacts.fromProjectData(oldProjectData);
RemoteOutputArtifacts newRemoteState = targetData.remoteOutputs;
ArtifactLocationDecoder artifactLocationDecoder = new ArtifactLocationDecoderImpl(projectState.getBlazeInfo(), projectState.getWorkspacePathResolver(), newRemoteState);
Scope.push(context, childContext -> {
childContext.push(new TimingScope("UpdateRemoteOutputsCache", EventType.Prefetching));
RemoteOutputsCache.getInstance(project).updateCache(context, targetMap, projectState.getLanguageSettings(), newRemoteState, oldRemoteState, /* clearCache= */
syncMode == SyncMode.FULL);
});
SyncState.Builder syncStateBuilder = new SyncState.Builder();
Scope.push(context, childContext -> {
childContext.push(new TimingScope("UpdateSyncState", EventType.Other));
for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
syncPlugin.updateSyncState(project, childContext, workspaceRoot, projectState.getProjectViewSet(), projectState.getLanguageSettings(), projectState.getBlazeVersionData(), projectState.getWorkingSet(), artifactLocationDecoder, targetMap, syncStateBuilder, oldProjectData != null ? oldProjectData.getSyncState() : null, syncMode);
}
});
if (context.isCancelled()) {
throw new SyncCanceledException();
}
if (context.hasErrors()) {
throw new SyncFailedException();
}
BlazeProjectData newProjectData = new BlazeProjectData(targetData, projectState.getBlazeInfo(), projectState.getBlazeVersionData(), projectState.getWorkspacePathResolver(), artifactLocationDecoder, projectState.getLanguageSettings(), syncStateBuilder.build());
FileCaches.onSync(project, context, projectState.getProjectViewSet(), newProjectData, oldProjectData, syncMode);
ListenableFuture<?> prefetch = PrefetchService.getInstance().prefetchProjectFiles(project, projectState.getProjectViewSet(), newProjectData);
FutureUtil.waitForFuture(context, prefetch).withProgressMessage("Prefetching files...").timed("PrefetchFiles", EventType.Prefetching).onError("Prefetch failed").run();
ListenableFuture<DirectoryStructure> directoryStructureFuture = DirectoryStructure.getRootDirectoryStructure(project, workspaceRoot, projectState.getProjectViewSet());
refreshVirtualFileSystem(context, project, newProjectData);
DirectoryStructure directoryStructure = FutureUtil.waitForFuture(context, directoryStructureFuture).withProgressMessage("Computing directory structure...").timed("DirectoryStructure", EventType.Other).onError("Directory structure computation failed").run().result();
if (directoryStructure == null) {
throw new SyncFailedException();
}
boolean success = updateProject(context, projectState.getProjectViewSet(), projectState.getBlazeVersionData(), directoryStructure, oldProjectData, newProjectData);
if (!success) {
throw new SyncFailedException();
}
}
use of com.google.idea.blaze.base.model.RemoteOutputArtifacts in project intellij by bazelbuild.
the class BlazeIdeInterfaceAspectsImpl method updateTargetData.
@Override
@Nullable
public ProjectTargetData updateTargetData(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, SyncProjectState projectState, BlazeBuildOutputs buildResult, boolean mergeWithOldState, @Nullable BlazeProjectData oldProjectData) {
TargetMapAndInterfaceState state = updateTargetMap(project, context, workspaceRoot, projectState, buildResult, mergeWithOldState, oldProjectData);
if (state == null) {
return null;
}
context.output(PrintOutput.log("Target map size: " + state.targetMap.targets().size()));
RemoteOutputArtifacts oldRemoteOutputs = RemoteOutputArtifacts.fromProjectData(oldProjectData);
// combine outputs map, then filter to remove out-of-date / unnecessary items
RemoteOutputArtifacts newRemoteOutputs = oldRemoteOutputs.appendNewOutputs(getTrackedOutputs(buildResult)).removeUntrackedOutputs(state.targetMap, projectState.getLanguageSettings());
return new ProjectTargetData(state.targetMap, state.state, newRemoteOutputs);
}
Aggregations