use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeCidrTestConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
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;
}
sourceElement.set(test.getPsiElement());
configuration.setTargetInfo(target);
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
ImmutableList.Builder<String> flags = ImmutableList.builder();
String testFilter = test.getTestFilterFlag();
if (testFilter != null) {
flags.add(testFilter);
}
flags.addAll(handlerState.getBlazeFlagsState().getRawFlags());
handlerState.getBlazeFlagsState().setRawFlags(flags.build());
configuration.setName(String.format("%s test: %s", Blaze.buildSystemName(configuration.getProject()), getTestName(target.label, test.gtest)));
return true;
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeJavaMainClassRunConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
PsiClass mainClass = getMainClass(context);
if (mainClass == null) {
return false;
}
// Try setting source element to a main method so ApplicationConfigurationProducer
// can't override our configuration by producing a more specific one.
PsiMethod mainMethod = PsiMethodUtil.findMainMethod(mainClass);
if (mainMethod == null) {
sourceElement.set(mainClass);
} else {
sourceElement.set(mainMethod);
}
TargetIdeInfo target = getTarget(context.getProject(), mainClass);
if (target == null) {
return false;
}
configuration.setTargetInfo(target.toTargetInfo());
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
handlerState.getCommandState().setCommand(BlazeCommandName.RUN);
configuration.setGeneratedName();
return true;
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeJavaMainClassRunConfigurationProducer 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.RUN)) {
return false;
}
PsiClass mainClass = getMainClass(context);
if (mainClass == null) {
return false;
}
TargetIdeInfo target = getTarget(context.getProject(), mainClass);
if (target == null) {
return false;
}
return Objects.equals(configuration.getTarget(), target.key.label);
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class MultipleJavaClassesTestConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
TestLocation location = getTestLocation(context);
if (location == null) {
return false;
}
sourceElement.set(location.psiLocation);
configuration.setTargetInfo(location.target);
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
// remove old test filter flag if present
List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
if (location.testFilter != null) {
flags.add(location.testFilter);
}
handlerState.getBlazeFlagsState().setRawFlags(flags);
if (location.description != null) {
BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
nameBuilder.setTargetString(location.description);
configuration.setName(nameBuilder.build());
// don't revert to generated name
configuration.setNameChangedByUser(true);
} else {
configuration.setGeneratedName();
}
return true;
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeJavaRunProfileStateTest method flagsShouldBeAppendedIfPresent.
@Test
public void flagsShouldBeAppendedIfPresent() {
configuration.setTargetInfo(TargetInfo.builder(Label.create("//label:rule"), "java_test").build());
BlazeCommandRunConfigurationCommonState handlerState = (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
handlerState.getCommandState().setCommand(BlazeCommandName.fromString("command"));
handlerState.getBlazeFlagsState().setRawFlags(ImmutableList.of("--flag1", "--flag2"));
assertThat(BlazeJavaRunProfileState.getBlazeCommandBuilder(project, configuration, ImmutableList.of(), ExecutorType.RUN).build().toList()).isEqualTo(ImmutableList.of("/usr/bin/blaze", "command", BlazeFlags.getToolTagFlag(), "--flag1", "--flag2", "--", "//label:rule"));
}
Aggregations