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;
}
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;
}
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;
}
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"));
}
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"));
}
Aggregations