Search in sources :

Example 6 with BlazeConfigurationNameBuilder

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

the class BlazeScalaSpecs2TestExprConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    TestLocation testLocation = testLocation(context);
    if (testLocation == null) {
        return false;
    }
    configuration.setTargetInfo(testLocation.target);
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    sourceElement.set(testLocation.testCase);
    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));
    String filter = testLocation.testFilter();
    if (filter != null) {
        flags.add(filter);
    }
    handlerState.getBlazeFlagsState().setRawFlags(flags);
    String name = new BlazeConfigurationNameBuilder(configuration).setTargetString(testLocation.targetString()).build();
    configuration.setName(name);
    // 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 7 with BlazeConfigurationNameBuilder

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

the class BlazePyTestConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    PsiElement element = selectedPsiElement(context);
    if (element == null) {
        return false;
    }
    PsiFile file = element.getContainingFile();
    if (!(file instanceof PyFile) || !PyTestUtils.isTestFile((PyFile) file)) {
        return false;
    }
    TargetInfo testTarget = TestTargetHeuristic.testTargetForPsiElement(element);
    if (testTarget == null) {
        return false;
    }
    configuration.setTargetInfo(testTarget);
    TestLocation testLocation = testLocation(element);
    sourceElement.set(testLocation.sourceElement(file));
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
    // remove conflicting flags from initial configuration
    List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
    flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
    String filter = testLocation.testFilter();
    if (filter != null) {
        flags.add(BlazeFlags.TEST_FILTER + "=" + filter);
    }
    handlerState.getBlazeFlagsState().setRawFlags(flags);
    BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
    nameBuilder.setTargetString(filter != null ? String.format("%s (%s)", filter, testTarget.label.toString()) : testTarget.label.toString());
    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) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ArrayList(java.util.ArrayList) PsiFile(com.intellij.psi.PsiFile) PyFile(com.jetbrains.python.psi.PyFile) BlazeConfigurationNameBuilder(com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder) PsiElement(com.intellij.psi.PsiElement)

Example 8 with BlazeConfigurationNameBuilder

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

the class BlazeJavaAbstractTestCaseConfigurationProducer method setupContext.

private static void setupContext(BlazeCommandRunConfiguration configuration, PsiClass subClass, @Nullable PsiMethod method) {
    TestSize testSize = method != null ? TestSizeAnnotationMap.getTestSize(method) : TestSizeAnnotationMap.getTestSize(subClass);
    TargetInfo target = RunUtil.targetForTestClass(subClass, testSize);
    if (target == null) {
        return;
    }
    configuration.setTargetInfo(target);
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return;
    }
    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));
    String testFilter = BlazeJUnitTestFilterFlags.testFilterForClassAndMethods(subClass, method == null ? ImmutableList.of() : ImmutableList.of(method));
    if (testFilter == null) {
        return;
    }
    flags.add(BlazeFlags.TEST_FILTER + "=" + testFilter);
    handlerState.getBlazeFlagsState().setRawFlags(flags);
    BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
    nameBuilder.setTargetString(configName(subClass, method));
    configuration.setName(nameBuilder.build());
    // don't revert to generated name
    configuration.setNameChangedByUser(true);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ArrayList(java.util.ArrayList) BlazeConfigurationNameBuilder(com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder) TestSize(com.google.idea.blaze.base.dependencies.TestSize)

Example 9 with BlazeConfigurationNameBuilder

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

the class BlazeJavaTestClassConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    TestLocation location = getSingleJUnitTestClass(context);
    if (location == null) {
        return false;
    }
    sourceElement.set(location.testClass);
    configuration.setTargetInfo(location.blazeTarget);
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    String testFilter = getTestFilter(location.testClass);
    if (testFilter == 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(BlazeFlags.TEST_FILTER + "=" + testFilter);
    handlerState.getBlazeFlagsState().setRawFlags(flags);
    String name = new BlazeConfigurationNameBuilder(configuration).setTargetString(location.testClass.getName()).build();
    configuration.setName(name);
    // 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 10 with BlazeConfigurationNameBuilder

use of com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder 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)

Aggregations

BlazeConfigurationNameBuilder (com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder)10 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)9 ArrayList (java.util.ArrayList)9 TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)4 TestSize (com.google.idea.blaze.base.dependencies.TestSize)1 Label (com.google.idea.blaze.base.model.primitives.Label)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PyFile (com.jetbrains.python.psi.PyFile)1 Nullable (javax.annotation.Nullable)1 ScClass (org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass)1