use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState 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);
}
});
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeBuildTargetRunConfigurationFactory method setupConfiguration.
@Override
public void setupConfiguration(RunConfiguration configuration, Label label) {
BlazeCommandRunConfiguration blazeConfig = (BlazeCommandRunConfiguration) configuration;
TargetInfo target = findProjectTarget(configuration.getProject(), label);
blazeConfig.setTargetInfo(target);
if (target == null) {
return;
}
BlazeCommandRunConfigurationCommonState state = blazeConfig.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (state != null) {
state.getCommandState().setCommand(commandForRuleType(target.getRuleType()));
}
blazeConfig.setGeneratedName();
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class RunConfigurationUtils method canUseClionRunner.
static boolean canUseClionRunner(BlazeCommandRunConfiguration config) {
Kind kind = config.getTargetKind();
BlazeCommandRunConfigurationCommonState handlerState = config.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
BlazeCommandName command = handlerState.getCommandState().getCommand();
return kind != null && command != null && ((kind == Kind.CC_TEST && command.equals(BlazeCommandName.TEST)) || (kind == Kind.CC_BINARY && command.equals(BlazeCommandName.RUN)));
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeCidrTestConfigurationProducer method doIsConfigFromContext.
@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
if (!Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.TEST)) {
return false;
}
PsiElement element = selectedPsiElement(context);
if (element == null) {
return false;
}
GoogleTestLocation test = GoogleTestLocation.findGoogleTest(element);
if (test == null) {
return false;
}
TargetInfo target = getTestTarget(test.getPsiElement());
if (target == null) {
return false;
}
return target.label.equals(configuration.getTarget()) && Objects.equals(handlerState.getTestFilterFlag(), test.getTestFilterFlag());
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeJavaTestMethodConfigurationProducerTest method testConfigWithDifferentFilterIgnored.
@Test
public void testConfigWithDifferentFilterIgnored() {
// Arrange
PsiMethod method = setupGenericJunitTestClassAndBlazeTarget();
ConfigurationContext context = createContextFromPsi(method);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) context.getConfiguration().getConfiguration();
BlazeCommandRunConfigurationCommonState handlerState = config.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
// modify the test filter, and check that is enough for the producer to class it as different.
List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
flags.add(BlazeFlags.TEST_FILTER + "=com.google.test.DifferentTestClass#");
handlerState.getBlazeFlagsState().setRawFlags(flags);
// Act
boolean isConfigFromContext = new BlazeJavaTestMethodConfigurationProducer().doIsConfigFromContext(config, context);
// Assert
assertThat(isConfigFromContext).isFalse();
}
Aggregations