Commit 76ab8709 authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

packer: PostProcessor takes a UI [GH-20]

parent 73cb1a3f
......@@ -169,7 +169,7 @@ PostProcessorRunSeqLoop:
artifact := builderArtifact
for _, corePP := range ppSeq {
var err error
artifact, err = corePP.processor.PostProcess(artifact)
artifact, err = corePP.processor.PostProcess(ui, artifact)
if err != nil {
errors = append(errors, fmt.Errorf("Post-processor failed: %s", err))
continue PostProcessorRunSeqLoop
......
......@@ -19,13 +19,13 @@ func (c *cmdPostProcessor) Configure(config interface{}) error {
return c.p.Configure(config)
}
func (c *cmdPostProcessor) PostProcess(a packer.Artifact) (packer.Artifact, error) {
func (c *cmdPostProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Artifact, error) {
defer func() {
r := recover()
c.checkExit(r, nil)
}()
return c.p.PostProcess(a)
return c.p.PostProcess(ui, a)
}
func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) {
......
......@@ -12,7 +12,7 @@ func (helperPostProcessor) Configure(interface{}) error {
return nil
}
func (helperPostProcessor) PostProcess(packer.Artifact) (packer.Artifact, error) {
func (helperPostProcessor) PostProcess(packer.Ui, packer.Artifact) (packer.Artifact, error) {
return nil, nil
}
......
......@@ -13,5 +13,5 @@ type PostProcessor interface {
// PostProcess takes a previously created Artifact and produces another
// Artifact. If an error occurs, it should return that error.
PostProcess(Artifact) (Artifact, error)
PostProcess(Ui, Artifact) (Artifact, error)
}
......@@ -5,6 +5,7 @@ type TestPostProcessor struct {
configVal interface{}
ppCalled bool
ppArtifact Artifact
ppUi Ui
}
func (pp *TestPostProcessor) Configure(v interface{}) error {
......@@ -13,8 +14,9 @@ func (pp *TestPostProcessor) Configure(v interface{}) error {
return nil
}
func (pp *TestPostProcessor) PostProcess(a Artifact) (Artifact, error) {
func (pp *TestPostProcessor) PostProcess(ui Ui, a Artifact) (Artifact, error) {
pp.ppCalled = true
pp.ppArtifact = a
pp.ppUi = ui
return nil, nil
}
......@@ -33,9 +33,10 @@ func (p *postProcessor) Configure(raw interface{}) (err error) {
return
}
func (p *postProcessor) PostProcess(a packer.Artifact) (packer.Artifact, error) {
func (p *postProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Artifact, error) {
server := rpc.NewServer()
RegisterArtifact(server, a)
RegisterUi(server, ui)
var response PostProcessorProcessResponse
if err := p.client.Call("PostProcessor.PostProcess", serveSingleConn(server), &response); err != nil {
......@@ -71,7 +72,7 @@ func (p *PostProcessorServer) PostProcess(address string, reply *PostProcessorPr
responseAddress := ""
artifact, err := p.p.PostProcess(Artifact(client))
artifact, err := p.p.PostProcess(&Ui{client}, Artifact(client))
if err == nil && artifact != nil {
server := rpc.NewServer()
RegisterArtifact(server, artifact)
......
......@@ -13,6 +13,7 @@ type TestPostProcessor struct {
configVal interface{}
ppCalled bool
ppArtifact packer.Artifact
ppUi packer.Ui
}
func (pp *TestPostProcessor) Configure(v interface{}) error {
......@@ -21,9 +22,10 @@ func (pp *TestPostProcessor) Configure(v interface{}) error {
return nil
}
func (pp *TestPostProcessor) PostProcess(a packer.Artifact) (packer.Artifact, error) {
func (pp *TestPostProcessor) PostProcess(ui packer.Ui, a packer.Artifact) (packer.Artifact, error) {
pp.ppCalled = true
pp.ppArtifact = a
pp.ppUi = ui
return testPostProcessorArtifact, nil
}
......@@ -60,7 +62,8 @@ func TestPostProcessorRPC(t *testing.T) {
// Test PostProcess
a := new(testArtifact)
artifact, err := pClient.PostProcess(a)
ui := new(testUi)
artifact, err := pClient.PostProcess(ui, a)
if err != nil {
t.Fatalf("err: %s", err)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment