use of com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder in project intellij by bazelbuild.
the class BlazeScalaSpecs2TestExprConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
TestLocation testLocation = testLocation(context);
if (testLocation == null) {
return false;
}
configuration.setTargetInfo(testLocation.target);
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
sourceElement.set(testLocation.testCase);
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 filter = testLocation.testFilter();
if (filter != null) {
flags.add(filter);
}
handlerState.getBlazeFlagsState().setRawFlags(flags);
String name = new BlazeConfigurationNameBuilder(configuration).setTargetString(testLocation.targetString()).build();
configuration.setName(name);
// don't revert to generated name
configuration.setNameChangedByUser(true);
return true;
}
use of com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder 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.run.BlazeConfigurationNameBuilder 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.run.BlazeConfigurationNameBuilder in project intellij by bazelbuild.
the class BlazeJavaTestClassConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
TestLocation location = getSingleJUnitTestClass(context);
if (location == null) {
return false;
}
sourceElement.set(location.testClass);
configuration.setTargetInfo(location.blazeTarget);
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
String testFilter = getTestFilter(location.testClass);
if (testFilter == null) {
return false;
}
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));
flags.add(BlazeFlags.TEST_FILTER + "=" + testFilter);
handlerState.getBlazeFlagsState().setRawFlags(flags);
String name = new BlazeConfigurationNameBuilder(configuration).setTargetString(location.testClass.getName()).build();
configuration.setName(name);
// don't revert to generated name
configuration.setNameChangedByUser(true);
return true;
}
use of com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder in project intellij by bazelbuild.
the class BlazeJavaTestMethodConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
TestMethodContext methodContext = getSelectedMethodContext(context);
if (methodContext == null) {
return false;
}
// PatternConfigurationProducer also chooses the first method as its source element.
// As long as we choose an element at the same PSI hierarchy level,
// PatternConfigurationProducer won't override our configuration.
sourceElement.set(methodContext.firstMethod);
configuration.setTargetInfo(methodContext.blazeTarget);
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
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));
flags.add(methodContext.testFilterFlag);
if (!flags.contains(BlazeFlags.DISABLE_TEST_SHARDING)) {
flags.add(BlazeFlags.DISABLE_TEST_SHARDING);
}
handlerState.getBlazeFlagsState().setRawFlags(flags);
BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
nameBuilder.setTargetString(String.format("%s.%s", methodContext.containingClass.getName(), String.join(",", methodContext.methodNames)));
configuration.setName(nameBuilder.build());
// don't revert to generated name
configuration.setNameChangedByUser(true);
return true;
}
Aggregations