Search in sources :

Example 1 with BlazeConfigurationNameBuilder

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

the class BlazeGoTestConfigurationProducer 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);
    sourceElement.set(testLocation.sourceElement());
    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 testFilter = testLocation.testFilter();
    if (testFilter != null) {
        flags.add(testFilter);
    }
    handlerState.getBlazeFlagsState().setRawFlags(flags);
    BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
    nameBuilder.setTargetString(testLocation.targetString());
    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 2 with BlazeConfigurationNameBuilder

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

the class BlazeScalaTestClassConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    ScClass testClass = getTestClass(context);
    if (testClass == null) {
        return false;
    }
    sourceElement.set(testClass);
    TargetInfo target = RunUtil.targetForTestClass(testClass, TestSizeAnnotationMap.getTestSize(testClass));
    if (target == null) {
        return false;
    }
    configuration.setTargetInfo(target);
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
    flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
    flags.add(getTestFilterFlag(testClass));
    handlerState.getBlazeFlagsState().setRawFlags(flags);
    handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
    BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
    nameBuilder.setTargetString(testClass.getName());
    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) BlazeConfigurationNameBuilder(com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder) ScClass(org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass)

Example 3 with BlazeConfigurationNameBuilder

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

the class BlazeAndroidTestRunConfigurationHandler method suggestedName.

@Override
@Nullable
public String suggestedName(BlazeCommandRunConfiguration configuration) {
    Label target = getLabel();
    if (target == null) {
        return null;
    }
    BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(this.configuration);
    boolean isClassTest = configState.getTestingType() == BlazeAndroidTestRunConfigurationState.TEST_CLASS;
    boolean isMethodTest = configState.getTestingType() == BlazeAndroidTestRunConfigurationState.TEST_METHOD;
    if ((isClassTest || isMethodTest) && configState.getClassName() != null) {
        // Get the class name without the package.
        String className = JavaExecutionUtil.getPresentableClassName(configState.getClassName());
        if (className != null) {
            String targetString = className;
            if (isMethodTest) {
                targetString += "#" + configState.getMethodName();
            }
            return nameBuilder.setTargetString(targetString).build();
        }
    }
    return nameBuilder.build();
}
Also used : Label(com.google.idea.blaze.base.model.primitives.Label) BlazeConfigurationNameBuilder(com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder) Nullable(javax.annotation.Nullable)

Example 4 with BlazeConfigurationNameBuilder

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

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

the class BlazeKotlinTestClassConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    TestLocation testLocation = TestLocation.from(context);
    if (testLocation == null) {
        return false;
    }
    sourceElement.set(testLocation.getSourceElement());
    TargetInfo targetInfo = testLocation.getTargetInfo();
    if (targetInfo == null) {
        return false;
    }
    configuration.setTargetInfo(targetInfo);
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
    String testFilter = testLocation.getTestFilterFlag();
    if (testFilter != null) {
        List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
        flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
        flags.add(testFilter);
        handlerState.getBlazeFlagsState().setRawFlags(flags);
    }
    BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
    nameBuilder.setTargetString(testLocation.getDisplayName());
    configuration.setName(nameBuilder.build());
    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) 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