Search in sources :

Example 1 with IdeaLogScope

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

the class BlazeBuildService method buildTargetExpressions.

@VisibleForTesting
void buildTargetExpressions(Project project, List<TargetExpression> targets, ProjectViewSet projectViewSet, NotificationScope notificationScope) {
    if (targets.isEmpty() || projectViewSet == null) {
        return;
    }
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return;
    }
    // go/futurereturn-lsc
    @SuppressWarnings("unused") Future<?> possiblyIgnoredError = ProgressiveTaskWithProgressIndicator.builder(project).setTitle("Building targets").submitTaskWithResult(new ScopedTask<Void>() {

        @Override
        public Void execute(BlazeContext context) {
            context.push(new ExperimentScope()).push(new BlazeConsoleScope.Builder(project).addConsoleFilters(new IssueOutputFilter(project, WorkspaceRoot.fromProject(project), BlazeInvocationContext.Sync, true)).build()).push(new IssuesScope(project, true)).push(new IdeaLogScope()).push(new TimingScope("Make", EventType.BlazeInvocation)).push(notificationScope);
            WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
            SaveUtil.saveAllFiles();
            ShardedTargetsResult shardedTargets = BlazeBuildTargetSharder.expandAndShardTargets(project, context, workspaceRoot, projectViewSet, blazeProjectData.workspacePathResolver, targets);
            if (shardedTargets.buildResult.status == BuildResult.Status.FATAL_ERROR) {
                return null;
            }
            BuildResult buildResult = BlazeIdeInterface.getInstance().compileIdeArtifacts(project, context, workspaceRoot, projectViewSet, blazeProjectData.blazeVersionData, blazeProjectData.workspaceLanguageSettings, shardedTargets.shardedTargets);
            FileCaches.refresh(project);
            if (buildResult.status != BuildResult.Status.SUCCESS) {
                context.setHasError();
            }
            return null;
        }
    });
}
Also used : ShardedTargetsResult(com.google.idea.blaze.base.sync.sharding.BlazeBuildTargetSharder.ShardedTargetsResult) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) ExperimentScope(com.google.idea.blaze.base.experiments.ExperimentScope) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with IdeaLogScope

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

the class BlazeJavaRunProfileState method startProcess.

@Override
protected ProcessHandler startProcess() throws ExecutionException {
    Project project = configuration.getProject();
    BlazeCommand.Builder blazeCommand;
    BlazeTestUiSession testUiSession = useTestUi() ? TestUiSessionProvider.getInstance(project).getTestUiSession(configuration.getTarget()) : null;
    if (testUiSession != null) {
        blazeCommand = getBlazeCommandBuilder(project, configuration, testUiSession.getBlazeFlags(), executorType);
        setConsoleBuilder(new TextConsoleBuilderImpl(project) {

            @Override
            protected ConsoleView createConsole() {
                return SmRunnerUtils.getConsoleView(project, configuration, getEnvironment().getExecutor(), testUiSession);
            }
        });
    } else {
        blazeCommand = getBlazeCommandBuilder(project, configuration, ImmutableList.of(), executorType);
    }
    addConsoleFilters(new BlazeTargetFilter(project, true), new IssueOutputFilter(project, WorkspaceRoot.fromProject(project), BlazeInvocationContext.NonSync, false));
    List<String> command = HotSwapUtils.canHotSwap(getEnvironment()) ? getBashCommandsToRunScript(blazeCommand) : blazeCommand.build().toList();
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    return new ScopedBlazeProcessHandler(project, command, workspaceRoot, new ScopedBlazeProcessHandler.ScopedProcessHandlerDelegate() {

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

        @Override
        public ImmutableList<ProcessListener> createProcessListeners(BlazeContext context) {
            LineProcessingOutputStream outputStream = LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context));
            return ImmutableList.of(new LineProcessingProcessAdapter(outputStream));
        }
    });
}
Also used : IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) LineProcessingProcessAdapter(com.google.idea.blaze.base.run.processhandler.LineProcessingProcessAdapter) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) ConsoleView(com.intellij.execution.ui.ConsoleView) ImmutableList(com.google.common.collect.ImmutableList) BlazeTargetFilter(com.google.idea.blaze.base.run.filter.BlazeTargetFilter) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) ScopedBlazeProcessHandler(com.google.idea.blaze.base.run.processhandler.ScopedBlazeProcessHandler) Project(com.intellij.openapi.project.Project) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) 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) TextConsoleBuilderImpl(com.intellij.execution.filters.TextConsoleBuilderImpl)

Example 3 with IdeaLogScope

use of com.google.idea.blaze.base.scope.scopes.IdeaLogScope 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 4 with IdeaLogScope

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

the class BlazeAndroidRunConfigurationRunner method executeBeforeRunTask.

@Override
public boolean executeBeforeRunTask(ExecutionEnvironment env) {
    final Project project = env.getProject();
    BlazeConsolePopupBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction() ? BlazeConsolePopupBehavior.NEVER : BlazeConsolePopupBehavior.ALWAYS;
    return Scope.root(context -> {
        context.push(new IssuesScope(project, true)).push(new ExperimentScope()).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, WorkspaceRoot.fromProject(project), BlazeInvocationContext.NonSync, true)).build()).push(new IdeaLogScope());
        BlazeAndroidRunContext runContext = env.getCopyableUserData(RUN_CONTEXT_KEY);
        if (runContext == null) {
            IssueOutput.error("Could not find run context. Please try again").submit(context);
            return false;
        }
        BlazeAndroidDeviceSelector.DeviceSession deviceSession = env.getCopyableUserData(DEVICE_SESSION_KEY);
        BlazeApkBuildStep buildStep = runContext.getBuildStep();
        try {
            return buildStep.build(context, deviceSession);
        } catch (Exception e) {
            LOG.error(e);
            return false;
        }
    });
}
Also used : IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) ExperimentScope(com.google.idea.blaze.base.experiments.ExperimentScope) ApkProvisionException(com.android.tools.idea.run.ApkProvisionException) ExecutionException(com.intellij.execution.ExecutionException) Project(com.intellij.openapi.project.Project) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) 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 5 with IdeaLogScope

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

the class NewBlazeRuleAction method actionPerformedInBlazeProject.

@Override
protected void actionPerformedInBlazeProject(Project project, AnActionEvent event) {
    final VirtualFile virtualFile = event.getData(CommonDataKeys.VIRTUAL_FILE);
    if (virtualFile == null) {
        return;
    }
    Scope.root(context -> {
        context.push(new ExperimentScope()).push(new BlazeConsoleScope.Builder(project).build()).push(new IssuesScope(project, true)).push(new IdeaLogScope());
        NewBlazeRuleDialog newBlazeRuleDialog = new NewBlazeRuleDialog(project, virtualFile);
        newBlazeRuleDialog.show();
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) ExperimentScope(com.google.idea.blaze.base.experiments.ExperimentScope) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope)

Aggregations

IdeaLogScope (com.google.idea.blaze.base.scope.scopes.IdeaLogScope)6 IssuesScope (com.google.idea.blaze.base.scope.scopes.IssuesScope)6 ExperimentScope (com.google.idea.blaze.base.experiments.ExperimentScope)5 IssueOutputFilter (com.google.idea.blaze.base.issueparser.IssueOutputFilter)5 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)4 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)3 BlazeConsoleScope (com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope)3 BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)2 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)2 BlazeConsolePopupBehavior (com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior)2 Project (com.intellij.openapi.project.Project)2 ApkProvisionException (com.android.tools.idea.run.ApkProvisionException)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 LineProcessingOutputStream (com.google.idea.blaze.base.async.process.LineProcessingOutputStream)1 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)1 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)1 BlazeTargetFilter (com.google.idea.blaze.base.run.filter.BlazeTargetFilter)1 LineProcessingProcessAdapter (com.google.idea.blaze.base.run.processhandler.LineProcessingProcessAdapter)1 ScopedBlazeProcessHandler (com.google.idea.blaze.base.run.processhandler.ScopedBlazeProcessHandler)1