Search in sources :

Example 26 with BlazeContext

use of com.google.idea.blaze.base.scope.BlazeContext in project intellij by bazelbuild.

the class BuildPluginBeforeRunTaskProvider method executeTask.

@Override
public final boolean executeTask(final DataContext dataContext, final RunConfiguration configuration, final ExecutionEnvironment env, Task task) {
    if (!canExecuteTask(configuration, task)) {
        return false;
    }
    BlazeConsolePopupBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction() ? BlazeConsolePopupBehavior.NEVER : BlazeConsolePopupBehavior.ALWAYS;
    return Scope.root(context -> {
        WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
        context.push(new ExperimentScope()).push(new IssuesScope(project, true)).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, workspaceRoot, BlazeInvocationContext.NonSync, true)).build()).push(new IdeaLogScope());
        BlazeIntellijPluginDeployer deployer = env.getUserData(BlazeIntellijPluginDeployer.USER_DATA_KEY);
        if (deployer == null) {
            IssueOutput.error("Could not find BlazeIntellijPluginDeployer in env.").submit(context);
            return false;
        }
        deployer.buildStarted();
        final ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
        if (projectViewSet == null) {
            IssueOutput.error("Could not load project view. Please resync project").submit(context);
            return false;
        }
        final ScopedTask<Void> buildTask = new ScopedTask<Void>(context) {

            @Override
            protected Void execute(BlazeContext context) {
                String binaryPath = Blaze.getBuildSystemProvider(project).getBinaryPath();
                BlazeIntellijPluginConfiguration config = (BlazeIntellijPluginConfiguration) configuration;
                ListenableFuture<String> executionRootFuture = BlazeInfoRunner.getInstance().runBlazeInfo(context, binaryPath, workspaceRoot, config.getBlazeFlagsState().getExpandedFlags(), BlazeInfo.EXECUTION_ROOT_KEY);
                String executionRoot;
                try {
                    executionRoot = executionRootFuture.get();
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    context.setCancelled();
                    return null;
                } catch (ExecutionException e) {
                    IssueOutput.error(e.getMessage()).submit(context);
                    context.setHasError();
                    return null;
                }
                if (executionRoot == null) {
                    IssueOutput.error("Could not determine execution root").submit(context);
                    return null;
                }
                BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
                if (blazeProjectData == null) {
                    IssueOutput.error("Could not determine execution root").submit(context);
                    return null;
                }
                try (BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(f -> true)) {
                    BlazeCommand command = BlazeCommand.builder(binaryPath, BlazeCommandName.BUILD).addTargets(config.getTarget()).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.BUILD, BlazeInvocationContext.NonSync)).addBlazeFlags(config.getBlazeFlagsState().getExpandedFlags()).addExeFlags(config.getExeFlagsState().getExpandedFlags()).addBlazeFlags(buildResultHelper.getBuildFlags()).build();
                    if (command == null || context.hasErrors() || context.isCancelled()) {
                        return null;
                    }
                    SaveUtil.saveAllFiles();
                    int retVal = ExternalTask.builder(workspaceRoot).addBlazeCommand(command).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
                    if (retVal != 0) {
                        context.setHasError();
                    }
                    FileCaches.refresh(project);
                    deployer.reportBuildComplete(new File(executionRoot), buildResultHelper);
                    return null;
                }
            }
        };
        ListenableFuture<Void> buildFuture = ProgressiveTaskWithProgressIndicator.builder(project).setTitle("Executing blaze build for IntelliJ plugin jar").submitTaskWithResult(buildTask);
        try {
            Futures.getChecked(buildFuture, ExecutionException.class);
        } catch (ExecutionException e) {
            context.setHasError();
        } catch (CancellationException e) {
            context.setCancelled();
        }
        if (context.hasErrors() || context.isCancelled()) {
            return false;
        }
        return true;
    });
}
Also used : WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) ExecutionException(java.util.concurrent.ExecutionException) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) ExperimentScope(com.google.idea.blaze.base.experiments.ExperimentScope) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) ScopedTask(com.google.idea.blaze.base.scope.ScopedTask) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope) CancellationException(java.util.concurrent.CancellationException) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) File(java.io.File) BlazeConsolePopupBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior)

Example 27 with BlazeContext

use of com.google.idea.blaze.base.scope.BlazeContext in project intellij by bazelbuild.

the class BlazeBeforeRunCommandHelper method runBlazeBuild.

/**
 * Kicks off the blaze build task, returning a corresponding {@link ListenableFuture}.
 */
public static ListenableFuture<BuildResult> runBlazeBuild(BlazeCommandRunConfiguration configuration, BuildResultHelper buildResultHelper, List<String> requiredExtraBlazeFlags, List<String> overridableExtraBlazeFlags, String progressMessage) {
    Project project = configuration.getProject();
    BlazeCommandRunConfigurationCommonState handlerState = (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
    String binaryPath = handlerState.getBlazeBinaryState().getBlazeBinary() != null ? handlerState.getBlazeBinaryState().getBlazeBinary() : Blaze.getBuildSystemProvider(project).getBinaryPath();
    BlazeConsolePopupBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction() ? BlazeConsolePopupBehavior.NEVER : BlazeConsolePopupBehavior.ALWAYS;
    return ProgressiveTaskWithProgressIndicator.builder(project).submitTaskWithResult(new ScopedTask<BuildResult>() {

        @Override
        protected BuildResult execute(BlazeContext context) {
            context.push(new IssuesScope(project, true)).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, workspaceRoot, BlazeInvocationContext.NonSync, true)).build());
            context.output(new StatusOutput(progressMessage));
            BlazeCommand.Builder command = BlazeCommand.builder(binaryPath, BlazeCommandName.BUILD).addTargets(configuration.getTarget()).addBlazeFlags(overridableExtraBlazeFlags).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.BUILD, BlazeInvocationContext.NonSync)).addBlazeFlags(handlerState.getBlazeFlagsState().getExpandedFlags()).addBlazeFlags(requiredExtraBlazeFlags).addBlazeFlags(buildResultHelper.getBuildFlags());
            int exitCode = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
            return BuildResult.fromExitCode(exitCode);
        }
    });
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Project(com.intellij.openapi.project.Project) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope) BlazeConsolePopupBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior)

Example 28 with BlazeContext

use of com.google.idea.blaze.base.scope.BlazeContext in project intellij by bazelbuild.

the class BlazeConfigurationResolver method buildBlazeConfigurationData.

private void buildBlazeConfigurationData(BlazeContext parentContext, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, ImmutableMap<TargetKey, CToolchainIdeInfo> toolchainLookupMap, ImmutableMap<File, VirtualFile> headerRoots, ImmutableMap<CToolchainIdeInfo, BlazeCompilerSettings> compilerSettings, CompilerInfoCache compilerInfoCache, ExecutionRootPathResolver executionRootPathResolver, BlazeConfigurationResolverResult oldConfigurationData, BlazeConfigurationResolverResult.Builder builder) {
    // Type specification needed to avoid incorrect type inference during command line build.
    Scope.push(parentContext, (ScopedOperation) context -> {
        context.push(new TimingScope("Build C configuration map", EventType.Other));
        ProjectViewTargetImportFilter filter = new ProjectViewTargetImportFilter(project, workspaceRoot, projectViewSet);
        ConcurrentMap<TargetKey, BlazeResolveConfigurationData> targetToData = Maps.newConcurrentMap();
        List<ListenableFuture<?>> targetToDataFutures = blazeProjectData.targetMap.targets().stream().filter(target -> target.kind.languageClass == LanguageClass.C).filter(target -> target.kind != Kind.CC_TOOLCHAIN).filter(filter::isSourceTarget).filter(BlazeConfigurationResolver::containsCompiledSources).map(target -> submit(() -> {
            BlazeResolveConfigurationData data = createResolveConfiguration(target, toolchainLookupMap, headerRoots, compilerSettings, compilerInfoCache, executionRootPathResolver);
            if (data != null) {
                targetToData.put(target.key, data);
            }
            return null;
        })).collect(Collectors.toList());
        try {
            Futures.allAsList(targetToDataFutures).get();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            context.setCancelled();
            return;
        } catch (ExecutionException e) {
            IssueOutput.error("Could not build C resolve configurations: " + e).submit(context);
            logger.error("Could not build C resolve configurations", e);
            return;
        }
        findEquivalenceClasses(context, project, blazeProjectData.workspacePathResolver, targetToData, oldConfigurationData, builder);
    });
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) FileUtilRt(com.intellij.openapi.util.io.FileUtilRt) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ScopedFunction(com.google.idea.blaze.base.scope.ScopedFunction) ExecutionRootPathResolver(com.google.idea.blaze.base.sync.workspace.ExecutionRootPathResolver) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Logger(com.intellij.openapi.diagnostic.Logger) Blaze(com.google.idea.blaze.base.settings.Blaze) ImmutableMap(com.google.common.collect.ImmutableMap) CompilerInfoCache(com.jetbrains.cidr.toolchains.CompilerInfoCache) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) CIdeInfo(com.google.idea.blaze.base.ideinfo.CIdeInfo) List(java.util.List) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) Queue(java.util.Queue) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Multimap(com.google.common.collect.Multimap) VfsUtils(com.google.idea.blaze.base.io.VfsUtils) ConcurrentMap(java.util.concurrent.ConcurrentMap) Kind(com.google.idea.blaze.base.model.primitives.Kind) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Scope(com.google.idea.blaze.base.scope.Scope) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) Maps(com.google.common.collect.Maps) File(java.io.File) CToolchainIdeInfo(com.google.idea.blaze.base.ideinfo.CToolchainIdeInfo) ExecutionException(java.util.concurrent.ExecutionException) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) Futures(com.google.common.util.concurrent.Futures) ExecutionRootPath(com.google.idea.blaze.base.model.primitives.ExecutionRootPath) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) ArrayDeque(java.util.ArrayDeque) ScopedOperation(com.google.idea.blaze.base.scope.ScopedOperation) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) ProjectViewTargetImportFilter(com.google.idea.blaze.base.sync.projectview.ProjectViewTargetImportFilter) ConcurrentMap(java.util.concurrent.ConcurrentMap) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ExecutionException(java.util.concurrent.ExecutionException)

Example 29 with BlazeContext

use of com.google.idea.blaze.base.scope.BlazeContext in project intellij by bazelbuild.

the class JdepsFileReader method loadJdepsFiles.

/**
 * Loads any updated jdeps files since the last invocation of this method.
 */
@Nullable
public JdepsMap loadJdepsFiles(Project project, BlazeContext parentContext, ArtifactLocationDecoder artifactLocationDecoder, Iterable<TargetIdeInfo> targetsToLoad, SyncState.Builder syncStateBuilder, @Nullable SyncState previousSyncState) {
    JdepsState oldState = previousSyncState != null ? previousSyncState.get(JdepsState.class) : null;
    JdepsState jdepsState = Scope.push(parentContext, (context) -> {
        context.push(new TimingScope("LoadJdepsFiles", EventType.Other));
        return doLoadJdepsFiles(project, context, artifactLocationDecoder, oldState, targetsToLoad);
    });
    if (jdepsState == null) {
        return null;
    }
    syncStateBuilder.put(JdepsState.class, jdepsState);
    return targetKey -> jdepsState.targetToJdeps.get(targetKey);
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) PrefetchService(com.google.idea.blaze.base.prefetch.PrefetchService) Callable(java.util.concurrent.Callable) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) Lists(com.google.common.collect.Lists) Scope(com.google.idea.blaze.base.scope.Scope) Map(java.util.Map) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) Nullable(javax.annotation.Nullable) FileDiffer(com.google.idea.blaze.base.filecache.FileDiffer) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ImmutableMap(com.google.common.collect.ImmutableMap) FutureUtil(com.google.idea.blaze.base.async.FutureUtil) SyncState(com.google.idea.blaze.base.model.SyncState) FileInputStream(java.io.FileInputStream) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Maps(com.google.common.collect.Maps) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Serializable(java.io.Serializable) ExecutionException(java.util.concurrent.ExecutionException) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Deps(com.google.devtools.build.lib.view.proto.Deps) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) InputStream(java.io.InputStream) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) Nullable(javax.annotation.Nullable)

Example 30 with BlazeContext

use of com.google.idea.blaze.base.scope.BlazeContext in project intellij by bazelbuild.

the class SourceDirectoryCalculator method calculateJavaSourceDirectories.

/**
 * Adds the java source directories.
 */
private void calculateJavaSourceDirectories(BlazeContext context, WorkspaceRoot workspaceRoot, ArtifactLocationDecoder artifactLocationDecoder, WorkspacePath directoryRoot, Collection<SourceArtifact> javaArtifacts, Collection<JavaPackageReader> javaPackageReaders, Collection<BlazeSourceDirectory> result) {
    List<SourceRoot> sourceRootsPerFile = Lists.newArrayList();
    // Get java sources
    List<ListenableFuture<SourceRoot>> sourceRootFutures = Lists.newArrayList();
    for (final SourceArtifact sourceArtifact : javaArtifacts) {
        ListenableFuture<SourceRoot> future = executorService.submit(() -> sourceRootForJavaSource(context, artifactLocationDecoder, sourceArtifact, javaPackageReaders));
        sourceRootFutures.add(future);
    }
    try {
        for (SourceRoot sourceRoot : Futures.allAsList(sourceRootFutures).get()) {
            if (sourceRoot != null) {
                sourceRootsPerFile.add(sourceRoot);
            }
        }
    } catch (ExecutionException | InterruptedException e) {
        logger.error(e);
        throw new IllegalStateException("Could not read sources");
    }
    // Sort source roots into their respective directories
    Map<WorkspacePath, Multiset<SourceRoot>> sourceDirectoryToSourceRoots = new HashMap<>();
    for (SourceRoot sourceRoot : sourceRootsPerFile) {
        sourceDirectoryToSourceRoots.computeIfAbsent(sourceRoot.workspacePath, k -> HashMultiset.create()).add(sourceRoot);
    }
    // Create a mapping from directory to package prefix
    Map<WorkspacePath, SourceRoot> workspacePathToSourceRoot = Maps.newHashMap();
    for (WorkspacePath workspacePath : sourceDirectoryToSourceRoots.keySet()) {
        Multiset<SourceRoot> sources = sourceDirectoryToSourceRoots.get(workspacePath);
        Multiset<String> packages = HashMultiset.create();
        for (Multiset.Entry<SourceRoot> entry : sources.entrySet()) {
            packages.setCount(entry.getElement().packagePrefix, entry.getCount());
        }
        final String directoryPackagePrefix;
        // Common case -- all source files agree on a single package
        if (packages.elementSet().size() == 1) {
            directoryPackagePrefix = packages.elementSet().iterator().next();
        } else {
            String preferredPackagePrefix = PackagePrefixCalculator.packagePrefixOf(workspacePath);
            directoryPackagePrefix = pickMostFrequentlyOccurring(packages, preferredPackagePrefix);
        }
        SourceRoot candidateRoot = new SourceRoot(workspacePath, directoryPackagePrefix);
        workspacePathToSourceRoot.put(workspacePath, candidateRoot);
    }
    // Add content entry base if it doesn't exist
    if (!workspacePathToSourceRoot.containsKey(directoryRoot)) {
        SourceRoot candidateRoot = new SourceRoot(directoryRoot, PackagePrefixCalculator.packagePrefixOf(directoryRoot));
        workspacePathToSourceRoot.put(directoryRoot, candidateRoot);
    }
    // First, create a graph of the directory structure from root to each source file
    Map<WorkspacePath, SourceRootDirectoryNode> sourceRootDirectoryNodeMap = Maps.newHashMap();
    SourceRootDirectoryNode rootNode = new SourceRootDirectoryNode(directoryRoot, null);
    sourceRootDirectoryNodeMap.put(directoryRoot, rootNode);
    for (SourceRoot sourceRoot : workspacePathToSourceRoot.values()) {
        final String sourcePathRelativeToDirectoryRoot = sourcePathRelativeToDirectoryRoot(directoryRoot, sourceRoot.workspacePath);
        List<String> pathComponents = !Strings.isNullOrEmpty(sourcePathRelativeToDirectoryRoot) ? PATH_SPLITTER.splitToList(sourcePathRelativeToDirectoryRoot) : ImmutableList.of();
        SourceRootDirectoryNode previousNode = rootNode;
        for (int i = 0; i < pathComponents.size(); ++i) {
            final WorkspacePath workspacePath = getWorkspacePathFromPathComponents(directoryRoot, pathComponents, i + 1);
            SourceRootDirectoryNode node = sourceRootDirectoryNodeMap.get(workspacePath);
            if (node == null) {
                node = new SourceRootDirectoryNode(workspacePath, pathComponents.get(i));
                sourceRootDirectoryNodeMap.put(workspacePath, node);
                previousNode.children.add(node);
            }
            previousNode = node;
        }
    }
    // Add package prefix votes at each directory node
    for (SourceRoot sourceRoot : workspacePathToSourceRoot.values()) {
        final String sourcePathRelativeToDirectoryRoot = sourcePathRelativeToDirectoryRoot(directoryRoot, sourceRoot.workspacePath);
        List<String> packageComponents = PACKAGE_SPLITTER.splitToList(sourceRoot.packagePrefix);
        List<String> pathComponents = !Strings.isNullOrEmpty(sourcePathRelativeToDirectoryRoot) ? PATH_SPLITTER.splitToList(sourcePathRelativeToDirectoryRoot) : ImmutableList.of();
        int packageIndex = packageComponents.size();
        int pathIndex = pathComponents.size();
        while (pathIndex >= 0 && packageIndex >= 0) {
            final WorkspacePath workspacePath = getWorkspacePathFromPathComponents(directoryRoot, pathComponents, pathIndex);
            SourceRootDirectoryNode node = sourceRootDirectoryNodeMap.get(workspacePath);
            String packagePrefix = PACKAGE_JOINER.join(packageComponents.subList(0, packageIndex));
            // Otherwise just add a vote
            if (sourceRoot.workspacePath.equals(workspacePath)) {
                node.forcedPackagePrefix = packagePrefix;
            } else {
                node.packagePrefixVotes.add(packagePrefix);
            }
            String pathComponent = pathIndex > 0 ? pathComponents.get(pathIndex - 1) : "";
            String packageComponent = packageIndex > 0 ? packageComponents.get(packageIndex - 1) : "";
            if (!pathComponent.equals(packageComponent)) {
                break;
            }
            --packageIndex;
            --pathIndex;
        }
    }
    Map<WorkspacePath, SourceRoot> sourceRoots = Maps.newHashMap();
    SourceRootDirectoryNode root = sourceRootDirectoryNodeMap.get(directoryRoot);
    visitDirectoryNode(sourceRoots, root, null);
    for (SourceRoot sourceRoot : sourceRoots.values()) {
        result.add(BlazeSourceDirectory.builder(workspaceRoot.fileForPath(sourceRoot.workspacePath)).setPackagePrefix(sourceRoot.packagePrefix).setGenerated(false).build());
    }
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) TransientExecutor(com.google.idea.blaze.base.async.executor.TransientExecutor) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Multiset(com.google.common.collect.Multiset) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) HashMultiset(com.google.common.collect.HashMultiset) Scope(com.google.idea.blaze.base.scope.Scope) Map(java.util.Map) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) Project(com.intellij.openapi.project.Project) Objects(com.google.common.base.Objects) Logger(com.intellij.openapi.diagnostic.Logger) Splitter(com.google.common.base.Splitter) Nullable(javax.annotation.Nullable) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) BlazeSourceDirectory(com.google.idea.blaze.java.sync.model.BlazeSourceDirectory) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Comparator(java.util.Comparator) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) PackagePrefixCalculator(com.google.idea.blaze.base.util.PackagePrefixCalculator) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) HashMap(java.util.HashMap) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Multiset(com.google.common.collect.Multiset) HashMultiset(com.google.common.collect.HashMultiset) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)42 ImmutableList (com.google.common.collect.ImmutableList)18 Nullable (javax.annotation.Nullable)18 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)17 List (java.util.List)16 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)15 Project (com.intellij.openapi.project.Project)15 File (java.io.File)15 Set (java.util.Set)15 Lists (com.google.common.collect.Lists)13 BlazeSyncPlugin (com.google.idea.blaze.base.sync.BlazeSyncPlugin)12 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)12 Logger (com.intellij.openapi.diagnostic.Logger)12 Collection (java.util.Collection)12 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)11 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)10 Map (java.util.Map)10 ImmutableSet (com.google.common.collect.ImmutableSet)9 BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)9 Collectors (java.util.stream.Collectors)9