Skip to content

Commit

Permalink
fix: Support basic Packer template functions
Browse files Browse the repository at this point in the history
  • Loading branch information
grv87 committed Mar 26, 2017
1 parent 9eed898 commit a3cac39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ class GradlePackerPlugin implements Plugin<Project> {
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<String> customVariablesCmdLine = []
for (variable in InputJSON['variables'])
if (project.packer.customVariables[variable.key]) {
Expand Down Expand Up @@ -356,6 +360,7 @@ class PackerTemplate {
class PackerPluginExtension {
Map customVariables = [:]
List<PackerTemplate> templates = []
Date initTime = new Date()

def template(String fileName, Task parentTask = null) {
templates.push(new PackerTemplate(fileName: fileName, parentTask: parentTask))
Expand Down

0 comments on commit a3cac39

Please sign in to comment.