Search in sources :

Example 1 with AzureRunConfigurationBase

use of com.microsoft.azure.toolkit.intellij.common.AzureRunConfigurationBase in project azure-tools-for-java by Microsoft.

the class FunctionRunConfigurationProducer method setupConfigurationFromContext.

@Override
protected boolean setupConfigurationFromContext(AzureRunConfigurationBase runConfigurationBase, ConfigurationContext context, Ref ref) {
    if (!(runConfigurationBase instanceof FunctionRunConfiguration || runConfigurationBase instanceof FunctionDeployConfiguration)) {
        return false;
    }
    final Location contextLocation = context.getLocation();
    assert contextLocation != null;
    Location<PsiMethod> methodLocation = getAzureFunctionMethods(contextLocation);
    if (methodLocation == null) {
        return false;
    }
    AzureRunConfigurationBase configuration = runConfigurationBase;
    if (configuration instanceof FunctionDeployConfiguration) {
        final RunManagerEx manager = RunManagerEx.getInstanceEx(context.getProject());
        // since deploy configuration doesn't support, we need to create a FunctionRunConfiguration
        final RunnerAndConfigurationSettings settings = RunConfigurationUtils.getOrCreateRunConfigurationSettings(context.getModule(), manager, getConfigurationFactory());
        configuration = (AzureRunConfigurationBase) settings.getConfiguration();
    }
    FunctionRunConfiguration runConfiguration = (FunctionRunConfiguration) configuration;
    final RunnerAndConfigurationSettings template = context.getRunManager().getConfigurationTemplate(getConfigurationFactory());
    final Module contextModule = context.getModule();
    final Module predefinedModule = ((FunctionRunConfiguration) template.getConfiguration()).getModule();
    if (predefinedModule != null) {
        runConfiguration.initializeDefaults(predefinedModule);
    } else {
        final Module module = findModule(runConfiguration, contextModule);
        if (module != null) {
            runConfiguration.initializeDefaults(module);
        } else {
            return false;
        }
    }
    if (StringUtils.isBlank(configuration.getName())) {
        configuration.setName("Run Functions - " + runConfiguration.getModule().getName());
    }
    return true;
}
Also used : RunManagerEx(com.intellij.execution.RunManagerEx) PsiMethod(com.intellij.psi.PsiMethod) AzureRunConfigurationBase(com.microsoft.azure.toolkit.intellij.common.AzureRunConfigurationBase) FunctionRunConfiguration(com.microsoft.azure.toolkit.intellij.function.runner.localrun.FunctionRunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) FunctionDeployConfiguration(com.microsoft.azure.toolkit.intellij.function.runner.deploy.FunctionDeployConfiguration) Module(com.intellij.openapi.module.Module) Location(com.intellij.execution.Location)

Aggregations

Location (com.intellij.execution.Location)1 RunManagerEx (com.intellij.execution.RunManagerEx)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 Module (com.intellij.openapi.module.Module)1 PsiMethod (com.intellij.psi.PsiMethod)1 AzureRunConfigurationBase (com.microsoft.azure.toolkit.intellij.common.AzureRunConfigurationBase)1 FunctionDeployConfiguration (com.microsoft.azure.toolkit.intellij.function.runner.deploy.FunctionDeployConfiguration)1 FunctionRunConfiguration (com.microsoft.azure.toolkit.intellij.function.runner.localrun.FunctionRunConfiguration)1