use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class BlazePyTestConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
PsiElement element = selectedPsiElement(context);
if (element == null) {
return false;
}
PsiFile file = element.getContainingFile();
if (!(file instanceof PyFile) || !PyTestUtils.isTestFile((PyFile) file)) {
return false;
}
TargetInfo testTarget = TestTargetHeuristic.testTargetForPsiElement(element);
if (testTarget == null) {
return false;
}
configuration.setTargetInfo(testTarget);
TestLocation testLocation = testLocation(element);
sourceElement.set(testLocation.sourceElement(file));
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 filter = testLocation.testFilter();
if (filter != null) {
flags.add(BlazeFlags.TEST_FILTER + "=" + filter);
}
handlerState.getBlazeFlagsState().setRawFlags(flags);
BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
nameBuilder.setTargetString(filter != null ? String.format("%s (%s)", filter, testTarget.label.toString()) : testTarget.label.toString());
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 BlazeBuildTargetRunConfigurationFactory method setupConfiguration.
@Override
public void setupConfiguration(RunConfiguration configuration, Label label) {
BlazeCommandRunConfiguration blazeConfig = (BlazeCommandRunConfiguration) configuration;
TargetInfo target = findProjectTarget(configuration.getProject(), label);
blazeConfig.setTargetInfo(target);
if (target == null) {
return;
}
BlazeCommandRunConfigurationCommonState state = blazeConfig.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (state != null) {
state.getCommandState().setCommand(commandForRuleType(target.getRuleType()));
}
blazeConfig.setGeneratedName();
}
use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class BlazeCidrTestConfigurationProducer method doIsConfigFromContext.
@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
if (!Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.TEST)) {
return false;
}
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;
}
return target.label.equals(configuration.getTarget()) && Objects.equals(handlerState.getTestFilterFlag(), test.getTestFilterFlag());
}
use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class BlazeJavaAbstractTestCaseConfigurationProducer method setupContext.
private static void setupContext(BlazeCommandRunConfiguration configuration, PsiClass subClass, @Nullable PsiMethod method) {
TestSize testSize = method != null ? TestSizeAnnotationMap.getTestSize(method) : TestSizeAnnotationMap.getTestSize(subClass);
TargetInfo target = RunUtil.targetForTestClass(subClass, testSize);
if (target == null) {
return;
}
configuration.setTargetInfo(target);
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return;
}
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));
String testFilter = BlazeJUnitTestFilterFlags.testFilterForClassAndMethods(subClass, method == null ? ImmutableList.of() : ImmutableList.of(method));
if (testFilter == null) {
return;
}
flags.add(BlazeFlags.TEST_FILTER + "=" + testFilter);
handlerState.getBlazeFlagsState().setRawFlags(flags);
BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
nameBuilder.setTargetString(configName(subClass, method));
configuration.setName(nameBuilder.build());
// don't revert to generated name
configuration.setNameChangedByUser(true);
}
use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.
the class BlazeJavaTestMethodConfigurationProducer method getSelectedMethodContext.
@Nullable
private static TestMethodContext getSelectedMethodContext(ConfigurationContext context) {
if (!SmRunnerUtils.getSelectedSmRunnerTreeElements(context).isEmpty()) {
// handled by a different producer
return null;
}
final List<PsiMethod> selectedMethods = TestMethodSelectionUtil.getSelectedMethods(context);
if (selectedMethods == null) {
return null;
}
assert selectedMethods.size() > 0;
final PsiMethod firstMethod = selectedMethods.get(0);
final PsiClass containingClass = firstMethod.getContainingClass();
if (containingClass == null) {
return null;
}
for (PsiMethod method : selectedMethods) {
if (!containingClass.equals(method.getContainingClass())) {
return null;
}
}
TestSize testSize = TestSizeAnnotationMap.getTestSize(firstMethod);
TargetInfo target = RunUtil.targetForTestClass(containingClass, testSize);
if (target == null) {
return null;
}
String testFilter = BlazeJUnitTestFilterFlags.testFilterForClassAndMethods(containingClass, selectedMethods);
if (testFilter == null) {
return null;
}
// Sort so multiple configurations created with different selection orders are the same.
List<String> methodNames = selectedMethods.stream().map(PsiMethod::getName).sorted().collect(Collectors.toList());
final String testFilterFlag = BlazeFlags.TEST_FILTER + "=" + testFilter;
return new TestMethodContext(firstMethod, containingClass, methodNames, testFilterFlag, target);
}
Aggregations