Search in sources :

Example 21 with BlazeCommandRunConfigurationCommonState

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;
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) GoogleTestLocation(com.google.idea.blaze.clwb.run.test.GoogleTestLocation) ImmutableList(com.google.common.collect.ImmutableList) PsiElement(com.intellij.psi.PsiElement)

Example 22 with BlazeCommandRunConfigurationCommonState

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

Example 23 with BlazeCommandRunConfigurationCommonState

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

Example 24 with BlazeCommandRunConfigurationCommonState

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

Example 25 with BlazeCommandRunConfigurationCommonState

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