use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeJavaTestMethodConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
TestMethodContext methodContext = getSelectedMethodContext(context);
if (methodContext == null) {
return false;
}
// PatternConfigurationProducer also chooses the first method as its source element.
// As long as we choose an element at the same PSI hierarchy level,
// PatternConfigurationProducer won't override our configuration.
sourceElement.set(methodContext.firstMethod);
configuration.setTargetInfo(methodContext.blazeTarget);
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));
flags.add(methodContext.testFilterFlag);
if (!flags.contains(BlazeFlags.DISABLE_TEST_SHARDING)) {
flags.add(BlazeFlags.DISABLE_TEST_SHARDING);
}
handlerState.getBlazeFlagsState().setRawFlags(flags);
BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
nameBuilder.setTargetString(String.format("%s.%s", methodContext.containingClass.getName(), String.join(",", methodContext.methodNames)));
configuration.setName(nameBuilder.build());
// don't revert to generated name
configuration.setNameChangedByUser(true);
return true;
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeJavaTestMethodConfigurationProducer 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;
}
TestMethodContext methodContext = getSelectedMethodContext(context);
return methodContext != null && handlerState.getBlazeFlagsState().getRawFlags().contains(methodContext.testFilterFlag) && methodContext.blazeTarget.label.equals(configuration.getTarget());
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class MultipleJavaClassesTestConfigurationProducer method doIsConfigFromContext.
@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
TestLocation location = getTestLocation(context);
if (location == null) {
return false;
}
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
return BlazeCommandName.TEST.equals(handlerState.getCommandState().getCommand()) && location.target.label.equals(configuration.getTarget()) && Objects.equals(location.testFilter, handlerState.getTestFilterFlag());
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeCommandRunConfigurationGenericHandlerIntegrationTest method testEditorApplyToAndResetFromHandlesNulls.
@Test
public void testEditorApplyToAndResetFromHandlesNulls() throws ConfigurationException {
BlazeCommandRunConfigurationSettingsEditor editor = new BlazeCommandRunConfigurationSettingsEditor(configuration);
// Call setTarget to initialize a generic handler, or this won't apply anything.
configuration.setTarget(null);
assertThat(configuration.getTarget()).isNull();
assertThat(configuration.getHandler()).isInstanceOf(BlazeCommandGenericRunConfigurationHandler.class);
BlazeCommandRunConfigurationCommonState state = (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
editor.resetFrom(configuration);
BlazeCommandRunConfiguration readConfiguration = type.getFactory().createTemplateConfiguration(getProject());
TargetExpression targetExpression = TargetExpression.fromStringSafe("//...");
readConfiguration.setTarget(targetExpression);
BlazeCommandRunConfigurationCommonState readState = (BlazeCommandRunConfigurationCommonState) readConfiguration.getHandler().getState();
readState.getCommandState().setCommand(COMMAND);
readState.getBlazeFlagsState().setRawFlags(ImmutableList.of("--flag1", "--flag2"));
readState.getExeFlagsState().setRawFlags(ImmutableList.of("--exeFlag1"));
readState.getBlazeBinaryState().setBlazeBinary("/usr/bin/blaze");
editor.applyEditorTo(readConfiguration);
assertThat(readConfiguration.getTarget()).isNull();
assertThat(configuration.getHandler()).isInstanceOf(BlazeCommandGenericRunConfigurationHandler.class);
readState = (BlazeCommandRunConfigurationCommonState) readConfiguration.getHandler().getState();
assertThat(readState.getCommandState().getCommand()).isEqualTo(state.getCommandState().getCommand());
assertThat(readState.getBlazeFlagsState().getRawFlags()).isEqualTo(state.getBlazeFlagsState().getRawFlags());
assertThat(readState.getExeFlagsState().getRawFlags()).isEqualTo(state.getExeFlagsState().getRawFlags());
assertThat(readState.getBlazeBinaryState().getBlazeBinary()).isEqualTo(state.getBlazeBinaryState().getBlazeBinary());
Disposer.dispose(editor);
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeCommandRunConfigurationGenericHandlerIntegrationTest method testEditorApplyToAndResetFromMatches.
@Test
public void testEditorApplyToAndResetFromMatches() throws ConfigurationException {
BlazeCommandRunConfigurationSettingsEditor editor = new BlazeCommandRunConfigurationSettingsEditor(configuration);
TargetExpression targetExpression = TargetExpression.fromStringSafe("//...");
configuration.setTarget(targetExpression);
BlazeCommandRunConfigurationCommonState state = (BlazeCommandRunConfigurationCommonState) configuration.getHandler().getState();
state.getCommandState().setCommand(COMMAND);
state.getBlazeFlagsState().setRawFlags(ImmutableList.of("--flag1", "--flag2"));
state.getExeFlagsState().setRawFlags(ImmutableList.of("--exeFlag1"));
state.getBlazeBinaryState().setBlazeBinary("/usr/bin/blaze");
editor.resetFrom(configuration);
BlazeCommandRunConfiguration readConfiguration = type.getFactory().createTemplateConfiguration(getProject());
editor.applyEditorTo(readConfiguration);
assertThat(readConfiguration.getTarget()).isEqualTo(targetExpression);
assertThat(readConfiguration.getHandler()).isInstanceOf(BlazeCommandGenericRunConfigurationHandler.class);
BlazeCommandRunConfigurationCommonState readState = (BlazeCommandRunConfigurationCommonState) readConfiguration.getHandler().getState();
assertThat(readState.getCommandState().getCommand()).isEqualTo(state.getCommandState().getCommand());
assertThat(readState.getBlazeFlagsState().getRawFlags()).isEqualTo(state.getBlazeFlagsState().getRawFlags());
assertThat(readState.getExeFlagsState().getRawFlags()).isEqualTo(state.getExeFlagsState().getRawFlags());
assertThat(readState.getBlazeBinaryState().getBlazeBinary()).isEqualTo(state.getBlazeBinaryState().getBlazeBinary());
Disposer.dispose(editor);
}
Aggregations