Search in sources :

Example 26 with WorkspaceRoot

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

the class WorkspaceHelper method resolveBlazePackage.

/**
 * Resolves the parent blaze package corresponding to this label.
 */
@Nullable
public static File resolveBlazePackage(Project project, Label label) {
    if (!label.isExternal()) {
        WorkspacePathResolver pathResolver = WorkspacePathResolverProvider.getInstance(project).getPathResolver();
        return pathResolver != null ? pathResolver.resolveToFile(label.blazePackage()) : null;
    }
    Map<String, WorkspaceRoot> externalWorkspaces = getExternalWorkspaceRoots(project);
    if (externalWorkspaces == null) {
        return null;
    }
    WorkspaceRoot root = externalWorkspaces.get(label.externalWorkspaceName());
    return root != null ? root.fileForPath(label.blazePackage()) : null;
}
Also used : WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Nullable(javax.annotation.Nullable)

Example 27 with WorkspaceRoot

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

the class BlazePsiDirectoryRootNode method updateImpl.

@Override
protected void updateImpl(PresentationData data) {
    super.updateImpl(data);
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(getProject());
    PsiDirectory psiDirectory = getValue();
    assert psiDirectory != null;
    WorkspacePath workspacePath = workspaceRoot.workspacePathFor(psiDirectory.getVirtualFile());
    String text = workspacePath.relativePath();
    for (BlazePsiDirectoryRootNodeNameModifier modifier : BlazePsiDirectoryRootNodeNameModifier.EP_NAME.getExtensions()) {
        text = modifier.modifyRootNodeName(text);
    }
    data.setPresentableText(text);
    data.clearText();
    data.addText(text, SimpleTextAttributes.REGULAR_ATTRIBUTES);
    data.setLocationString("");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) PsiDirectory(com.intellij.psi.PsiDirectory) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot)

Example 28 with WorkspaceRoot

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

the class BlazeTreeStructureProvider method createRootNode.

@Nullable
private WorkspaceRootNode createRootNode(Project project, ViewSettings settings) {
    BlazeImportSettings importSettings = BlazeImportSettingsManager.getInstance(project).getImportSettings();
    if (importSettings != null) {
        WorkspaceRoot workspaceRoot = WorkspaceRoot.fromImportSettings(importSettings);
        File fdir = workspaceRoot.directory();
        VirtualFile vdir = LocalFileSystem.getInstance().findFileByIoFile(fdir);
        if (vdir != null) {
            final PsiManager psiManager = PsiManager.getInstance(project);
            PsiDirectory directory = psiManager.findDirectory(vdir);
            return new WorkspaceRootNode(project, workspaceRoot, directory, wrapViewSettings(settings));
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) PsiDirectory(com.intellij.psi.PsiDirectory) PsiManager(com.intellij.psi.PsiManager) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 29 with WorkspaceRoot

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

the class SourceDirectoryCalculatorTest method getDecoder.

private static ArtifactLocationDecoder getDecoder() {
    File root = new File("/root");
    WorkspaceRoot workspaceRoot = new WorkspaceRoot(root);
    BlazeInfo roots = BlazeInfo.createMockBlazeInfo("/", "/root", "/root/out/crosstool/bin", "/root/out/crosstool/gen");
    return new ArtifactLocationDecoderImpl(roots, new WorkspacePathResolverImpl(workspaceRoot));
}
Also used : BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) ArtifactLocationDecoderImpl(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoderImpl) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) File(java.io.File)

Example 30 with WorkspaceRoot

use of com.google.idea.blaze.base.model.primitives.WorkspaceRoot 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)

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