Search in sources :

Example 1 with StorageAccount

use of com.microsoft.azure.functions.annotation.StorageAccount in project azure-tools-for-java by Microsoft.

the class FunctionUtils method patchStorageBinding.

private static void patchStorageBinding(final PsiMethod method, final List<Binding> bindings) {
    final PsiAnnotation storageAccount = AnnotationUtil.findAnnotation(method, StorageAccount.class.getCanonicalName());
    if (storageAccount != null) {
        // todo: Remove System.out.println
        System.out.println(message("function.binding.storage.found"));
        final String connectionString = AnnotationUtil.getDeclaredStringAttributeValue(storageAccount, "value");
        // Replace empty connection string
        bindings.stream().filter(binding -> binding.getBindingEnum().isStorage()).filter(binding -> StringUtils.isEmpty((String) binding.getAttribute("connection"))).forEach(binding -> binding.setAttribute("connection", connectionString));
    } else {
        // todo: Remove System.out.println
        System.out.println(message("function.binding.storage.notFound"));
    }
}
Also used : JsonObject(com.google.gson.JsonObject) Azure(com.microsoft.azure.toolkit.lib.Azure) AzureExecutionException(com.microsoft.azure.toolkit.lib.common.exception.AzureExecutionException) Arrays(java.util.Arrays) AzureConfiguration(com.microsoft.azure.toolkit.lib.AzureConfiguration) AzureBundle.message(com.microsoft.intellij.ui.messages.AzureBundle.message) OrderEnumerator(com.intellij.openapi.roots.OrderEnumerator) JsonUtils(com.microsoft.azuretools.utils.JsonUtils) VirtualFile(com.intellij.openapi.vfs.VirtualFile) StringUtils(org.apache.commons.lang3.StringUtils) Library(com.intellij.openapi.roots.libraries.Library) ClassUtils(org.apache.commons.lang3.ClassUtils) PsiJavaCodeReferenceElement(com.intellij.psi.PsiJavaCodeReferenceElement) Map(java.util.Map) Module(com.intellij.openapi.module.Module) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension) Path(java.nio.file.Path) MavenProject(org.jetbrains.idea.maven.project.MavenProject) FunctionCliResolver(com.microsoft.azure.toolkit.lib.appservice.utils.FunctionCliResolver) OrderRootType(com.intellij.openapi.roots.OrderRootType) Nullable(com.microsoft.azuretools.azurecommons.helpers.Nullable) MetaAnnotationUtil(com.intellij.codeInsight.MetaAnnotationUtil) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Collectors(java.util.stream.Collectors) MavenProjectsManager(org.jetbrains.idea.maven.project.MavenProjectsManager) List(java.util.List) AnnotatedElementsSearch(com.intellij.psi.search.searches.AnnotatedElementsSearch) AnnotationUtil(com.intellij.codeInsight.AnnotationUtil) PsiAnnotation(com.intellij.psi.PsiAnnotation) IntelliJSecureStore(com.microsoft.intellij.secure.IntelliJSecureStore) JvmParameter(com.intellij.lang.jvm.JvmParameter) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation) ModuleManager(com.intellij.openapi.module.ModuleManager) JavaPsiFacade(com.intellij.psi.JavaPsiFacade) ArrayUtils(org.apache.commons.lang3.ArrayUtils) HashMap(java.util.HashMap) ContainerUtil(com.intellij.util.containers.ContainerUtil) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) PsiClass(com.intellij.psi.PsiClass) Charset(java.nio.charset.Charset) Project(com.intellij.openapi.project.Project) FunctionConfiguration(com.microsoft.azure.toolkit.lib.legacy.function.configurations.FunctionConfiguration) Binding(com.microsoft.azure.toolkit.lib.legacy.function.bindings.Binding) AzureToolkitRuntimeException(com.microsoft.azure.toolkit.lib.common.exception.AzureToolkitRuntimeException) PsiModifierListOwner(com.intellij.psi.PsiModifierListOwner) PsiMethod(com.intellij.psi.PsiMethod) MapUtils(org.apache.commons.collections.MapUtils) Files(java.nio.file.Files) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) JvmAnnotation(com.intellij.lang.jvm.JvmAnnotation) File(java.io.File) BindingEnum(com.microsoft.azure.toolkit.lib.legacy.function.bindings.BindingEnum) Paths(java.nio.file.Paths) Log(com.microsoft.azure.toolkit.lib.common.logging.Log) StorageAccount(com.microsoft.azure.functions.annotation.StorageAccount) StorageAccount(com.microsoft.azure.functions.annotation.StorageAccount) PsiAnnotation(com.intellij.psi.PsiAnnotation)

Aggregations

JsonObject (com.google.gson.JsonObject)1 AnnotationUtil (com.intellij.codeInsight.AnnotationUtil)1 MetaAnnotationUtil (com.intellij.codeInsight.MetaAnnotationUtil)1 JvmAnnotation (com.intellij.lang.jvm.JvmAnnotation)1 JvmParameter (com.intellij.lang.jvm.JvmParameter)1 Module (com.intellij.openapi.module.Module)1 ModuleManager (com.intellij.openapi.module.ModuleManager)1 Project (com.intellij.openapi.project.Project)1 CompilerModuleExtension (com.intellij.openapi.roots.CompilerModuleExtension)1 OrderEnumerator (com.intellij.openapi.roots.OrderEnumerator)1 OrderRootType (com.intellij.openapi.roots.OrderRootType)1 Library (com.intellij.openapi.roots.libraries.Library)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)1 PsiAnnotation (com.intellij.psi.PsiAnnotation)1 PsiClass (com.intellij.psi.PsiClass)1 PsiJavaCodeReferenceElement (com.intellij.psi.PsiJavaCodeReferenceElement)1 PsiMethod (com.intellij.psi.PsiMethod)1 PsiModifierListOwner (com.intellij.psi.PsiModifierListOwner)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1