2013-05-09 00:05:35 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2013-05-09 00:05:35 -04:00
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type cmdBuilder struct {
|
|
|
|
builder packer.Builder
|
2013-06-11 14:03:36 -04:00
|
|
|
client *Client
|
2013-05-09 00:05:35 -04:00
|
|
|
}
|
|
|
|
|
2013-11-02 23:51:26 -04:00
|
|
|
func (b *cmdBuilder) Prepare(config ...interface{}) ([]string, error) {
|
2013-05-09 00:05:35 -04:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
b.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
2013-06-14 15:27:50 -04:00
|
|
|
return b.builder.Prepare(config...)
|
2013-05-09 00:05:35 -04:00
|
|
|
}
|
|
|
|
|
2013-06-12 19:06:56 -04:00
|
|
|
func (b *cmdBuilder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
2013-05-09 00:05:35 -04:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
b.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
2013-06-10 01:00:47 -04:00
|
|
|
return b.builder.Run(ui, hook, cache)
|
2013-05-09 00:05:35 -04:00
|
|
|
}
|
|
|
|
|
2013-06-03 17:44:34 -04:00
|
|
|
func (b *cmdBuilder) Cancel() {
|
2013-06-03 18:31:28 -04:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
b.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
|
|
|
b.builder.Cancel()
|
2013-06-03 17:44:34 -04:00
|
|
|
}
|
|
|
|
|
2013-05-09 00:05:35 -04:00
|
|
|
func (c *cmdBuilder) checkExit(p interface{}, cb func()) {
|
|
|
|
if c.client.Exited() && cb != nil {
|
|
|
|
cb()
|
2013-08-20 02:38:22 -04:00
|
|
|
} else if p != nil && !Killed {
|
2013-05-09 00:05:35 -04:00
|
|
|
log.Panic(p)
|
|
|
|
}
|
|
|
|
}
|