Search in sources :

Example 1 with FastBuildInfo

use of com.google.idea.blaze.java.fastbuild.FastBuildInfo 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;
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) Task(com.google.idea.blaze.base.toolwindow.Task) Label(com.google.idea.blaze.base.model.primitives.Label) FastBuildService(com.google.idea.blaze.java.fastbuild.FastBuildService) RunCanceledByUserException(com.intellij.execution.RunCanceledByUserException) FastBuildLogDataScope(com.google.idea.blaze.java.fastbuild.FastBuildLogDataScope) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) FastBuildException(com.google.idea.blaze.java.fastbuild.FastBuildException) ExecutionException(com.intellij.execution.ExecutionException) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) FastBuildIncrementalCompileException(com.google.idea.blaze.java.fastbuild.FastBuildIncrementalCompileException) FocusBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior) Project(com.intellij.openapi.project.Project) IdeaLogScope(com.google.idea.blaze.base.scope.scopes.IdeaLogScope) FastBuildInfo(com.google.idea.blaze.java.fastbuild.FastBuildInfo) ProblemsViewScope(com.google.idea.blaze.base.scope.scopes.ProblemsViewScope) CancellationException(java.util.concurrent.CancellationException) BlazeBuildError(com.google.idea.blaze.java.fastbuild.FastBuildException.BlazeBuildError)

Aggregations

IssueOutputFilter (com.google.idea.blaze.base.issueparser.IssueOutputFilter)1 Label (com.google.idea.blaze.base.model.primitives.Label)1 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)1 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)1 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)1 BlazeConsoleScope (com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope)1 IdeaLogScope (com.google.idea.blaze.base.scope.scopes.IdeaLogScope)1 ProblemsViewScope (com.google.idea.blaze.base.scope.scopes.ProblemsViewScope)1 FocusBehavior (com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior)1 Task (com.google.idea.blaze.base.toolwindow.Task)1 FastBuildException (com.google.idea.blaze.java.fastbuild.FastBuildException)1 BlazeBuildError (com.google.idea.blaze.java.fastbuild.FastBuildException.BlazeBuildError)1 FastBuildIncrementalCompileException (com.google.idea.blaze.java.fastbuild.FastBuildIncrementalCompileException)1 FastBuildInfo (com.google.idea.blaze.java.fastbuild.FastBuildInfo)1 FastBuildLogDataScope (com.google.idea.blaze.java.fastbuild.FastBuildLogDataScope)1 FastBuildService (com.google.idea.blaze.java.fastbuild.FastBuildService)1 ExecutionException (com.intellij.execution.ExecutionException)1 RunCanceledByUserException (com.intellij.execution.RunCanceledByUserException)1 Project (com.intellij.openapi.project.Project)1 CancellationException (java.util.concurrent.CancellationException)1