Search in sources :

Example 56 with ProjectViewSet

use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.

the class BlazeScalaWorkspaceImporterTest method importJava.

private BlazeJavaImportResult importJava(ProjectView projectView, TargetMap targetMap) {
    ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
    WorkspaceLanguageSettings languageSettings = new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of(LanguageClass.GENERIC, LanguageClass.SCALA, LanguageClass.JAVA));
    JavaSourceFilter sourceFilter = new JavaSourceFilter(project, workspaceRoot, projectViewSet, targetMap);
    JdepsMap jdepsMap = key -> ImmutableList.of();
    ArtifactLocationDecoder decoder = location -> new File(location.getRelativePath());
    return new BlazeJavaWorkspaceImporter(project, workspaceRoot, projectViewSet, languageSettings, targetMap, sourceFilter, jdepsMap, null, decoder).importWorkspace(context);
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) LibraryKey(com.google.idea.blaze.base.model.LibraryKey) PrefetchService(com.google.idea.blaze.base.prefetch.PrefetchService) Map(java.util.Map) JavaLikeLanguage(com.google.idea.blaze.java.sync.source.JavaLikeLanguage) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) ImmutableSet(com.google.common.collect.ImmutableSet) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) SourceArtifact(com.google.idea.blaze.java.sync.source.SourceArtifact) ErrorCollector(com.google.idea.blaze.base.scope.ErrorCollector) BlazeSourceDirectory(com.google.idea.blaze.java.sync.model.BlazeSourceDirectory) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ScalaJavaLikeLanguage(com.google.idea.blaze.scala.sync.source.ScalaJavaLikeLanguage) NotNull(org.jetbrains.annotations.NotNull) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) JavaSourcePackageReader(com.google.idea.blaze.java.sync.source.JavaSourcePackageReader) PackageManifestReader(com.google.idea.blaze.java.sync.source.PackageManifestReader) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) RunWith(org.junit.runner.RunWith) BlazeJavaWorkspaceImporter(com.google.idea.blaze.java.sync.importer.BlazeJavaWorkspaceImporter) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) ImmutableList(com.google.common.collect.ImmutableList) BuildSystem(com.google.idea.blaze.base.settings.Blaze.BuildSystem) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Nullable(javax.annotation.Nullable) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ExtensionPoint(com.intellij.openapi.extensions.ExtensionPoint) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) MockPrefetchService(com.google.idea.blaze.base.prefetch.MockPrefetchService) BlazeJavaSyncAugmenter(com.google.idea.blaze.java.sync.BlazeJavaSyncAugmenter) BlazeScalaImportResult(com.google.idea.blaze.scala.sync.model.BlazeScalaImportResult) File(java.io.File) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) JdepsMap(com.google.idea.blaze.java.sync.jdeps.JdepsMap) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) JdepsMap(com.google.idea.blaze.java.sync.jdeps.JdepsMap) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) BlazeJavaWorkspaceImporter(com.google.idea.blaze.java.sync.importer.BlazeJavaWorkspaceImporter) File(java.io.File)

Example 57 with ProjectViewSet

use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.

the class NewBlazePackageAction method filterDirectories.

/**
 * Filter out directories that do not live under the project's directories.
 */
private static List<PsiDirectory> filterDirectories(Project project, PsiDirectory[] directories) {
    if (directories.length == 0) {
        return ImmutableList.of();
    }
    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
    if (projectViewSet == null) {
        return ImmutableList.of();
    }
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    ImportRoots importRoots = ImportRoots.builder(workspaceRoot, Blaze.getBuildSystem(project)).add(projectViewSet).build();
    return Lists.newArrayList(directories).stream().filter(directory -> isUnderProjectViewDirectory(workspaceRoot, importRoots, directory)).collect(Collectors.toList());
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) LocalHistoryAction(com.intellij.history.LocalHistoryAction) Presentation(com.intellij.openapi.actionSystem.Presentation) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) PsiManager(com.intellij.psi.PsiManager) BlazeProjectAction(com.google.idea.blaze.base.actions.BlazeProjectAction) BuildFileModifier(com.google.idea.blaze.base.buildmodifier.BuildFileModifier) Kind(com.google.idea.blaze.base.model.primitives.Kind) IdeView(com.intellij.ide.IdeView) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Scope(com.google.idea.blaze.base.scope.Scope) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Logger(com.intellij.openapi.diagnostic.Logger) DumbAware(com.intellij.openapi.project.DumbAware) Nullable(javax.annotation.Nullable) Blaze(com.google.idea.blaze.base.settings.Blaze) PlatformIcons(com.intellij.util.PlatformIcons) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) WorkspacePathUtil(com.google.idea.blaze.base.util.WorkspacePathUtil) IOException(java.io.IOException) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Collectors(java.util.stream.Collectors) File(java.io.File) DirectoryChooserUtil(com.intellij.ide.util.DirectoryChooserUtil) List(java.util.List) Label(com.google.idea.blaze.base.model.primitives.Label) Result(com.intellij.openapi.application.Result) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Optional(java.util.Optional) VfsUtil(com.intellij.openapi.vfs.VfsUtil) PsiDirectory(com.intellij.psi.PsiDirectory) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) LocalHistory(com.intellij.history.LocalHistory) LangDataKeys(com.intellij.openapi.actionSystem.LangDataKeys) NotNull(org.jetbrains.annotations.NotNull) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot)

Example 58 with ProjectViewSet

use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.

the class BlazeIssueParser method defaultIssueParsers.

public static ImmutableList<BlazeIssueParser.Parser> defaultIssueParsers(Project project, WorkspaceRoot workspaceRoot, BlazeInvocationContext invocationContext) {
    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
    if (projectViewSet == null) {
        // project view available
        return ImmutableList.of();
    }
    ImmutableList.Builder<BlazeIssueParser.Parser> parsers = ImmutableList.<BlazeIssueParser.Parser>builder().add(new BlazeIssueParser.CompileParser(workspaceRoot), new BlazeIssueParser.TracebackParser(), new BlazeIssueParser.BuildParser(), new BlazeIssueParser.SkylarkErrorParser(), new BlazeIssueParser.LinelessBuildParser(), new BlazeIssueParser.ProjectViewLabelParser(projectViewSet), new BlazeIssueParser.InvalidTargetProjectViewPackageParser(projectViewSet, "no such package '(.*)': BUILD file not found on package path"), new BlazeIssueParser.InvalidTargetProjectViewPackageParser(projectViewSet, "no targets found beneath '(.*?)'"), new BlazeIssueParser.InvalidTargetProjectViewPackageParser(projectViewSet, "ERROR: invalid target format '(.*?)'"), new BlazeIssueParser.InvalidTargetProjectViewPackageParser(projectViewSet, "ERROR: Skipping '(.*?)'"), new BlazeIssueParser.FileNotFoundBuildParser(workspaceRoot)).addAll(BlazeIssueParserProvider.getAllIssueParsers(project));
    if (invocationContext == BlazeInvocationContext.Sync) {
        parsers.add(BlazeIssueParser.GenericErrorParser.INSTANCE);
    }
    return parsers.build();
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) ImmutableList(com.google.common.collect.ImmutableList)

Example 59 with ProjectViewSet

use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.

the class BlazeSyncTask method doSyncProject.

/**
 * @return true if sync successfully completed
 */
private SyncResult doSyncProject(BlazeContext context, @Nullable BlazeProjectData oldBlazeProjectData) {
    long syncStartTime = System.currentTimeMillis();
    if (!FileOperationProvider.getInstance().exists(workspaceRoot.directory())) {
        IssueOutput.error(String.format("Workspace '%s' doesn't exist.", workspaceRoot.directory())).submit(context);
        return SyncResult.FAILURE;
    }
    BlazeVcsHandler vcsHandler = BlazeVcsHandler.vcsHandlerForProject(project);
    if (vcsHandler == null) {
        IssueOutput.error("Could not find a VCS handler").submit(context);
        return SyncResult.FAILURE;
    }
    ListeningExecutorService executor = BlazeExecutor.getInstance().getExecutor();
    WorkspacePathResolverAndProjectView workspacePathResolverAndProjectView = computeWorkspacePathResolverAndProjectView(context, vcsHandler, executor);
    if (workspacePathResolverAndProjectView == null) {
        return SyncResult.FAILURE;
    }
    ProjectViewSet projectViewSet = workspacePathResolverAndProjectView.projectViewSet;
    List<String> syncFlags = BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.INFO, BlazeInvocationContext.Sync);
    syncStats.setSyncFlags(syncFlags);
    ListenableFuture<BlazeInfo> blazeInfoFuture = BlazeInfoRunner.getInstance().runBlazeInfo(context, importSettings.getBuildSystem(), Blaze.getBuildSystemProvider(project).getSyncBinaryPath(), workspaceRoot, syncFlags);
    ListenableFuture<WorkingSet> workingSetFuture = vcsHandler.getWorkingSet(project, context, workspaceRoot, executor);
    BlazeInfo blazeInfo = FutureUtil.waitForFuture(context, blazeInfoFuture).timed(Blaze.buildSystemName(project) + "Info", EventType.BlazeInvocation).withProgressMessage(String.format("Running %s info...", Blaze.buildSystemName(project))).onError(String.format("Could not run %s info", Blaze.buildSystemName(project))).run().result();
    if (blazeInfo == null) {
        return SyncResult.FAILURE;
    }
    BlazeVersionData blazeVersionData = BlazeVersionData.build(importSettings.getBuildSystem(), workspaceRoot, blazeInfo);
    if (!BuildSystemVersionChecker.verifyVersionSupported(context, blazeVersionData)) {
        return SyncResult.FAILURE;
    }
    WorkspacePathResolver workspacePathResolver = workspacePathResolverAndProjectView.workspacePathResolver;
    ArtifactLocationDecoder artifactLocationDecoder = new ArtifactLocationDecoderImpl(blazeInfo, workspacePathResolver);
    WorkspaceLanguageSettings workspaceLanguageSettings = LanguageSupport.createWorkspaceLanguageSettings(projectViewSet);
    syncStats.setLanguagesActive(new ArrayList<>(workspaceLanguageSettings.activeLanguages));
    syncStats.setWorkspaceType(workspaceLanguageSettings.getWorkspaceType());
    for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
        syncPlugin.installSdks(context);
    }
    if (!ProjectViewVerifier.verifyProjectView(project, context, workspacePathResolver, projectViewSet, workspaceLanguageSettings)) {
        return SyncResult.FAILURE;
    }
    final BlazeProjectData newBlazeProjectData;
    WorkingSet workingSet = FutureUtil.waitForFuture(context, workingSetFuture).timed("WorkingSet", EventType.Other).withProgressMessage("Computing VCS working set...").onError("Could not compute working set").run().result();
    if (context.isCancelled()) {
        return SyncResult.CANCELLED;
    }
    if (context.hasErrors()) {
        return SyncResult.FAILURE;
    }
    if (workingSet != null) {
        printWorkingSet(context, workingSet);
    }
    SyncState.Builder syncStateBuilder = new SyncState.Builder();
    SyncState previousSyncState = oldBlazeProjectData != null ? oldBlazeProjectData.syncState : null;
    List<TargetExpression> targets = Lists.newArrayList();
    if (syncParams.addProjectViewTargets) {
        Collection<TargetExpression> projectViewTargets = projectViewSet.listItems(TargetSection.KEY);
        if (!projectViewTargets.isEmpty()) {
            syncStats.setBlazeProjectTargets(new ArrayList<>(projectViewTargets));
            targets.addAll(projectViewTargets);
            printTargets(context, "project view", projectViewTargets);
        }
    }
    if (syncParams.addWorkingSet && workingSet != null) {
        Collection<? extends TargetExpression> workingSetTargets = getWorkingSetTargets(projectViewSet, workingSet);
        if (!workingSetTargets.isEmpty()) {
            targets.addAll(workingSetTargets);
            syncStats.setWorkingSetTargets(new ArrayList<>(workingSetTargets));
            printTargets(context, "working set", workingSetTargets);
        }
    }
    if (!syncParams.targetExpressions.isEmpty()) {
        targets.addAll(syncParams.targetExpressions);
        printTargets(context, syncParams.title, syncParams.targetExpressions);
    }
    ShardedTargetsResult shardedTargetsResult = BlazeBuildTargetSharder.expandAndShardTargets(project, context, workspaceRoot, projectViewSet, workspacePathResolver, targets);
    if (shardedTargetsResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
        return SyncResult.FAILURE;
    }
    ShardedTargetList shardedTargets = shardedTargetsResult.shardedTargets;
    syncStats.setSyncSharded(shardedTargets.shardedTargets.size() > 1);
    BlazeConfigurationHandler configHandler = new BlazeConfigurationHandler(blazeInfo);
    boolean mergeWithOldState = !syncParams.addProjectViewTargets;
    BlazeIdeInterface.IdeResult ideQueryResult = getIdeQueryResult(project, context, projectViewSet, blazeVersionData, configHandler, shardedTargets, workspaceLanguageSettings, artifactLocationDecoder, syncStateBuilder, previousSyncState, mergeWithOldState);
    if (context.isCancelled()) {
        return SyncResult.CANCELLED;
    }
    context.output(PrintOutput.log("ide-query result: " + ideQueryResult.buildResult.status));
    if (ideQueryResult.targetMap == null || ideQueryResult.buildResult.status == BuildResult.Status.FATAL_ERROR) {
        context.setHasError();
        if (ideQueryResult.buildResult.outOfMemory()) {
            SuggestBuildShardingNotification.syncOutOfMemoryError(project, context);
        }
        return SyncResult.FAILURE;
    }
    TargetMap targetMap = ideQueryResult.targetMap;
    context.output(PrintOutput.log("Target map size: " + ideQueryResult.targetMap.targets().size()));
    BuildResult ideInfoResult = ideQueryResult.buildResult;
    ListenableFuture<ImmutableMultimap<TargetKey, TargetKey>> reverseDependenciesFuture = BlazeExecutor.getInstance().submit(() -> ReverseDependencyMap.createRdepsMap(targetMap));
    BuildResult ideResolveResult = resolveIdeArtifacts(project, context, workspaceRoot, projectViewSet, blazeVersionData, workspaceLanguageSettings, shardedTargets);
    if (ideResolveResult.status == BuildResult.Status.FATAL_ERROR) {
        context.setHasError();
        if (ideResolveResult.outOfMemory()) {
            SuggestBuildShardingNotification.syncOutOfMemoryError(project, context);
        }
        return SyncResult.FAILURE;
    }
    if (context.isCancelled()) {
        return SyncResult.CANCELLED;
    }
    Scope.push(context, (childContext) -> {
        childContext.push(new TimingScope("UpdateSyncState", EventType.Other));
        for (BlazeSyncPlugin syncPlugin : BlazeSyncPlugin.EP_NAME.getExtensions()) {
            syncPlugin.updateSyncState(project, childContext, workspaceRoot, projectViewSet, workspaceLanguageSettings, blazeInfo, workingSet, workspacePathResolver, artifactLocationDecoder, targetMap, syncStateBuilder, previousSyncState);
        }
    });
    ImmutableMultimap<TargetKey, TargetKey> reverseDependencies = FutureUtil.waitForFuture(context, reverseDependenciesFuture).timed("ReverseDependencies", EventType.Other).onError("Failed to compute reverse dependency map").run().result();
    if (reverseDependencies == null) {
        return SyncResult.FAILURE;
    }
    newBlazeProjectData = new BlazeProjectData(syncStartTime, targetMap, blazeInfo, blazeVersionData, workspacePathResolver, artifactLocationDecoder, workspaceLanguageSettings, syncStateBuilder.build(), reverseDependencies);
    FileCaches.onSync(project, context, projectViewSet, newBlazeProjectData, syncParams.syncMode);
    ListenableFuture<?> prefetch = PrefetchService.getInstance().prefetchProjectFiles(project, projectViewSet, newBlazeProjectData);
    FutureUtil.waitForFuture(context, prefetch).withProgressMessage("Prefetching files...").timed("PrefetchFiles", EventType.Prefetching).onError("Prefetch failed").run();
    ListenableFuture<DirectoryStructure> directoryStructureFuture = DirectoryStructure.getRootDirectoryStructure(project, workspaceRoot, projectViewSet);
    refreshVirtualFileSystem(context, newBlazeProjectData);
    DirectoryStructure directoryStructure = FutureUtil.waitForFuture(context, directoryStructureFuture).withProgressMessage("Computing directory structure...").timed("DirectoryStructure", EventType.Other).onError("Directory structure computation failed").run().result();
    if (directoryStructure == null) {
        return SyncResult.FAILURE;
    }
    boolean success = updateProject(context, projectViewSet, blazeVersionData, directoryStructure, oldBlazeProjectData, newBlazeProjectData);
    if (!success) {
        return SyncResult.FAILURE;
    }
    SyncResult syncResult = SyncResult.SUCCESS;
    if (ideInfoResult.status == BuildResult.Status.BUILD_ERROR || ideResolveResult.status == BuildResult.Status.BUILD_ERROR) {
        final String errorType = ideInfoResult.status == BuildResult.Status.BUILD_ERROR ? "BUILD file errors" : "compilation errors";
        String message = String.format("Sync was successful, but there were %s. " + "The project may not be fully updated or resolve until fixed. " + "If the errors are from your working set, please uncheck " + "'Blaze > Sync > Expand Sync to Working Set' and try again.", errorType);
        context.output(PrintOutput.error(message));
        IssueOutput.warn(message).submit(context);
        syncResult = SyncResult.PARTIAL_SUCCESS;
    }
    return syncResult;
}
Also used : ShardedTargetsResult(com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder.ShardedTargetsResult) Builder(com.google.idea.blaze.base.model.SyncState.Builder) BlazeIdeInterface(com.google.idea.blaze.base.sync.aspects.BlazeIdeInterface) Builder(com.google.idea.blaze.base.model.SyncState.Builder) BlazeVersionData(com.google.idea.blaze.base.model.BlazeVersionData) BlazeConfigurationHandler(com.google.idea.blaze.base.command.info.BlazeConfigurationHandler) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) SyncState(com.google.idea.blaze.base.model.SyncState) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) ArtifactLocationDecoderImpl(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoderImpl) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) WorkingSet(com.google.idea.blaze.base.sync.workspace.WorkingSet) SyncResult(com.google.idea.blaze.base.sync.SyncListener.SyncResult) DirectoryStructure(com.google.idea.blaze.base.sync.projectstructure.DirectoryStructure) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) ShardedTargetList(com.google.idea.blaze.base.sync.sharding.ShardedTargetList) BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeVcsHandler(com.google.idea.blaze.base.vcs.BlazeVcsHandler)

Example 60 with ProjectViewSet

use of com.google.idea.blaze.base.projectview.ProjectViewSet in project intellij by bazelbuild.

the class BlazeSyncTask method syncProject.

/**
 * Returns true if sync successfully completed
 */
@VisibleForTesting
boolean syncProject(BlazeContext context) {
    TimingScope timingScope = new TimingScope("Sync", EventType.Other);
    timingScope.addScopeListener(timingScopeListener, true);
    context.push(timingScope);
    long syncStartTime = System.currentTimeMillis();
    SyncResult syncResult = SyncResult.FAILURE;
    syncStats.setStartTimeInEpochTime(System.currentTimeMillis());
    try {
        SaveUtil.saveAllFiles();
        BlazeProjectData oldBlazeProjectData = syncParams.syncMode != SyncMode.FULL ? getOldProjectData(context) : null;
        if (oldBlazeProjectData == null && syncParams.syncMode != SyncMode.NO_BUILD) {
            syncParams = BlazeSyncParams.Builder.copy(syncParams).setSyncMode(SyncMode.FULL).addProjectViewTargets(true).build();
        }
        syncStats.setSyncMode(syncParams.syncMode);
        onSyncStart(project, context, syncParams.syncMode);
        if (syncParams.syncMode != SyncMode.STARTUP) {
            syncResult = doSyncProject(context, oldBlazeProjectData);
            if (context.isCancelled()) {
                syncResult = SyncResult.CANCELLED;
            }
        } else {
            syncResult = SyncResult.SUCCESS;
        }
        if (syncResult.successful()) {
            ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
            BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
            updateInMemoryState(project, context, projectViewSet, blazeProjectData);
            onSyncComplete(project, context, projectViewSet, blazeProjectData, syncResult);
        }
    } catch (Throwable e) {
        logSyncError(context, e);
    } finally {
        try {
            syncStats.setTotalExecTimeMs(System.currentTimeMillis() - syncStartTime);
            syncStats.setSyncResult(syncResult);
            EventLoggingService.getInstance().ifPresent(s -> s.log(buildStats(syncStats)));
        } catch (Exception e) {
            logSyncError(context, e);
        }
        afterSync(project, context, syncResult);
    }
    return syncResult == SyncResult.SUCCESS || syncResult == SyncResult.PARTIAL_SUCCESS;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) SyncResult(com.google.idea.blaze.base.sync.SyncListener.SyncResult) IOException(java.io.IOException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)74 File (java.io.File)30 Test (org.junit.Test)29 WorkspaceLanguageSettings (com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings)21 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)17 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)17 ImmutableList (com.google.common.collect.ImmutableList)16 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)16 Project (com.intellij.openapi.project.Project)16 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)15 Nullable (javax.annotation.Nullable)15 List (java.util.List)14 DirectoryEntry (com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry)12 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)11 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)11 Kind (com.google.idea.blaze.base.model.primitives.Kind)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)11 Set (java.util.Set)11 Lists (com.google.common.collect.Lists)10 Collectors (java.util.stream.Collectors)10