use of com.google.idea.blaze.base.scope.scopes.ProblemsViewScope in project intellij by bazelbuild.
the class BlazeAndroidRunConfigurationRunner method executeBeforeRunTask.
@Override
public boolean executeBeforeRunTask(ExecutionEnvironment env) {
final Project project = env.getProject();
BlazeUserSettings settings = BlazeUserSettings.getInstance();
return Scope.root(context -> {
context.push(new ProblemsViewScope(project, settings.getShowProblemsViewOnRun())).push(new ExperimentScope()).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(settings.getShowBlazeConsoleOnRun()).addConsoleFilters(new IssueOutputFilter(project, WorkspaceRoot.fromProject(project), BlazeInvocationContext.ContextType.BeforeRunTask, true)).build()).push(new ToolWindowScope.Builder(project, new Task(project, "Build apk", Task.Type.BEFORE_LAUNCH)).setPopupBehavior(settings.getShowBlazeConsoleOnRun()).setIssueParsers(BlazeIssueParser.defaultIssueParsers(project, WorkspaceRoot.fromProject(project), ContextType.BeforeRunTask)).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);
ApkBuildStep buildStep = runContext.getBuildStep();
ScopedTask<Void> buildTask = new ScopedTask<Void>(context) {
@Override
protected Void execute(BlazeContext context) {
buildStep.build(context, deviceSession);
return null;
}
};
try {
ListenableFuture<Void> buildFuture = ProgressiveTaskWithProgressIndicator.builder(project, String.format("Executing %s apk build", Blaze.buildSystemName(project))).submitTaskWithResult(buildTask);
Futures.getChecked(buildFuture, ExecutionException.class);
} catch (ExecutionException e) {
context.setHasError();
} catch (CancellationException e) {
context.setCancelled();
} catch (Exception e) {
LOG.error(e);
return false;
}
return context.shouldContinue();
});
}
use of com.google.idea.blaze.base.scope.scopes.ProblemsViewScope in project intellij by bazelbuild.
the class FastBuildConfigurationRunner method executeBeforeRunTask.
@Override
public boolean executeBeforeRunTask(ExecutionEnvironment env) {
if (!canRun(env.getRunProfile())) {
return true;
}
Project project = env.getProject();
BlazeCommandRunConfiguration configuration = BlazeCommandRunConfigurationRunner.getBlazeConfig(env.getRunProfile());
BlazeCommandRunConfigurationCommonState handlerState = (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
checkState(configuration.getSingleTarget() != null);
Label label = (Label) configuration.getSingleTarget();
String binaryPath = handlerState.getBlazeBinaryState().getBlazeBinary() != null ? handlerState.getBlazeBinaryState().getBlazeBinary() : Blaze.getBuildSystemProvider(project).getBinaryPath(project);
SaveUtil.saveAllFiles();
FastBuildService buildService = FastBuildService.getInstance(project);
Future<FastBuildInfo> buildFuture = null;
FocusBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getShowBlazeConsoleOnRun();
FocusBehavior problemsViewFocus = BlazeUserSettings.getInstance().getShowProblemsViewOnRun();
BlazeContext context = BlazeContext.create().push(new ToolWindowScope.Builder(project, new Task(project, "Fast Build " + label.targetName(), Task.Type.FAST_BUILD)).setPopupBehavior(consolePopupBehavior).setIssueParsers(BlazeIssueParser.defaultIssueParsers(project, WorkspaceRoot.fromProject(project), ContextType.RunConfiguration)).build()).push(new ProblemsViewScope(project, problemsViewFocus)).push(new IdeaLogScope()).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, WorkspaceRoot.fromProject(project), ContextType.RunConfiguration, /* linkToBlazeConsole= */
true)).build()).push(new FastBuildLogDataScope());
try {
buildFuture = buildService.createBuild(context, label, binaryPath, handlerState.getBlazeFlagsState().getFlagsForExternalProcesses());
FastBuildInfo fastBuildInfo = buildFuture.get();
env.getCopyableUserData(BUILD_INFO_KEY).set(fastBuildInfo);
env.getCopyableUserData(BLAZE_CONTEXT).set(context);
return true;
} catch (InterruptedException e) {
buildFuture.cancel(/* mayInterruptIfRunning= */
true);
Thread.currentThread().interrupt();
} catch (CancellationException e) {
ExecutionUtil.handleExecutionError(env.getProject(), env.getExecutor().getToolWindowId(), env.getRunProfile(), new RunCanceledByUserException());
} catch (FastBuildException e) {
if (!(e instanceof BlazeBuildError)) {
// no need to log blaze build errors; they're expected
logger.warn(e);
}
ExecutionUtil.handleExecutionError(env, new ExecutionException(e));
} catch (java.util.concurrent.ExecutionException e) {
logger.warn(e);
if (e.getCause() instanceof FastBuildIncrementalCompileException) {
handleJavacError(env, project, label, buildService, (FastBuildIncrementalCompileException) e.getCause());
} else {
ExecutionUtil.handleExecutionError(env, new ExecutionException(e.getCause()));
}
}
// Fall-through for all exceptions. If no exception was thrown, we return from the try{} block.
context.endScope();
return false;
}
use of com.google.idea.blaze.base.scope.scopes.ProblemsViewScope in project intellij by bazelbuild.
the class BlazeCidrLauncher method createProcess.
private ProcessHandler createProcess(CommandLineState state, List<String> extraBlazeFlags) throws ExecutionException {
ImmutableList<String> testHandlerFlags = ImmutableList.of();
BlazeTestUiSession testUiSession = useTestUi() ? TestUiSessionProvider.getInstance(project).getTestUiSession(configuration.getTargets()) : null;
if (testUiSession != null) {
testHandlerFlags = testUiSession.getBlazeFlags();
}
ProjectViewSet projectViewSet = Preconditions.checkNotNull(ProjectViewManager.getInstance(project).getProjectViewSet());
if (shouldDisplayBazelTestFilterWarning()) {
String messageContents = "<html>The Google Test framework did not apply test filtering correctly before " + "git commit <a href='https://github.com/google/googletest/commit/" + "ba96d0b1161f540656efdaed035b3c062b60e006" + "'>ba96d0b<a>.<br/>" + "Please ensure you are past this commit if you are using it.<br/><br/>" + "More information on the bazel <a href='https://github.com/bazelbuild/bazel/issues/" + "4411'>issue</a></html>";
int selectedOption = Messages.showDialog(getProject(), messageContents, "Please update 'Google Test' past ba96d0b...", new String[] { "Close", "Don't show again" }, // Default to "Close"
0, Messages.getWarningIcon());
if (selectedOption == 1) {
PropertiesComponent.getInstance().setValue(DISABLE_BAZEL_GOOGLETEST_FILTER_WARNING, "true");
}
}
BlazeCommand.Builder commandBuilder = BlazeCommand.builder(Blaze.getBuildSystemProvider(project).getBinaryPath(project), handlerState.getCommandState().getCommand()).addTargets(configuration.getTargets()).addBlazeFlags(extraBlazeFlags).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, handlerState.getCommandState().getCommand(), BlazeContext.create(), BlazeInvocationContext.runConfigContext(ExecutorType.fromExecutor(env.getExecutor()), configuration.getType(), false))).addBlazeFlags(testHandlerFlags).addBlazeFlags(handlerState.getBlazeFlagsState().getFlagsForExternalProcesses()).addExeFlags(handlerState.getExeFlagsState().getFlagsForExternalProcesses());
state.setConsoleBuilder(createConsoleBuilder(testUiSession));
state.addConsoleFilters(getConsoleFilters().toArray(new Filter[0]));
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
final BlazeCommand command = commandBuilder.build();
return new ScopedBlazeProcessHandler(project, command, workspaceRoot, new ScopedBlazeProcessHandler.ScopedProcessHandlerDelegate() {
@Override
public void onBlazeContextStart(BlazeContext context) {
context.push(new ProblemsViewScope(project, BlazeUserSettings.getInstance().getShowProblemsViewOnRun()));
}
@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.scope.scopes.ProblemsViewScope 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;
}
BlazeUserSettings userSettings = BlazeUserSettings.getInstance();
return Scope.root(context -> {
WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
context.push(new ExperimentScope()).push(new ProblemsViewScope(project, userSettings.getShowProblemsViewOnRun())).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(userSettings.getShowBlazeConsoleOnRun()).addConsoleFilters(new IssueOutputFilter(project, workspaceRoot, ContextType.BeforeRunTask, true)).build()).push(new ToolWindowScope.Builder(project, new com.google.idea.blaze.base.toolwindow.Task(project, "Build Plugin Jar", com.google.idea.blaze.base.toolwindow.Task.Type.BEFORE_LAUNCH)).setPopupBehavior(userSettings.getShowBlazeConsoleOnRun()).setIssueParsers(BlazeIssueParser.defaultIssueParsers(project, WorkspaceRoot.fromProject(project), ContextType.BeforeRunTask)).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(project);
BlazeIntellijPluginConfiguration config = (BlazeIntellijPluginConfiguration) configuration;
ListenableFuture<String> executionRootFuture = BlazeInfoRunner.getInstance().runBlazeInfo(context, binaryPath, workspaceRoot, config.getBlazeFlagsState().getFlagsForExternalProcesses(), 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;
}
// expects the outputs to be available locally
try (BuildResultHelper buildResultHelper = BuildResultHelperProvider.createForLocalBuild(project)) {
BlazeCommand command = BlazeCommand.builder(binaryPath, BlazeCommandName.BUILD).addTargets(config.getTargets()).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.BUILD, context, BlazeInvocationContext.runConfigContext(ExecutorType.fromExecutor(env.getExecutor()), config.getType(), true))).addBlazeFlags(config.getBlazeFlagsState().getFlagsForExternalProcesses()).addExeFlags(config.getExeFlagsState().getFlagsForExternalProcesses()).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();
}
ListenableFuture<Void> unusedFuture = FileCaches.refresh(project, context, BlazeBuildOutputs.noOutputs(BuildResult.fromExitCode(retVal)));
try {
deployer.reportBuildComplete(new File(executionRoot), buildResultHelper);
} catch (GetArtifactsException e) {
IssueOutput.error("Failed to get build artifacts: " + e.getMessage()).submit(context);
return null;
}
return null;
}
}
};
ListenableFuture<Void> buildFuture = ProgressiveTaskWithProgressIndicator.builder(project, "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.scope.scopes.ProblemsViewScope in project intellij by bazelbuild.
the class SyncPhaseCoordinator method setupScopes.
/**
* Sets up the root {@link BlazeContext} for the given {@link SyncPhase}.
*/
private void setupScopes(BlazeSyncParams syncParams, BlazeContext context, ProgressIndicator indicator, SyncPhase phase, Task task, boolean startTaskOnScopeBegin) {
boolean clearProblems = phase != SyncPhase.PROJECT_UPDATE;
boolean notifyFinished = phase != SyncPhase.BUILD;
context.push(new ExperimentScope());
if (BlazeUserSettings.getInstance().getShowPerformanceWarnings()) {
context.push(new PerformanceWarningScope());
}
context.push(new ProgressIndicatorScope(indicator));
BlazeUserSettings userSettings = BlazeUserSettings.getInstance();
context.push(new ToolWindowScope.Builder(project, task).setStartTaskOnScopeBegin(startTaskOnScopeBegin).setProgressIndicator(indicator).setPopupBehavior(syncParams.backgroundSync() ? FocusBehavior.NEVER : userSettings.getShowBlazeConsoleOnSync()).setIssueParsers(BlazeIssueParser.defaultIssueParsers(project, WorkspaceRoot.fromProject(project), ContextType.Sync)).build()).push(new BlazeConsoleScope.Builder(project, indicator).setPopupBehavior(syncParams.backgroundSync() ? FocusBehavior.NEVER : userSettings.getShowBlazeConsoleOnSync()).addConsoleFilters(new IssueOutputFilter(project, WorkspaceRoot.fromProject(project), ContextType.Sync, true)).setClearPreviousState(clearProblems).build()).push(new ProblemsViewScope(project, syncParams.backgroundSync() ? FocusBehavior.NEVER : userSettings.getShowProblemsViewOnSync(), /* resetProblemsContext= */
clearProblems)).push(new IdeaLogScope());
if (notifyFinished && !syncParams.backgroundSync() && syncParams.syncMode() != SyncMode.NO_BUILD) {
context.push(new NotificationScope(project, "Sync", "Sync project", "Sync successful", "Sync failed"));
}
context.output(new StatusOutput(String.format("Syncing project: %s...", syncParams)));
}
Aggregations