Search in sources :

Example 1 with BlazeConsolePopupBehavior

use of com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior in project intellij by bazelbuild.

the class FastBuildServiceImpl method buildDeployJar.

private ListenableFuture<FastBuildState.BuildOutput> buildDeployJar(Label label, FastBuildParameters buildParameters) {
    Label deployJarLabel = createDeployJarLabel(label);
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    // TODO(plumpy): this assumes we're running this build as part of a run action. I try not to
    // make that assumption anywhere else, so this should be supplied by the caller.
    BlazeConsolePopupBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction() ? BlazeConsolePopupBehavior.NEVER : BlazeConsolePopupBehavior.ALWAYS;
    AspectStrategy aspectStrategy = AspectStrategyProvider.findAspectStrategy(projectDataManager.getBlazeProjectData().blazeVersionData);
    BuildResultHelper buildResultHelper = BuildResultHelper.forFiles(file -> file.endsWith(deployJarLabel.targetName().toString()) || aspectStrategy.getAspectOutputFilePredicate().test(file));
    ListenableFuture<BuildResult> buildResultFuture = ProgressiveTaskWithProgressIndicator.builder(project).submitTaskWithResult(new ScopedTask<BuildResult>() {

        @Override
        protected BuildResult execute(BlazeContext context) {
            context.push(new IssuesScope(project, /* focusProblemsViewOnIssue */
            true)).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, workspaceRoot, BlazeInvocationContext.NonSync, true)).build());
            context.output(new StatusOutput("Building base deploy jar for fast builds: " + deployJarLabel.targetName()));
            BlazeCommand.Builder command = BlazeCommand.builder(buildParameters.blazeBinary(), BlazeCommandName.BUILD).addTargets(label).addTargets(deployJarLabel).addBlazeFlags(buildParameters.blazeFlags()).addBlazeFlags(buildResultHelper.getBuildFlags());
            List<String> outputGroups = new ArrayList<>();
            // needed to retrieve the deploy jar
            outputGroups.add("default");
            outputGroups.addAll(aspectStrategy.getOutputGroups(OutputGroup.INFO, ImmutableSet.of(LanguageClass.JAVA)));
            aspectStrategy.addAspectAndOutputGroups(command, outputGroups);
            int exitCode = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
            return BuildResult.fromExitCode(exitCode);
        }
    });
    ListenableFuture<BuildOutput> buildOutputFuture = transform(buildResultFuture, result -> {
        if (result.status != Status.SUCCESS) {
            throw new RuntimeException("Blaze failure building deploy jar");
        }
        ImmutableList<File> deployJarArtifacts = buildResultHelper.getBuildArtifactsForTarget(deployJarLabel);
        checkState(deployJarArtifacts.size() == 1);
        File deployJar = deployJarArtifacts.get(0);
        ImmutableList<File> ideInfoFiles = buildResultHelper.getArtifactsForOutputGroups(aspectStrategy.getOutputGroups(OutputGroup.INFO, ImmutableSet.of(LanguageClass.JAVA)));
        ImmutableMap<TargetKey, TargetIdeInfo> targetMap = ideInfoFiles.stream().map(file -> readTargetIdeInfo(aspectStrategy, file)).filter(Objects::nonNull).collect(toImmutableMap(ideInfo -> ideInfo.key, i -> i));
        return BuildOutput.create(deployJar, new TargetMap(targetMap));
    }, ConcurrencyUtil.getAppExecutorService());
    buildOutputFuture.addListener(buildResultHelper::close, ConcurrencyUtil.getAppExecutorService());
    return buildOutputFuture;
}
Also used : ExternalTask(com.google.idea.blaze.base.async.process.ExternalTask) InvokeAfterUpdateMode(com.intellij.openapi.vcs.changes.InvokeAfterUpdateMode) ModalityState(com.intellij.openapi.application.ModalityState) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) ProjectViewManager(com.google.idea.blaze.base.projectview.ProjectViewManager) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Future(java.util.concurrent.Future) ScopedTask(com.google.idea.blaze.base.scope.ScopedTask) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) ProjectManager(com.intellij.openapi.project.ProjectManager) FileUtil(com.intellij.openapi.util.io.FileUtil) GuavaHelper.toImmutableMap(com.google.idea.common.guava.GuavaHelper.toImmutableMap) ConcurrencyUtil(com.google.idea.common.concurrency.ConcurrencyUtil) BlazeConsoleLineProcessorProvider(com.google.idea.blaze.base.console.BlazeConsoleLineProcessorProvider) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) BuildOutput(com.google.idea.blaze.java.fastbuild.FastBuildState.BuildOutput) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AspectStrategy(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) CancellationException(java.util.concurrent.CancellationException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) Preconditions.checkState(com.google.common.base.Preconditions.checkState) BlazeCommandName(com.google.idea.blaze.base.command.BlazeCommandName) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) List(java.util.List) LineProcessingOutputStream(com.google.idea.blaze.base.async.process.LineProcessingOutputStream) Status(com.google.idea.blaze.base.sync.aspects.BuildResult.Status) Stream(java.util.stream.Stream) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AspectStrategyProvider(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategyProvider) ContentRevision(com.intellij.openapi.vcs.changes.ContentRevision) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Kind(com.google.idea.blaze.base.model.primitives.Kind) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope) ImmutableList(com.google.common.collect.ImmutableList) OutputGroup(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy.OutputGroup) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeConsolePopupBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior) Project(com.intellij.openapi.project.Project) Nullable(javax.annotation.Nullable) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) Files(java.nio.file.Files) Executor(java.util.concurrent.Executor) IOException(java.io.IOException) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) Futures(com.google.common.util.concurrent.Futures) Label(com.google.idea.blaze.base.model.primitives.Label) BlazeUserSettings(com.google.idea.blaze.base.settings.BlazeUserSettings) BlazeFlags(com.google.idea.blaze.base.command.BlazeFlags) ProgressiveTaskWithProgressIndicator(com.google.idea.blaze.base.async.executor.ProgressiveTaskWithProgressIndicator) BlazeInvocationContext(com.google.idea.blaze.base.command.BlazeInvocationContext) IdeInfoFromProtobuf(com.google.idea.blaze.base.sync.aspects.IdeInfoFromProtobuf) BlazeCommand(com.google.idea.blaze.base.command.BlazeCommand) Label(com.google.idea.blaze.base.model.primitives.Label) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BlazeConsoleScope(com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BuildOutput(com.google.idea.blaze.java.fastbuild.FastBuildState.BuildOutput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) IssuesScope(com.google.idea.blaze.base.scope.scopes.IssuesScope) AspectStrategy(com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) File(java.io.File) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) BlazeConsolePopupBehavior(com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior)

Example 2 with BlazeConsolePopupBehavior

use of com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior 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 3 with BlazeConsolePopupBehavior

use of com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior in project intellij by bazelbuild.

the class BlazeBeforeRunCommandHelper method runBlazeBuild.

/**
 * Kicks off the blaze build task, returning a corresponding {@link ListenableFuture}.
 */
public static ListenableFuture<BuildResult> runBlazeBuild(BlazeCommandRunConfiguration configuration, BuildResultHelper buildResultHelper, List<String> requiredExtraBlazeFlags, List<String> overridableExtraBlazeFlags, String progressMessage) {
    Project project = configuration.getProject();
    BlazeCommandRunConfigurationCommonState handlerState = (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
    WorkspaceRoot workspaceRoot = WorkspaceRoot.fromProject(project);
    ProjectViewSet projectViewSet = ProjectViewManager.getInstance(project).getProjectViewSet();
    String binaryPath = handlerState.getBlazeBinaryState().getBlazeBinary() != null ? handlerState.getBlazeBinaryState().getBlazeBinary() : Blaze.getBuildSystemProvider(project).getBinaryPath();
    BlazeConsolePopupBehavior consolePopupBehavior = BlazeUserSettings.getInstance().getSuppressConsoleForRunAction() ? BlazeConsolePopupBehavior.NEVER : BlazeConsolePopupBehavior.ALWAYS;
    return ProgressiveTaskWithProgressIndicator.builder(project).submitTaskWithResult(new ScopedTask<BuildResult>() {

        @Override
        protected BuildResult execute(BlazeContext context) {
            context.push(new IssuesScope(project, true)).push(new BlazeConsoleScope.Builder(project).setPopupBehavior(consolePopupBehavior).addConsoleFilters(new IssueOutputFilter(project, workspaceRoot, BlazeInvocationContext.NonSync, true)).build());
            context.output(new StatusOutput(progressMessage));
            BlazeCommand.Builder command = BlazeCommand.builder(binaryPath, BlazeCommandName.BUILD).addTargets(configuration.getTarget()).addBlazeFlags(overridableExtraBlazeFlags).addBlazeFlags(BlazeFlags.blazeFlags(project, projectViewSet, BlazeCommandName.BUILD, BlazeInvocationContext.NonSync)).addBlazeFlags(handlerState.getBlazeFlagsState().getExpandedFlags()).addBlazeFlags(requiredExtraBlazeFlags).addBlazeFlags(buildResultHelper.getBuildFlags());
            int exitCode = ExternalTask.builder(workspaceRoot).addBlazeCommand(command.build()).context(context).stderr(LineProcessingOutputStream.of(BlazeConsoleLineProcessorProvider.getAllStderrLineProcessors(context))).build().run();
            return BuildResult.fromExitCode(exitCode);
        }
    });
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) IssueOutputFilter(com.google.idea.blaze.base.issueparser.IssueOutputFilter) StatusOutput(com.google.idea.blaze.base.scope.output.StatusOutput) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Project(com.intellij.openapi.project.Project) BuildResult(com.google.idea.blaze.base.sync.aspects.BuildResult) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) 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 4 with BlazeConsolePopupBehavior

use of com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior 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)

Aggregations

IssueOutputFilter (com.google.idea.blaze.base.issueparser.IssueOutputFilter)4 BlazeConsoleScope (com.google.idea.blaze.base.scope.scopes.BlazeConsoleScope)4 IssuesScope (com.google.idea.blaze.base.scope.scopes.IssuesScope)4 BlazeConsolePopupBehavior (com.google.idea.blaze.base.settings.BlazeUserSettings.BlazeConsolePopupBehavior)4 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)3 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)3 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)3 BlazeCommand (com.google.idea.blaze.base.command.BlazeCommand)2 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)2 ExperimentScope (com.google.idea.blaze.base.experiments.ExperimentScope)2 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)2 ScopedTask (com.google.idea.blaze.base.scope.ScopedTask)2 StatusOutput (com.google.idea.blaze.base.scope.output.StatusOutput)2 IdeaLogScope (com.google.idea.blaze.base.scope.scopes.IdeaLogScope)2 BuildResult (com.google.idea.blaze.base.sync.aspects.BuildResult)2 Project (com.intellij.openapi.project.Project)2 ApkProvisionException (com.android.tools.idea.run.ApkProvisionException)1 Function (com.google.common.base.Function)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1