Search in sources :

Example 1 with RemoteOutputArtifacts

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();
    }
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) FileCacheDiffer(com.google.idea.blaze.base.filecache.FileCacheDiffer) HashMap(java.util.HashMap) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) HashSet(java.util.HashSet) FileCache(com.google.idea.blaze.base.filecache.FileCache) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeDataStorage(com.google.idea.blaze.base.sync.data.BlazeDataStorage) Map(java.util.Map) AarLibrary(com.google.idea.blaze.android.sync.model.AarLibrary) Project(com.intellij.openapi.project.Project) BlazeBuildOutputs(com.google.idea.blaze.base.sync.aspects.BlazeBuildOutputs) Logger(com.intellij.openapi.diagnostic.Logger) Nullable(javax.annotation.Nullable) RemoteOutputArtifacts(com.google.idea.blaze.base.model.RemoteOutputArtifacts) ImmutableMap(com.google.common.collect.ImmutableMap) BlazeLibraryCollector(com.google.idea.blaze.base.sync.libraries.BlazeLibraryCollector) Collection(java.util.Collection) FutureUtil(com.google.idea.blaze.base.async.FutureUtil) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) Set(java.util.Set) IOException(java.io.IOException) RemoteArtifactPrefetcher(com.google.idea.blaze.base.prefetch.RemoteArtifactPrefetcher) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Collectors(java.util.stream.Collectors) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) ExecutionException(java.util.concurrent.ExecutionException) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) RemoteOutputArtifact(com.google.idea.blaze.base.command.buildresult.RemoteOutputArtifact) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) SyncMode(com.google.idea.blaze.base.sync.SyncMode) LocalFileArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) IOException(java.io.IOException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) HashSet(java.util.HashSet)

Example 2 with RemoteOutputArtifacts

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));
}
Also used : RemoteOutputArtifact(com.google.idea.blaze.base.command.buildresult.RemoteOutputArtifact) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) RemoteOutputArtifacts(com.google.idea.blaze.base.model.RemoteOutputArtifacts) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 3 with RemoteOutputArtifacts

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();
    }
}
Also used : RemoteOutputArtifacts(com.google.idea.blaze.base.model.RemoteOutputArtifacts) SyncFailedException(com.google.idea.blaze.base.sync.SyncScope.SyncFailedException) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) SyncState(com.google.idea.blaze.base.model.SyncState) SyncCanceledException(com.google.idea.blaze.base.sync.SyncScope.SyncCanceledException) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) ArtifactLocationDecoderImpl(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoderImpl) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) DirectoryStructure(com.google.idea.blaze.base.sync.projectstructure.DirectoryStructure)

Example 4 with RemoteOutputArtifacts

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);
}
Also used : ProjectTargetData(com.google.idea.blaze.base.model.ProjectTargetData) RemoteOutputArtifacts(com.google.idea.blaze.base.model.RemoteOutputArtifacts) Nullable(javax.annotation.Nullable)

Aggregations

RemoteOutputArtifacts (com.google.idea.blaze.base.model.RemoteOutputArtifacts)4 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)3 RemoteOutputArtifact (com.google.idea.blaze.base.command.buildresult.RemoteOutputArtifact)2 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)2 File (java.io.File)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 AarLibrary (com.google.idea.blaze.android.sync.model.AarLibrary)1 FutureUtil (com.google.idea.blaze.base.async.FutureUtil)1 BlazeArtifact (com.google.idea.blaze.base.command.buildresult.BlazeArtifact)1 LocalFileArtifact (com.google.idea.blaze.base.command.buildresult.BlazeArtifact.LocalFileArtifact)1 FileCache (com.google.idea.blaze.base.filecache.FileCache)1 FileCacheDiffer (com.google.idea.blaze.base.filecache.FileCacheDiffer)1 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)1 BlazeLibrary (com.google.idea.blaze.base.model.BlazeLibrary)1 ProjectTargetData (com.google.idea.blaze.base.model.ProjectTargetData)1 SyncState (com.google.idea.blaze.base.model.SyncState)1