Search in sources :

Example 1 with TargetSelectionMode

use of com.android.tools.idea.run.TargetSelectionMode in project android by JetBrains.

the class AndroidUtils method getDefaultTargetSelectionMode.

@Nullable
public static TargetSelectionMode getDefaultTargetSelectionMode(@NotNull Module module, @NotNull ConfigurationType type, @NonNls ConfigurationType alternativeType) {
    final RunManager runManager = RunManager.getInstance(module.getProject());
    List<RunConfiguration> configurations = runManager.getConfigurationsList(type);
    TargetSelectionMode alternative = null;
    if (configurations.size() > 0) {
        for (RunConfiguration configuration : configurations) {
            if (configuration instanceof AndroidRunConfigurationBase) {
                final AndroidRunConfigurationBase runConfig = (AndroidRunConfigurationBase) configuration;
                final TargetSelectionMode targetMode = runConfig.getDeployTargetContext().getTargetSelectionMode();
                //noinspection IfStatementWithIdenticalBranches - branches are only identical for final iteration of outer loop
                if (runConfig.getConfigurationModule() == module) {
                    return targetMode;
                } else {
                    alternative = targetMode;
                }
            }
        }
    }
    if (alternative != null) {
        return alternative;
    }
    configurations = runManager.getConfigurationsList(alternativeType);
    if (configurations.size() > 0) {
        for (RunConfiguration configuration : configurations) {
            if (configuration instanceof AndroidRunConfigurationBase) {
                return ((AndroidRunConfigurationBase) configuration).getDeployTargetContext().getTargetSelectionMode();
            }
        }
    }
    return null;
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) AndroidRunConfigurationBase(com.android.tools.idea.run.AndroidRunConfigurationBase) TargetSelectionMode(com.android.tools.idea.run.TargetSelectionMode) RunManager(com.intellij.execution.RunManager) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with TargetSelectionMode

use of com.android.tools.idea.run.TargetSelectionMode in project android by JetBrains.

the class AndroidTestConfigurationProducer method setupConfiguration.

private boolean setupConfiguration(AndroidTestRunConfiguration configuration, PsiElement element, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    final Module module = AndroidUtils.getAndroidModule(context);
    if (module == null) {
        return false;
    }
    sourceElement.set(element);
    setupConfigurationModule(context, configuration);
    final TargetSelectionMode targetSelectionMode = AndroidUtils.getDefaultTargetSelectionMode(module, AndroidTestRunConfigurationType.getInstance(), AndroidRunConfigurationType.getInstance());
    if (targetSelectionMode != null) {
        configuration.getDeployTargetContext().setTargetSelectionMode(targetSelectionMode);
    }
    return true;
}
Also used : TargetSelectionMode(com.android.tools.idea.run.TargetSelectionMode) Module(com.intellij.openapi.module.Module)

Aggregations

TargetSelectionMode (com.android.tools.idea.run.TargetSelectionMode)2 AndroidRunConfigurationBase (com.android.tools.idea.run.AndroidRunConfigurationBase)1 RunManager (com.intellij.execution.RunManager)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 Module (com.intellij.openapi.module.Module)1 Nullable (org.jetbrains.annotations.Nullable)1