use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class CoverageUtils method isApplicableTo.
public static boolean isApplicableTo(RunProfile runProfile) {
BlazeCommandRunConfiguration config = toBlazeConfig(runProfile);
if (config == null) {
return false;
}
if (Blaze.getBuildSystem(config.getProject()) != BuildSystem.Blaze) {
// file locations
return false;
}
BlazeCommandRunConfigurationCommonState handlerState = config.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
BlazeCommandName command = handlerState.getCommandState().getCommand();
return BlazeCommandName.TEST.equals(command) || BlazeCommandName.COVERAGE.equals(command);
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class AllInPackageBlazeConfigurationProducer method doIsConfigFromContext.
@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
PsiDirectory dir = getTestDirectory(context);
if (dir == null) {
return false;
}
WorkspaceRoot root = WorkspaceRoot.fromProject(context.getProject());
WorkspacePath packagePath = getWorkspaceRelativeDirectoryPath(root, dir);
if (packagePath == null) {
return false;
}
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null) {
return false;
}
return Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.TEST) && Objects.equals(configuration.getTarget(), TargetExpression.allFromPackageRecursive(packagePath));
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeBuildFileRunConfigurationProducer method setupBuildFileConfiguration.
private static void setupBuildFileConfiguration(BlazeCommandRunConfiguration configuration, BuildTarget target) {
configuration.setTarget(target.label);
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState != null) {
handlerState.getCommandState().setCommand(commandForRuleType(target.ruleType));
}
configuration.setGeneratedName();
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeBuildFileRunConfigurationProducer method doIsConfigFromContext.
@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
BuildTarget target = getBuildTarget(context);
if (target == null) {
return false;
}
if (!Objects.equals(configuration.getTarget(), target.label)) {
return false;
}
// We don't know any details about how the various factories set up configurations from here.
// Simply returning true at this point would be overly broad
// (all configs with a matching target would be identified).
// A complete equality check, meanwhile, would be too restrictive
// (things like config name and user flags shouldn't count)
// - not to mention we lack the equals() implementations needed to perform such a check!
// So we compromise: if the target, suggested name, and command name match,
// we consider it close enough. The suggested name is checked because it tends
// to cover what the handler considers important,
// and ignores changes the user may have made to the name.
BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(configuration.getProject()).getBlazeProjectData();
if (blazeProjectData == null) {
return false;
}
BlazeCommandRunConfiguration generatedConfiguration = new BlazeCommandRunConfiguration(configuration.getProject(), configuration.getFactory(), configuration.getName());
setupConfiguration(configuration.getProject(), blazeProjectData, generatedConfiguration, target);
// ignore filtered test configs, produced by other configuration producers.
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState != null && handlerState.getTestFilterFlag() != null) {
return false;
}
return Objects.equals(configuration.suggestedName(), generatedConfiguration.suggestedName()) && Objects.equals(configuration.getHandler().getCommandName(), generatedConfiguration.getHandler().getCommandName());
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeFilterExistingRunConfigurationProducer method doSetupConfigFromContext.
@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
Optional<String> testFilter = getTestFilter(context);
if (!testFilter.isPresent()) {
return false;
}
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null || !BlazeCommandName.TEST.equals(handlerState.getCommandState().getCommand())) {
return false;
}
// replace old test filter flag if present
List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
flags.add(testFilter.get());
if (SmRunnerUtils.countSelectedTestCases(context) == 1 && !flags.contains(BlazeFlags.DISABLE_TEST_SHARDING)) {
flags.add(BlazeFlags.DISABLE_TEST_SHARDING);
}
handlerState.getBlazeFlagsState().setRawFlags(flags);
configuration.setName(configuration.getName() + " (filtered)");
configuration.setNameChangedByUser(true);
return true;
}
Aggregations