From a3cac39202ea33d25b8c662718aca0fdfa1bdf62 Mon Sep 17 00:00:00 2001 From: Basil Peace Date: Sun, 26 Mar 2017 21:57:35 +0300 Subject: [PATCH] fix: Support basic Packer template functions --- README.md | 7 +++++++ .../org/fidata/gradle/packer/GradlePackerPlugin.groovy | 7 ++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8c8ff5e..cce8242 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,13 @@ saves results in Gradle's cache. `override` configuration is supported. +* Functions: + + Now only a subset of Packer template functions is supported: + * `pwd` + * `template_dir` + * `timestamp` + ## Notes 1. Gradle (as of 3.2) [can't handle URLs] (https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:file(java.lang.Object)). diff --git a/src/main/groovy/org/fidata/gradle/packer/GradlePackerPlugin.groovy b/src/main/groovy/org/fidata/gradle/packer/GradlePackerPlugin.groovy index 14f5bfa..ff164dd 100644 --- a/src/main/groovy/org/fidata/gradle/packer/GradlePackerPlugin.groovy +++ b/src/main/groovy/org/fidata/gradle/packer/GradlePackerPlugin.groovy @@ -63,7 +63,11 @@ class GradlePackerPlugin implements Plugin { project.logger.info(sprintf('gradle-packer-plugin: Processing %s template', [fileName])) File templateFile = project.file(fileName) Map InputJSON = new JsonSlurper().parse(templateFile) - Map variables = [:] + Map variables = [ + 'pwd': project.file('.').getCanonicalPath(), + 'template_dir': templateFile.getParentFile().getAbsolutePath(), + 'timestamp': project.extensions.packer.initTime.time.intdiv(1000), + ] List customVariablesCmdLine = [] for (variable in InputJSON['variables']) if (project.packer.customVariables[variable.key]) { @@ -356,6 +360,7 @@ class PackerTemplate { class PackerPluginExtension { Map customVariables = [:] List templates = [] + Date initTime = new Date() def template(String fileName, Task parentTask = null) { templates.push(new PackerTemplate(fileName: fileName, parentTask: parentTask))