Search in sources :

Example 1 with BaseBinding

use of com.microsoft.azure.gradle.functions.bindings.BaseBinding in project azure-gradle-plugins by lenala.

the class AnnotationHandlerImpl method patchStorageBinding.

private void patchStorageBinding(final Method method, final List<BaseBinding> bindings) {
    final Optional<Annotation> storageAccount = Arrays.stream(method.getAnnotations()).filter(a -> a instanceof StorageAccount).findFirst();
    if (storageAccount.isPresent()) {
        logger.quiet("StorageAccount annotation found.");
        final String connectionString = ((StorageAccount) storageAccount.get()).value();
        bindings.stream().forEach(b -> {
            if (b instanceof StorageBaseBinding) {
                final StorageBaseBinding sb = (StorageBaseBinding) b;
                // Override storage bindings with empty connection
                if (StringUtils.isEmpty(sb.getConnection())) {
                    sb.setConnection(connectionString);
                }
            }
        });
    } else {
        logger.quiet("No StorageAccount annotation found.");
    }
}
Also used : StorageBaseBinding(com.microsoft.azure.gradle.functions.bindings.StorageBaseBinding) Arrays(java.util.Arrays) URL(java.net.URL) HttpBinding(com.microsoft.azure.gradle.functions.bindings.HttpBinding) HashMap(java.util.HashMap) Reflections(org.reflections.Reflections) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Logger(org.gradle.api.logging.Logger) ArrayList(java.util.ArrayList) StorageAccount(com.microsoft.azure.serverless.functions.annotation.StorageAccount) URLClassLoader(java.net.URLClassLoader) HttpTrigger(com.microsoft.azure.serverless.functions.annotation.HttpTrigger) Parameter(java.lang.reflect.Parameter) Map(java.util.Map) MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) Method(java.lang.reflect.Method) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) BaseBinding(com.microsoft.azure.gradle.functions.bindings.BaseBinding) FunctionConfiguration(com.microsoft.azure.gradle.functions.configuration.FunctionConfiguration) Set(java.util.Set) List(java.util.List) FunctionName(com.microsoft.azure.serverless.functions.annotation.FunctionName) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) BindingFactory(com.microsoft.azure.gradle.functions.bindings.BindingFactory) StorageAccount(com.microsoft.azure.serverless.functions.annotation.StorageAccount) StorageBaseBinding(com.microsoft.azure.gradle.functions.bindings.StorageBaseBinding) Annotation(java.lang.annotation.Annotation)

Example 2 with BaseBinding

use of com.microsoft.azure.gradle.functions.bindings.BaseBinding in project azure-gradle-plugins by lenala.

the class AnnotationHandlerImpl method generateConfiguration.

@Override
public FunctionConfiguration generateConfiguration(final Method method) {
    final FunctionConfiguration config = new FunctionConfiguration();
    final List<BaseBinding> bindings = config.getBindings();
    processParameterAnnotations(method, bindings);
    processMethodAnnotations(method, bindings);
    patchStorageBinding(method, bindings);
    config.setEntryPoint(method.getDeclaringClass().getCanonicalName() + "." + method.getName());
    return config;
}
Also used : FunctionConfiguration(com.microsoft.azure.gradle.functions.configuration.FunctionConfiguration) StorageBaseBinding(com.microsoft.azure.gradle.functions.bindings.StorageBaseBinding) BaseBinding(com.microsoft.azure.gradle.functions.bindings.BaseBinding)

Example 3 with BaseBinding

use of com.microsoft.azure.gradle.functions.bindings.BaseBinding in project azure-gradle-plugins by lenala.

the class AnnotationHandlerImpl method parseAnnotations.

private List<BaseBinding> parseAnnotations(Supplier<Annotation[]> annotationProvider, Function<Annotation, BaseBinding> annotationParser) {
    final List<BaseBinding> bindings = new ArrayList<>();
    for (final Annotation annotation : annotationProvider.get()) {
        final BaseBinding binding = annotationParser.apply(annotation);
        if (binding != null) {
            logger.quiet("Adding binding: " + binding.toString());
            bindings.add(binding);
        }
    }
    return bindings;
}
Also used : StorageBaseBinding(com.microsoft.azure.gradle.functions.bindings.StorageBaseBinding) BaseBinding(com.microsoft.azure.gradle.functions.bindings.BaseBinding) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation)

Aggregations

BaseBinding (com.microsoft.azure.gradle.functions.bindings.BaseBinding)3 StorageBaseBinding (com.microsoft.azure.gradle.functions.bindings.StorageBaseBinding)3 FunctionConfiguration (com.microsoft.azure.gradle.functions.configuration.FunctionConfiguration)2 Annotation (java.lang.annotation.Annotation)2 ArrayList (java.util.ArrayList)2 BindingFactory (com.microsoft.azure.gradle.functions.bindings.BindingFactory)1 HttpBinding (com.microsoft.azure.gradle.functions.bindings.HttpBinding)1 FunctionName (com.microsoft.azure.serverless.functions.annotation.FunctionName)1 HttpTrigger (com.microsoft.azure.serverless.functions.annotation.HttpTrigger)1 StorageAccount (com.microsoft.azure.serverless.functions.annotation.StorageAccount)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1