Search in sources :

Example 26 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class BlazeScalaSpecs2TestExprConfigurationProducer method testLocation.

@Nullable
private static TestLocation testLocation(ConfigurationContext context) {
    // Handled by SM runner.
    if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
        return null;
    }
    ScInfixExpr testCase = Specs2Utils.getContainingTestExprOrScope(context.getPsiLocation());
    if (testCase == null) {
        return null;
    }
    ScTypeDefinition testClass = PsiTreeUtil.getParentOfType(testCase, ScTypeDefinition.class);
    if (testClass == null) {
        return null;
    }
    TestSize testSize = TestSizeAnnotationMap.getTestSize(testClass);
    TargetInfo target = RunUtil.targetForTestClass(testClass, testSize);
    if (target == null) {
        return null;
    }
    return new TestLocation(target, testClass, testCase);
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ScInfixExpr(org.jetbrains.plugins.scala.lang.psi.api.expr.ScInfixExpr) ScTypeDefinition(org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition) TestSize(com.google.idea.blaze.base.dependencies.TestSize) Nullable(javax.annotation.Nullable)

Example 27 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class BlazeScalaTestClassConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    PsiClass testClass = getTestClass(context);
    if (testClass == null) {
        return false;
    }
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null || !Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.TEST) || !Objects.equals(handlerState.getTestFilterFlag(), getTestFilterFlag(testClass))) {
        return false;
    }
    TargetInfo target = RunUtil.targetForTestClass(testClass, TestSizeAnnotationMap.getTestSize(testClass));
    return target != null && Objects.equals(configuration.getTarget(), target.label);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiClass(com.intellij.psi.PsiClass)

Example 28 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo 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 29 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class BlazeAndroidTestClassRunConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    final Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation);
    if (location == null) {
        return false;
    }
    if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
        // handled by a different producer
        return false;
    }
    if (JUnitConfigurationUtil.isMultipleElementsSelected(context)) {
        return false;
    }
    PsiClass testClass = JUnitUtil.getTestClass(location);
    if (testClass == null) {
        return false;
    }
    sourceElement.set(testClass);
    TargetInfo target = RunUtil.targetForTestClass(testClass, null);
    if (target == null) {
        return false;
    }
    if (!Kind.ANDROID_TEST.equals(target.getKind())) {
        return false;
    }
    configuration.setTargetInfo(target);
    BlazeAndroidTestRunConfigurationState configState = configuration.getHandlerStateIfType(BlazeAndroidTestRunConfigurationState.class);
    if (configState == null) {
        return false;
    }
    configState.setTestingType(AndroidTestRunConfiguration.TEST_CLASS);
    configState.setClassName(testClass.getQualifiedName());
    configuration.setGeneratedName();
    return true;
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiClass(com.intellij.psi.PsiClass) Location(com.intellij.execution.Location)

Example 30 with TargetInfo

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

Aggregations

TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)69 File (java.io.File)43 Test (org.junit.Test)40 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)19 PsiFile (com.intellij.psi.PsiFile)18 Nullable (javax.annotation.Nullable)15 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)14 PsiElement (com.intellij.psi.PsiElement)9 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)7 Label (com.google.idea.blaze.base.model.primitives.Label)7 PsiClass (com.intellij.psi.PsiClass)7 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)6 RuleType (com.google.idea.blaze.base.model.primitives.RuleType)6 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)5 BlazeTestCase (com.google.idea.blaze.base.BlazeTestCase)5 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)5 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)5