Search in sources :

Example 1 with BlazeCommandRunConfigurationCommonState

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);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) BlazeCommandName(com.google.idea.blaze.base.command.BlazeCommandName)

Example 2 with BlazeCommandRunConfigurationCommonState

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));
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) PsiDirectory(com.intellij.psi.PsiDirectory) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot)

Example 3 with BlazeCommandRunConfigurationCommonState

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();
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)

Example 4 with BlazeCommandRunConfigurationCommonState

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());
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)

Example 5 with BlazeCommandRunConfigurationCommonState

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;
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) ArrayList(java.util.ArrayList)

Aggregations

BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)52 TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)13 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)10 BlazeConfigurationNameBuilder (com.google.idea.blaze.base.run.BlazeConfigurationNameBuilder)9 BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)8 PsiFile (com.intellij.psi.PsiFile)8 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)6 PsiElement (com.intellij.psi.PsiElement)6 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)5 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)4 PsiMethod (com.intellij.psi.PsiMethod)4 PyFile (com.jetbrains.python.psi.PyFile)4 BlazeCommandName (com.google.idea.blaze.base.command.BlazeCommandName)3 TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)3 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)3 PsiClass (com.intellij.psi.PsiClass)3 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)2 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)2 Kind (com.google.idea.blaze.base.model.primitives.Kind)2