Search in sources :

Example 16 with WorkspaceRoot

use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.

the class BlazeIdeInterfaceAspectsImpl method getIdeInfo.

private static IdeInfoResult getIdeInfo(Project project, BlazeContext parentContext, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, ImmutableSet<LanguageClass> activeLanguages, ShardedTargetList shardedTargets, AspectStrategy aspectStrategy) {
    return Scope.push(parentContext, context -> {
        context.push(new TimingScope(String.format("Execute%sCommand", Blaze.buildSystemName(project)), EventType.BlazeInvocation));
        Set<File> ideInfoFiles = new LinkedHashSet<>();
        Function<Integer, String> progressMessage = count -> String.format("Building IDE info files for shard %s of %s...", count, shardedTargets.shardedTargets.size());
        Function<List<TargetExpression>, BuildResult> invocation = targets -> {
            IdeInfoResult result = getIdeInfoForTargets(project, context, workspaceRoot, projectViewSet, activeLanguages, targets, aspectStrategy);
            ideInfoFiles.addAll(result.files);
            return result.buildResult;
        };
        BuildResult result = shardedTargets.runShardedCommand(project, context, progressMessage, invocation);
        return new IdeInfoResult(ideInfoFiles, result);
    });
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ExternalTask(com.google.idea.blaze.base.async.process.ExternalTask) AdditionalLanguagesHelper(com.google.idea.blaze.base.lang.AdditionalLanguagesHelper) Result(com.google.idea.blaze.base.scope.Result) LanguageSupport(com.google.idea.blaze.base.sync.projectview.LanguageSupport) PrefetchService(com.google.idea.blaze.base.prefetch.PrefetchService) ScopedFunction(com.google.idea.blaze.base.scope.ScopedFunction) Map(java.util.Map) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) IntellijIdeInfo(com.google.devtools.intellij.ideinfo.IntellijIdeInfo) FileDiffer(com.google.idea.blaze.base.filecache.FileDiffer) BlazeConsoleLineProcessorProvider(com.google.idea.blaze.base.console.BlazeConsoleLineProcessorProvider) Blaze(com.google.idea.blaze.base.settings.Blaze) BiMap(com.google.common.collect.BiMap) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AspectStrategy(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy) Predicate(java.util.function.Predicate) Collection(java.util.Collection) BuildSystemProvider(com.google.idea.blaze.base.bazel.BuildSystemProvider) FutureUtil(com.google.idea.blaze.base.async.FutureUtil) Set(java.util.Set) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Sets(com.google.common.collect.Sets) Serializable(java.io.Serializable) BlazeCommandName(com.google.idea.blaze.base.command.BlazeCommandName) Objects(java.util.Objects) List(java.util.List) LineProcessingOutputStream(com.google.idea.blaze.base.async.process.LineProcessingOutputStream) Status(com.google.idea.blaze.base.sync.aspects.BuildResult.Status) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ShardedTargetList(com.google.idea.blaze.base.sync.sharding.ShardedTargetList) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Joiner(com.google.common.base.Joiner) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AspectStrategyProvider(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategyProvider) Function(java.util.function.Function) ArrayList(java.util.ArrayList) NavigatableAdapter(com.intellij.pom.NavigatableAdapter) HashSet(java.util.HashSet) Kind(com.google.idea.blaze.base.model.primitives.Kind) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) BuildSystem(com.google.idea.blaze.base.settings.Blaze.BuildSystem) Scope(com.google.idea.blaze.base.scope.Scope) OutputGroup(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy.OutputGroup) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) LinkedHashSet(java.util.LinkedHashSet) Nullable(javax.annotation.Nullable) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) PerformanceWarning(com.google.idea.blaze.base.scope.output.PerformanceWarning) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) PrefetchFileSource(com.google.idea.blaze.base.prefetch.PrefetchFileSource) SyncState(com.google.idea.blaze.base.model.SyncState) Maps(com.google.common.collect.Maps) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) AtomicLong(java.util.concurrent.atomic.AtomicLong) HashBiMap(com.google.common.collect.HashBiMap) Futures(com.google.common.util.concurrent.Futures) Ordering(com.google.common.collect.Ordering) 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) BlazeFlags(com.google.idea.blaze.base.command.BlazeFlags) BlazeInvocationContext(com.google.idea.blaze.base.command.BlazeInvocationContext) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) List(java.util.List) ShardedTargetList(com.google.idea.blaze.base.sync.sharding.ShardedTargetList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) File(java.io.File)

Example 17 with WorkspaceRoot

use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.

the class DirectoryStructure method walkDirectoryStructure.

private static ListenableFuture<PathStructurePair> walkDirectoryStructure(WorkspaceRoot workspaceRoot, Set<WorkspacePath> excludeDirectories, FileOperationProvider fileOperationProvider, ListeningExecutorService executorService, WorkspacePath workspacePath) {
    if (excludeDirectories.contains(workspacePath)) {
        return Futures.immediateFuture(null);
    }
    File file = workspaceRoot.fileForPath(workspacePath);
    if (!fileOperationProvider.isDirectory(file)) {
        return Futures.immediateFuture(null);
    }
    ListenableFuture<File[]> childrenFuture = executorService.submit(() -> fileOperationProvider.listFiles(file));
    return Futures.transformAsync(childrenFuture, children -> {
        if (children == null) {
            return Futures.immediateFuture(null);
        }
        List<ListenableFuture<PathStructurePair>> futures = Lists.newArrayListWithExpectedSize(children.length);
        for (File child : children) {
            WorkspacePath childWorkspacePath;
            try {
                childWorkspacePath = workspaceRoot.workspacePathFor(child);
            } catch (IllegalArgumentException e) {
                // stop at directories with unhandled characters.
                continue;
            }
            futures.add(walkDirectoryStructure(workspaceRoot, excludeDirectories, fileOperationProvider, executorService, childWorkspacePath));
        }
        return Futures.transform(Futures.allAsList(futures), (Function<List<PathStructurePair>, PathStructurePair>) pairs -> {
            Builder<WorkspacePath, DirectoryStructure> result = ImmutableMap.builder();
            for (PathStructurePair pair : pairs) {
                if (pair != null) {
                    result.put(pair.path, pair.directoryStructure);
                }
            }
            return new PathStructurePair(workspacePath, new DirectoryStructure(result.build()));
        }, executorService);
    }, executorService);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Blaze(com.google.idea.blaze.base.settings.Blaze) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) Function(com.google.common.base.Function) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) Set(java.util.Set) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) File(java.io.File) Builder(com.google.common.collect.ImmutableMap.Builder) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Lists(com.google.common.collect.Lists) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Project(com.intellij.openapi.project.Project) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) FetchExecutor(com.google.idea.blaze.base.prefetch.FetchExecutor) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Builder(com.google.common.collect.ImmutableMap.Builder) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) List(java.util.List) File(java.io.File)

Example 18 with WorkspaceRoot

use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.

the class BlazeIntegrationTestCase method setUp.

@Before
public final void setUp() throws Exception {
    IdeaTestFixtureFactory factory = IdeaTestFixtureFactory.getFixtureFactory();
    TestFixtureBuilder<IdeaProjectTestFixture> fixtureBuilder = factory.createLightFixtureBuilder(LightCodeInsightFixtureTestCase.JAVA_8);
    final IdeaProjectTestFixture fixture = fixtureBuilder.getFixture();
    testFixture = factory.createCodeInsightFixture(fixture, new LightTempDirTestFixtureImpl(true));
    testFixture.setUp();
    fileSystem = new TestFileSystem(getProject(), testFixture.getTempDirFixture());
    runWriteAction(() -> {
        ProjectJdkTable.getInstance().addJdk(IdeaTestUtil.getMockJdk18());
        VirtualFile workspaceRootVirtualFile = fileSystem.createDirectory("workspace");
        workspaceRoot = new WorkspaceRoot(new File(workspaceRootVirtualFile.getPath()));
        projectDataDirectory = fileSystem.createDirectory("project-data-dir");
        workspace = new WorkspaceFileSystem(workspaceRoot, fileSystem);
    });
    BlazeImportSettingsManager.getInstance(getProject()).setImportSettings(new BlazeImportSettings(workspaceRoot.toString(), "test-project", projectDataDirectory.getPath(), workspaceRoot.fileForPath(new WorkspacePath("project-view-file")).getPath(), buildSystem()));
    registerApplicationService(FileOperationProvider.class, new TestFileSystem.MockFileOperationProvider());
    registerApplicationService(InputStreamProvider.class, file -> {
        VirtualFile vf = fileSystem.findFile(file.getPath());
        if (vf == null) {
            throw new FileNotFoundException();
        }
        return vf.getInputStream();
    });
    registerApplicationService(VirtualFileSystemProvider.class, new TestFileSystem.TempVirtualFileSystemProvider());
    String requiredPlugins = System.getProperty("idea.required.plugins.id");
    if (requiredPlugins != null) {
        VerifyRequiredPluginsEnabled.runCheck(requiredPlugins.split(","));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) IdeaTestFixtureFactory(com.intellij.testFramework.fixtures.IdeaTestFixtureFactory) FileNotFoundException(java.io.FileNotFoundException) LightTempDirTestFixtureImpl(com.intellij.testFramework.fixtures.impl.LightTempDirTestFixtureImpl) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) IdeaProjectTestFixture(com.intellij.testFramework.fixtures.IdeaProjectTestFixture) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Before(org.junit.Before)

Example 19 with WorkspaceRoot

use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.

the class BlazeCidrLauncher method createProcess.

@Override
public ProcessHandler createProcess(CommandLineState state) throws ExecutionException {
    ImmutableList<String> testHandlerFlags = ImmutableList.of();
    BlazeTestUiSession testUiSession = useTestUi() ? TestUiSessionProvider.getInstance(project).getTestUiSession(configuration.getTarget()) : null;
    if (testUiSession != null) {
        testHandlerFlags = testUiSession.getBlazeFlags();
    }
    ProjectViewSet projectViewSet = Preconditions.checkNotNull(ProjectViewManager.getInstance(project).getProjectViewSet());
    List<String> fixedBlazeFlags = getFixedBlazeFlags();
    BlazeCommand.Builder command = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(), handlerState.getCommandState().getCommand()).addTargets(configuration.getTarget()).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, handlerState.getCommandState().getCommand(), BlazeInvocationContext.NonSync)).addBlazeFlags(testHandlerFlags).addBlazeFlags(fixedBlazeFlags).addExeFlags(handlerState.getExeFlagsState().getExpandedFlags());
    state.setConsoleBuilder(createConsoleBuilder(testUiSession));
    state.addConsoleFilters(getConsoleFilters().toArray(new Filter[0]));
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    return new ScopedBlazeProcessHandler(project, command.build(), workspaceRoot, new ScopedBlazeProcessHandler.ScopedProcessHandlerDelegate() {

        @Override
        public void onBlazeContextStart(BlazeContext context) {
            context.push(new IssuesScope(project, BlazeUserSettings.getInstance().getShowProblemsViewForRunAction()));
        }

        @Override
        public ImmutableList<ProcessListener> createProcessListeners(BlazeContext context) {
            LineProcessingOutputStream outputStream = LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context));
            return ImmutableList.of(new LineProcessingProcessAdapter(outputStream));
        }
    });
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) LineProcessingProcessAdapter(com.google.idea.blaze.base.run.processhandler.LineProcessingProcessAdapter) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) ImmutableList(com.google.common.collect.ImmutableList) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ScopedBlazeProcessHandler(com.google.idea.blaze.base.run.processhandler.ScopedBlazeProcessHandler) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) UrlFilter(com.intellij.execution.filters.UrlFilter) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) Filter(com.intellij.execution.filters.Filter) BlazeTargetFilter(com.google.idea.blaze.base.run.filter.BlazeTargetFilter) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope) LineProcessingOutputStream(com.google.idea.blaze.base.async.process.LineProcessingOutputStream) BlazeTestUiSession(com.google.idea.blaze.base.run.smrunner.BlazeTestUiSession)

Example 20 with WorkspaceRoot

use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot in project intellij by bazelbuild.

the class BlazeCoverageEngine method createCoverageViewExtension.

@Nullable
@Override
public CoverageViewExtension createCoverageViewExtension(Project project, CoverageSuitesBundle suites, StateBean stateBean) {
    WorkspaceRoot root = WorkspaceRoot.fromProjectSafe(project);
    if (root == null) {
        return null;
    }
    Set<File> topLevelDirectories = getTopLevelDirectories(suites);
    if (topLevelDirectories.isEmpty()) {
        return null;
    }
    CoverageAnnotator annotator = getCoverageAnnotator(project);
    return new DirectoryCoverageViewExtension(project, annotator, suites, stateBean) {

        private List<AbstractTreeNode> topLevelNodes;

        @Override
        public AbstractTreeNode createRootNode() {
            if (topLevelDirectories.size() == 1) {
                File file = topLevelDirectories.iterator().next();
                return new CoverageListRootNode(project, resolveFile(project, file), suites, stateBean);
            }
            return new CoverageListRootNode(project, resolveFile(project, root.directory()), suites, stateBean) {

                @Override
                public Collection<? extends AbstractTreeNode> getChildren() {
                    return getRootChildren(this);
                }
            };
        }

        @Override
        public List<AbstractTreeNode> getChildrenNodes(AbstractTreeNode node) {
            if (node instanceof CoverageListRootNode && topLevelDirectories.size() != 1) {
                return getRootChildren((CoverageListRootNode) node);
            }
            return super.getChildrenNodes(node).stream().filter(treeNode -> !isLeaf(treeNode) || getPercentage(0, treeNode) != null).collect(Collectors.toList());
        }

        private List<AbstractTreeNode> getRootChildren(CoverageListRootNode root) {
            if (topLevelNodes == null) {
                topLevelNodes = ReadAction.compute(() -> getTopLevelNodes(project, suites, stateBean));
                for (AbstractTreeNode node : topLevelNodes) {
                    node.setParent(root);
                }
            }
            return topLevelNodes;
        }
    };
}
Also used : DirectoryCoverageViewExtension(com.intellij.coverage.view.DirectoryCoverageViewExtension) CoverageListRootNode(com.intellij.coverage.view.CoverageListRootNode) Arrays(java.util.Arrays) CoverageRunner(com.intellij.coverage.CoverageRunner) VirtualFile(com.intellij.openapi.vfs.VirtualFile) CoverageFileProvider(com.intellij.coverage.CoverageFileProvider) ReadAction(com.intellij.openapi.application.ReadAction) PsiManager(com.intellij.psi.PsiManager) CoverageUtils(com.google.idea.blaze.base.run.coverage.CoverageUtils) ImmutableList(com.google.common.collect.ImmutableList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) DirectoryCoverageViewExtension(com.intellij.coverage.view.DirectoryCoverageViewExtension) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) VirtualFileSystemProvider(com.google.idea.blaze.base.io.VirtualFileSystemProvider) Module(com.intellij.openapi.module.Module) CoverageEngine(com.intellij.coverage.CoverageEngine) CoverageEnabledConfiguration(com.intellij.execution.configurations.coverage.CoverageEnabledConfiguration) Nullable(javax.annotation.Nullable) Blaze(com.google.idea.blaze.base.settings.Blaze) Extensions(com.intellij.openapi.extensions.Extensions) CoverageSuitesBundle(com.intellij.coverage.CoverageSuitesBundle) ImmutableSet(com.google.common.collect.ImmutableSet) RunConfigurationBase(com.intellij.execution.configurations.RunConfigurationBase) Collection(java.util.Collection) Set(java.util.Set) CoverageListNode(com.intellij.coverage.view.CoverageListNode) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) Collectors(java.util.stream.Collectors) File(java.io.File) Objects(java.util.Objects) CoverageSuite(com.intellij.coverage.CoverageSuite) List(java.util.List) CoverageViewExtension(com.intellij.coverage.view.CoverageViewExtension) StateBean(com.intellij.coverage.view.CoverageViewManager.StateBean) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) CoverageAnnotator(com.intellij.coverage.CoverageAnnotator) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) CoverageAnnotator(com.intellij.coverage.CoverageAnnotator) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) CoverageListRootNode(com.intellij.coverage.view.CoverageListRootNode) Nullable(javax.annotation.Nullable)

Aggregations

WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)50 File (java.io.File)30 Nullable (javax.annotation.Nullable)23 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)21 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)19 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)18 ImmutableList (com.google.common.collect.ImmutableList)14 List (java.util.List)13 Project (com.intellij.openapi.project.Project)12 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)10 Kind (com.google.idea.blaze.base.model.primitives.Kind)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 Lists (com.google.common.collect.Lists)9 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)9 ImportRoots (com.google.idea.blaze.base.sync.projectview.ImportRoots)9 Collectors (java.util.stream.Collectors)9 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)8 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)8 Label (com.google.idea.blaze.base.model.primitives.Label)8 BlazeImportSettings (com.google.idea.blaze.base.settings.BlazeImportSettings)8