Search in sources :

Example 1 with FunctionRunConfiguration

use of com.microsoft.azure.toolkit.intellij.function.runner.localrun.FunctionRunConfiguration 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)

Example 2 with FunctionRunConfiguration

use of com.microsoft.azure.toolkit.intellij.function.runner.localrun.FunctionRunConfiguration in project azure-tools-for-java by Microsoft.

the class FunctionRunConfigurationProducer method isConfigurationFromContext.

@Override
public boolean isConfigurationFromContext(AzureRunConfigurationBase appConfiguration, ConfigurationContext context) {
    if (!(appConfiguration instanceof FunctionRunConfiguration)) {
        return false;
    }
    Location<PsiMethod> methodLocation = getAzureFunctionMethods(context.getLocation());
    if (methodLocation == null) {
        return false;
    }
    final Module configurationModule = ((FunctionRunConfiguration) appConfiguration).getModule();
    if (Comparing.equal(context.getModule(), configurationModule)) {
        return true;
    }
    return false;
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) FunctionRunConfiguration(com.microsoft.azure.toolkit.intellij.function.runner.localrun.FunctionRunConfiguration) Module(com.intellij.openapi.module.Module)

Aggregations

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