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));
}
});
}
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;
}
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;
});
}
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;
}
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;
}
Aggregations