Search in sources :

Example 46 with BlazeCommandRunConfigurationCommonState

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;
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) ArrayList(java.util.ArrayList) BlazeConfigurationNameBuilder(com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder)

Example 47 with BlazeCommandRunConfigurationCommonState

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());
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)

Example 48 with BlazeCommandRunConfigurationCommonState

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());
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)

Example 49 with BlazeCommandRunConfigurationCommonState

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);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) BlazeCommandRunConfigurationSettingsEditor(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration.BlazeCommandRunConfigurationSettingsEditor) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) Test(org.junit.Test)

Example 50 with BlazeCommandRunConfigurationCommonState

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);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) BlazeCommandRunConfigurationSettingsEditor(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration.BlazeCommandRunConfigurationSettingsEditor) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression) Test(org.junit.Test)

Aggregations

BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)52 TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)10 BlazeConfigurationNameBuilder (com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder)9 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)8 PsiFile (com.intellij.psi.PsiFile)8 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)6 PsiElement (com.intellij.psi.PsiElement)6 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)5 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)4 PsiMethod (com.intellij.psi.PsiMethod)4 PyFile (com.jetbrains.python.psi.PyFile)4 BlazeCommandName (com.google.idea.blaze.base.command.BlazeCommandName)3 TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)3 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)3 PsiClass (com.intellij.psi.PsiClass)3 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)2 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)2 Kind (com.google.idea.blaze.base.model.primitives.Kind)2