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