Search in sources :

Example 1 with FunctionTemplate

use of com.microsoft.azure.gradle.functions.template.FunctionTemplate in project azure-gradle-plugins by lenala.

the class AddTask method loadAllFunctionTemplates.

private List<FunctionTemplate> loadAllFunctionTemplates() throws Exception {
    getLogger().quiet(LOAD_TEMPLATES);
    try (final InputStream is = AddTask.class.getResourceAsStream("/templates.json")) {
        final String templatesJsonStr = IOUtils.toString(is);
        final List<FunctionTemplate> templates = parseTemplateJson(templatesJsonStr);
        getLogger().quiet(LOAD_TEMPLATES_DONE);
        return templates;
    } catch (Exception e) {
        getLogger().quiet(LOAD_TEMPLATES_FAIL);
        throw e;
    }
}
Also used : FunctionTemplate(com.microsoft.azure.gradle.functions.template.FunctionTemplate) InputStream(java.io.InputStream) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException)

Example 2 with FunctionTemplate

use of com.microsoft.azure.gradle.functions.template.FunctionTemplate in project azure-gradle-plugins by lenala.

the class AddTask method add.

@TaskAction
void add() {
    try {
        final List<FunctionTemplate> templates = loadAllFunctionTemplates();
        final FunctionTemplate template = getFunctionTemplate(templates);
        final Map params = prepareRequiredParameters(template);
        final String newFunctionClass = substituteParametersInTemplate(template, params);
        saveNewFunctionToFile(newFunctionClass);
    } catch (Exception ex) {
        throw new TaskExecutionException(this, ex);
    }
}
Also used : TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) FunctionTemplate(com.microsoft.azure.gradle.functions.template.FunctionTemplate) HashMap(java.util.HashMap) Map(java.util.Map) TaskExecutionException(org.gradle.api.tasks.TaskExecutionException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) TaskAction(org.gradle.api.tasks.TaskAction)

Aggregations

FunctionTemplate (com.microsoft.azure.gradle.functions.template.FunctionTemplate)2 FileAlreadyExistsException (java.nio.file.FileAlreadyExistsException)2 TaskExecutionException (org.gradle.api.tasks.TaskExecutionException)2 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TaskAction (org.gradle.api.tasks.TaskAction)1