use of com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder in project intellij by bazelbuild.
the class BlazeGoTestConfigurationProducer 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);
sourceElement.set(testLocation.sourceElement());
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 testFilter = testLocation.testFilter();
if (testFilter != null) {
flags.add(testFilter);
}
handlerState.getBlazeFlagsState().setRawFlags(flags);
BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
nameBuilder.setTargetString(testLocation.targetString());
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 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.run.BlazeConfigurationNameBuilder in project intellij by bazelbuild.
the class BlazeAndroidTestRunConfigurationHandler method suggestedName.
@Override
@Nullable
public String suggestedName(BlazeCommandRunConfiguration configuration) {
Label target = getLabel();
if (target == null) {
return null;
}
BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(this.configuration);
boolean isClassTest = configState.getTestingType() == BlazeAndroidTestRunConfigurationState.TEST_CLASS;
boolean isMethodTest = configState.getTestingType() == BlazeAndroidTestRunConfigurationState.TEST_METHOD;
if ((isClassTest || isMethodTest) && configState.getClassName() != null) {
// Get the class name without the package.
String className = JavaExecutionUtil.getPresentableClassName(configState.getClassName());
if (className != null) {
String targetString = className;
if (isMethodTest) {
targetString += "#" + configState.getMethodName();
}
return nameBuilder.setTargetString(targetString).build();
}
}
return nameBuilder.build();
}
use of com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder in project intellij by bazelbuild.
the class MultipleJavaClassesTestConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
TestLocation location = getTestLocation(context);
if (location == null) {
return false;
}
sourceElement.set(location.psiLocation);
configuration.setTargetInfo(location.target);
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));
if (location.testFilter != null) {
flags.add(location.testFilter);
}
handlerState.getBlazeFlagsState().setRawFlags(flags);
if (location.description != null) {
BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
nameBuilder.setTargetString(location.description);
configuration.setName(nameBuilder.build());
// don't revert to generated name
configuration.setNameChangedByUser(true);
} else {
configuration.setGeneratedName();
}
return true;
}
use of com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder in project intellij by bazelbuild.
the class BlazeKotlinTestClassConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
TestLocation testLocation = TestLocation.from(context);
if (testLocation == null) {
return false;
}
sourceElement.set(testLocation.getSourceElement());
TargetInfo targetInfo = testLocation.getTargetInfo();
if (targetInfo == null) {
return false;
}
configuration.setTargetInfo(targetInfo);
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
handlerState.getCommandState().setCommand(BlazeCommandName.TEST);
String testFilter = testLocation.getTestFilterFlag();
if (testFilter != null) {
List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
flags.add(testFilter);
handlerState.getBlazeFlagsState().setRawFlags(flags);
}
BlazeConfigurationNameBuilder nameBuilder = new BlazeConfigurationNameBuilder(configuration);
nameBuilder.setTargetString(testLocation.getDisplayName());
configuration.setName(nameBuilder.build());
configuration.setNameChangedByUser(true);
return true;
}
Aggregations