Search in sources :

Example 1 with BlazeCommand

use of com.google.idea.blaze.base.command.BlazeCommand 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 2 with BlazeCommand

use of com.google.idea.blaze.base.command.BlazeCommand in project intellij by bazelbuild.

the class BlazeJavaRunProfileState method getBlazeCommandBuilder.

@VisibleForTesting
static BlazeCommand.Builder getBlazeCommandBuilder(Project project, BlazeCommandRunConfiguration configuration, List<String> extraBlazeFlags, ExecutorType executorType) {
    List<String> blazeFlags = new ArrayList<>(extraBlazeFlags);
    ProjectViewSet projectViewSet = Preconditions.checkNotNull(ProjectViewManager.getInstance(project).getProjectViewSet());
    BlazeJavaRunConfigState handlerState = getState(configuration);
    String binaryPath = handlerState.getBlazeBinaryState().getBlazeBinary() != null ? handlerState.getBlazeBinaryState().getBlazeBinary() : Blaze.getBuildSystemProvider(project).getBinaryPath();
    BlazeCommandName blazeCommand = Preconditions.checkNotNull(handlerState.getCommandState().getCommand());
    if (executorType == ExecutorType.COVERAGE) {
        blazeCommand = BlazeCommandName.COVERAGE;
        blazeFlags.addAll(CoverageUtils.getBlazeFlags());
    }
    BlazeCommand.Builder command = BlazeCommand.builder(binaryPath, blazeCommand).addTargets(configuration.getTarget()).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, blazeCommand, BlazeInvocationContext.NonSync)).addBlazeFlags(blazeFlags).addBlazeFlags(handlerState.getBlazeFlagsState().getExpandedFlags());
    if (executorType == ExecutorType.DEBUG) {
        Kind kind = configuration.getTargetKind();
        boolean isBinary = kind != null && kind.ruleType == RuleType.BINARY;
        int debugPort = handlerState.getDebugPortState().port;
        if (isBinary) {
            command.addExeFlags(debugPortFlag(false, debugPort));
        } else {
            command.addBlazeFlags(BlazeFlags.JAVA_TEST_DEBUG);
            command.addBlazeFlags(debugPortFlag(true, debugPort));
        }
    }
    command.addExeFlags(handlerState.getExeFlagsState().getExpandedFlags());
    return command;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) Kind(com.google.idea.blaze.base.model.primitives.Kind) ArrayList(java.util.ArrayList) BlazeCommandName(com.google.idea.blaze.base.command.BlazeCommandName) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with BlazeCommand

use of com.google.idea.blaze.base.command.BlazeCommand 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 BlazeCommand

use of com.google.idea.blaze.base.command.BlazeCommand in project intellij by bazelbuild.

the class BlazeAndroidTestLaunchTask method perform.

@Override
public boolean perform(@NotNull IDevice device, @NotNull LaunchStatus launchStatus, @NotNull ConsolePrinter printer) {
    BlazeExecutor executor = BlazeExecutor.getInstance();
    ProcessHandlerLaunchStatus processHandlerLaunchStatus = (ProcessHandlerLaunchStatus) launchStatus;
    final ProcessHandler processHandler = processHandlerLaunchStatus.getProcessHandler();
    blazeResult = executor.submit(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return Scope.root(new ScopedFunction<Boolean>() {

                @Override
                public Boolean execute(@NotNull BlazeContext context) {
                    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
                    if (projectViewSet == null) {
                        IssueOutput.error("Could not load project view. Please resync project.").submit(context);
                        return false;
                    }
                    BlazeCommand.Builder commandBuilder = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(), BlazeCommandName.TEST).addTargets(target);
                    // Build flags must match BlazeBeforeRunTask.
                    commandBuilder.addBlazeFlags(buildFlags);
                    // Run the test on the selected local device/emulator.
                    commandBuilder.addBlazeFlags(TEST_LOCAL_DEVICE, BlazeFlags.TEST_OUTPUT_STREAMED).addBlazeFlags(testDeviceSerialFlags(device.getSerialNumber())).addBlazeFlags(testFilter.getBlazeFlags());
                    if (debug) {
                        commandBuilder.addBlazeFlags(TEST_DEBUG, BlazeFlags.NO_CACHE_TEST_RESULTS);
                    }
                    BlazeCommand command = commandBuilder.build();
                    printer.stdout(String.format("Starting %s test...\n", Blaze.buildSystemName(project)));
                    printer.stdout(command + "\n");
                    LineProcessingOutputStream.LineProcessor stdoutLineProcessor = line -> {
                        printer.stdout(line);
                        return true;
                    };
                    LineProcessingOutputStream.LineProcessor stderrLineProcessor = line -> {
                        printer.stderr(line);
                        return true;
                    };
                    SaveUtil.saveAllFiles();
                    int retVal = ExternalTask.builder(WorkspaceRoot.fromProject(project)).addBlazeCommand(command).context(context).stdout(LineProcessingOutputStream.of(stdoutLineProcessor)).stderr(LineProcessingOutputStream.of(stderrLineProcessor)).build().run();
                    FileCaches.refresh(project);
                    if (retVal != 0) {
                        context.setHasError();
                    }
                    return !context.hasErrors();
                }
            });
        }
    });
    blazeResult.addListener(runContext::onLaunchTaskComplete, PooledThreadExecutor.INSTANCE);
    // The debug case is set up in ConnectBlazeTestDebuggerTask
    if (!debug) {
        waitAndSetUpForKillingBlazeOnStop(processHandler, launchStatus);
    }
    return true;
}
Also used : ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) Callable(java.util.concurrent.Callable) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) ProcessHandlerLaunchStatus(com.android.tools.idea.run.util.ProcessHandlerLaunchStatus) ProcessHandler(com.intellij.execution.process.ProcessHandler)

Example 5 with BlazeCommand

use of com.google.idea.blaze.base.command.BlazeCommand in project intellij by bazelbuild.

the class BlazeInfoRunnerImpl method runBlazeInfo.

private static ByteArrayOutputStream runBlazeInfo(String binaryPath, WorkspaceRoot workspaceRoot, @Nullable String key, List<String> blazeFlags, BlazeContext context) throws BlazeInfoException {
    BlazeCommand.Builder builder = BlazeCommand.builder(binaryPath, BlazeCommandName.INFO);
    if (key != null) {
        builder.addBlazeFlags(key);
    }
    BlazeCommand command = builder.addBlazeFlags(blazeFlags).build();
    ByteArrayOutputStream stdout = new ByteArrayOutputStream();
    int exitCode = ExternalTask.builder(workspaceRoot).addBlazeCommand(command).context(context).stdout(stdout).stderr(LineProcessingOutputStream.of(new PrintOutputLineProcessor(context))).build().run();
    if (exitCode != 0) {
        throw new BlazeInfoException(exitCode, stdout.toString());
    }
    return stdout;
}
Also used : BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintOutputLineProcessor(com.google.idea.blaze.base.async.process.PrintOutputLineProcessor)

Aggregations

BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)5 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)3 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)3 IssueOutputFilter (com.google.idea.blaze.base.issueparser.IssueOutputFilter)2 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)2 IdeaLogScope (com.google.idea.blaze.base.scope.scopes.IdeaLogScope)2 IssuesScope (com.google.idea.blaze.base.scope.scopes.IssuesScope)2 ProcessHandlerLaunchStatus (com.android.tools.idea.run.util.ProcessHandlerLaunchStatus)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1 BlazeExecutor (com.google.idea.blaze.base.async.executor.BlazeExecutor)1 LineProcessingOutputStream (com.google.idea.blaze.base.async.process.LineProcessingOutputStream)1 PrintOutputLineProcessor (com.google.idea.blaze.base.async.process.PrintOutputLineProcessor)1 BlazeCommandName (com.google.idea.blaze.base.command.BlazeCommandName)1 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)1 ExperimentScope (com.google.idea.blaze.base.experiments.ExperimentScope)1 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)1 Kind (com.google.idea.blaze.base.model.primitives.Kind)1 BlazeTargetFilter (com.google.idea.blaze.base.run.filter.BlazeTargetFilter)1 LineProcessingProcessAdapter (com.google.idea.blaze.base.run.processhandler.LineProcessingProcessAdapter)1