Search in sources :

Example 11 with BlazeCommandRunConfigurationCommonState

use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.

the class BlazeKotlinTestClassConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    TestLocation testLocation = TestLocation.from(context);
    if (testLocation == null) {
        return false;
    }
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    return handlerState != null && Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.TEST) && Objects.equals(handlerState.getTestFilterFlag(), testLocation.getTestFilterFlag()) && Objects.equals(configuration.getTarget(), testLocation.getTargetInfo().label);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)

Example 12 with BlazeCommandRunConfigurationCommonState

use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.

the class BlazeJavaTestClassConfigurationProducerTest method testConfigWithDifferentFilterIgnored.

@Test
public void testConfigWithDifferentFilterIgnored() {
    PsiFile javaFile = createAndIndexFile(new WorkspacePath("java/com/google/test/TestClass.java"), "package com.google.test;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass {", "  @org.junit.Test", "  public void testMethod() {}", "}");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/test:TestClass").addSource(sourceRoot("java/com/google/test/TestClass.java")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    ConfigurationContext context = createContextFromPsi(javaFile);
    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.OtherTestClass#");
    handlerState.getBlazeFlagsState().setRawFlags(flags);
    assertThat(new BlazeJavaTestClassConfigurationProducer().doIsConfigFromContext(config, context)).isFalse();
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Example 13 with BlazeCommandRunConfigurationCommonState

use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.

the class BlazePyBinaryConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    Location<?> location = context.getLocation();
    if (location == null) {
        return false;
    }
    PsiElement element = location.getPsiElement();
    PsiFile file = element.getContainingFile();
    if (!(file instanceof PyFile)) {
        return false;
    }
    TargetInfo binaryTarget = getTargetLabel(file);
    if (binaryTarget == null) {
        return false;
    }
    configuration.setTargetInfo(binaryTarget);
    sourceElement.set(file);
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    handlerState.getCommandState().setCommand(BlazeCommandName.RUN);
    configuration.setGeneratedName();
    return true;
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiFile(com.intellij.psi.PsiFile) PyFile(com.jetbrains.python.psi.PyFile) PsiElement(com.intellij.psi.PsiElement)

Example 14 with BlazeCommandRunConfigurationCommonState

use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.

the class BlazePyTestConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null || !BlazeCommandName.TEST.equals(handlerState.getCommandState().getCommand())) {
        return false;
    }
    PsiElement element = selectedPsiElement(context);
    if (element == null) {
        return false;
    }
    if (!(element.getContainingFile() instanceof PyFile)) {
        return false;
    }
    TargetInfo testTarget = TestTargetHeuristic.testTargetForPsiElement(element);
    if (testTarget == null || !testTarget.label.equals(configuration.getTarget())) {
        return false;
    }
    String filter = testLocation(element).testFilter();
    String filterFlag = handlerState.getTestFilterFlag();
    return (filterFlag == null && filter == null) || Objects.equals(filterFlag, BlazeFlags.TEST_FILTER + "=" + filter);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PyFile(com.jetbrains.python.psi.PyFile) PsiElement(com.intellij.psi.PsiElement)

Example 15 with BlazeCommandRunConfigurationCommonState

use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.

the class BlazePyDebugRunner method canRun.

@Override
public boolean canRun(String executorId, RunProfile profile) {
    if (!DefaultDebugExecutor.EXECUTOR_ID.equals(executorId) || !(profile instanceof BlazeCommandRunConfiguration)) {
        return false;
    }
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) profile;
    BlazeCommandRunConfigurationCommonState handlerState = config.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    BlazeCommandName command = handlerState != null ? handlerState.getCommandState().getCommand() : null;
    return PyDebugUtils.canUsePyDebugger(config.getTargetKind()) && (BlazeCommandName.TEST.equals(command) || BlazeCommandName.RUN.equals(command));
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) BlazeCommandName(com.google.idea.blaze.base.command.BlazeCommandName)

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