Search in sources :

Example 51 with TargetInfo

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

the class MultipleJavaClassesTestConfigurationProducer method getTestTargetIfUnique.

@Nullable
private static TargetInfo getTestTargetIfUnique(Set<PsiClass> classes) {
    TargetInfo testTarget = null;
    for (PsiClass psiClass : classes) {
        TargetInfo target = testTargetForClass(psiClass);
        if (target == null) {
            continue;
        }
        if (testTarget != null && !testTarget.equals(target)) {
            return null;
        }
        testTarget = target;
    }
    return testTarget;
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiClass(com.intellij.psi.PsiClass) Nullable(javax.annotation.Nullable)

Example 52 with TargetInfo

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

the class BlazeAndroidTestMethodRunConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
        // handled by a different producer
        return false;
    }
    if (JUnitConfigurationUtil.isMultipleElementsSelected(context)) {
        return false;
    }
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    Location<PsiMethod> methodLocation = ProducerUtils.getMethodLocation(contextLocation);
    if (methodLocation == null) {
        return false;
    }
    final PsiMethod psiMethod = methodLocation.getPsiElement();
    sourceElement.set(psiMethod);
    final PsiClass containingClass = psiMethod.getContainingClass();
    if (containingClass == null) {
        return false;
    }
    TargetInfo target = RunUtil.targetForTestClass(containingClass, 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_METHOD);
    configState.setClassName(containingClass.getQualifiedName());
    configState.setMethodName(psiMethod.getName());
    configuration.setGeneratedName();
    return true;
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) Location(com.intellij.execution.Location)

Example 53 with TargetInfo

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

the class BlazeAndroidRunConfigurationValidationUtil method validateLabel.

public static List<ValidationError> validateLabel(@Nullable Label label, Project project, ImmutableList<Kind> kinds) {
    List<ValidationError> errors = Lists.newArrayList();
    if (label == null) {
        errors.add(ValidationError.fatal("No target selected."));
        return errors;
    }
    TargetInfo target = TargetFinder.findTargetInfo(project, label);
    if (target == null) {
        errors.add(ValidationError.fatal(String.format("No existing %s rule selected.", Blaze.buildSystemName(project))));
    } else if (target.getKind() == null || !target.getKind().isOneOf(kinds)) {
        errors.add(ValidationError.fatal(String.format("Selected %s rule is not one of: %s", Blaze.buildSystemName(project), kinds.stream().map(Kind::toString).collect(Collectors.joining(", ")))));
    }
    return errors;
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ValidationError(com.android.tools.idea.run.ValidationError)

Example 54 with TargetInfo

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

the class TestTargetHeuristicTest method testTestSizeMatched.

@Test
public void testTestSizeMatched() {
    File source = workspaceRoot.fileForPath(new WorkspacePath("java/com/foo/FooTest.java"));
    Collection<TargetInfo> targets = ImmutableList.of(TargetIdeInfo.builder().setLabel("//foo:test1").setKind("java_test").setTestInfo(TestIdeInfo.builder().setTestSize(TestSize.MEDIUM)).build().toTargetInfo(), TargetIdeInfo.builder().setLabel("//foo:test2").setKind("java_test").setTestInfo(TestIdeInfo.builder().setTestSize(TestSize.SMALL)).build().toTargetInfo());
    TargetInfo match = TestTargetHeuristic.chooseTestTargetForSourceFile(getProject(), null, source, targets, TestSize.SMALL);
    assertThat(match.label).isEqualTo(Label.create("//foo:test2"));
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) File(java.io.File) Test(org.junit.Test)

Example 55 with TargetInfo

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

the class TestTargetHeuristicTest method testTargetNameMatched.

@Test
public void testTargetNameMatched() {
    File source = workspaceRoot.fileForPath(new WorkspacePath("java/com/foo/FooTest.java"));
    Collection<TargetInfo> targets = ImmutableList.of(TargetIdeInfo.builder().setLabel("//foo:FirstTest").setKind("java_test").build().toTargetInfo(), TargetIdeInfo.builder().setLabel("//foo:FooTest").setKind("java_test").build().toTargetInfo());
    TargetInfo match = TestTargetHeuristic.chooseTestTargetForSourceFile(getProject(), null, source, targets, null);
    assertThat(match.label).isEqualTo(Label.create("//foo:FooTest"));
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) File(java.io.File) Test(org.junit.Test)

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