Skip to content

Commit

Permalink
fix: Fix errors with Vagrant post-processor and cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
grv87 committed Jan 1, 2017
1 parent 3e961ed commit 73cfab7
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/main/groovy/org/fidata/gradle/packer/GradlePackerPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class GradlePackerPlugin implements Plugin<Project> {
group 'Build'
ext.builderType = builderType
ext.buildName = buildName
ext.fullBuildName = fullBuildName
ext.cleanTask = project.task("clean-$fullBuildName") {
group 'Clean'
}
commandLine((['packer', 'build', "-only=$buildName"] + customVariablesCmdLine + (project.gradle.startParameter.logLevel >= LogLevel.DEBUG ? ['-debug'] : []) + [fileName]))
inputs.file templateFile
}
Expand Down Expand Up @@ -129,19 +133,16 @@ class GradlePackerPlugin implements Plugin<Project> {
// Output filename when no post-processors are used - default
t.ext.outputFileName = project.file(new File(outputDir, VMName + '.' + (builder['format'] ?: 'ovf'))).toString()
project.logger.info(sprintf('gradle-packer-plugin: outputFileName %s', [t.outputFileName]))
/*t.dependsOn*/ project.task("clean-$imageName-$buildName") {
Task unregisterVM = project.task([type: Exec], "unregisterVM-$fullBuildName") {
group 'Clean'
Task unregisterVM = project.task([type: Exec], "unregisterVM-$imageName-$buildName") {
group 'Clean'
commandLine 'VBoxManage', 'unregistervm', "$VMName", '--delete'
ignoreExitValue true
}
dependsOn unregisterVM
dependsOn project.task([type: Delete], "deleteOutputDir-$imageName-$buildName") {
group 'Clean'
shouldRunAfter unregisterVM
delete outputDir
}
commandLine 'VBoxManage', 'unregistervm', "$VMName", '--delete'
ignoreExitValue true
}
t.cleanTask.dependsOn unregisterVM
t.cleanTask.dependsOn project.task([type: Delete], "deleteOutputDir-$fullBuildName") {
group 'Clean'
shouldRunAfter unregisterVM
delete outputDir
}
}

Expand Down Expand Up @@ -241,11 +242,12 @@ class GradlePackerPlugin implements Plugin<Project> {
if (p.containsKey('only'))
for (buildName in p['only'])
processedTasks[buildName] = ts[buildName]
else if (p.containsKey('except')) {
else {
for (t in ts)
processedTasks[t.key] = t.value
for (buildName in p['except'])
processedTasks.remove buildName
if (p.containsKey('except'))
for (buildName in p['except'])
processedTasks.remove buildName
}
for (t in processedTasks.values()) {
Map postProcessor = new HashMap(p)
Expand All @@ -262,20 +264,23 @@ class GradlePackerPlugin implements Plugin<Project> {
if (postProcessor.containsKey('include'))
for (include in postProcessor['include'])
t.inputs.file parseString(include, variables)
String vargantProvider
String vagrantProvider
switch (t.builderType) {
case 'virtualbox-iso':
case 'virtualbox-ovf':
vargantProvider = 'virtualbox'
vagrantProvider = 'virtualbox'
break
case 'amazon-ebs':
vargantProvider = 'aws'
vagrantProvider = 'aws'
break
}
t.ext.outputFileName = parseString(postProcessor['output'] ?: 'packer_{{.BuildName}}_{{.Provider}}.box', variables + ['.Provider': vargantProvider, '.ArtifactId': vagrantProvider, '.BuildName': t.buildName])
t.ext.outputFileName = parseString(postProcessor['output'] ?: 'packer_{{.BuildName}}_{{.Provider}}.box', variables + ['.Provider': vagrantProvider, '.ArtifactId': vagrantProvider, '.BuildName': t.buildName])
project.logger.info(sprintf('gradle-packer-plugin: outputFileName %s', [t.outputFileName]))
t.cleanTask.dependsOn project.task([type: Delete], "deleteOutputFile-${t.fullBuildName}") {
group 'Clean'
delete t.outputFileName
}
}

}
}

Expand Down

0 comments on commit 73cfab7

Please sign in to comment.