From 9e78cbaa89a6a64ec022b13463acfdeac8b20850 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 18 Jun 2013 20:38:21 -0700 Subject: [PATCH] packer: PostProcessor takes a UI [GH-20] --- packer/build.go | 2 +- packer/plugin/post_processor.go | 4 ++-- packer/plugin/post_processor_test.go | 2 +- packer/post_processor.go | 2 +- packer/post_processor_test.go | 4 +++- packer/rpc/post_processor.go | 5 +++-- packer/rpc/post_processor_test.go | 7 +++++-- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packer/build.go b/packer/build.go index 895969a0a..b8536687b 100644 --- a/packer/build.go +++ b/packer/build.go @@ -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 diff --git a/packer/plugin/post_processor.go b/packer/plugin/post_processor.go index 52044ec23..74d49a7bc 100644 --- a/packer/plugin/post_processor.go +++ b/packer/plugin/post_processor.go @@ -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()) { diff --git a/packer/plugin/post_processor_test.go b/packer/plugin/post_processor_test.go index ef50e8d68..81e7dca77 100644 --- a/packer/plugin/post_processor_test.go +++ b/packer/plugin/post_processor_test.go @@ -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 } diff --git a/packer/post_processor.go b/packer/post_processor.go index d84d3eafc..e95a36561 100644 --- a/packer/post_processor.go +++ b/packer/post_processor.go @@ -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) } diff --git a/packer/post_processor_test.go b/packer/post_processor_test.go index 7e06e51fe..08fb55712 100644 --- a/packer/post_processor_test.go +++ b/packer/post_processor_test.go @@ -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 } diff --git a/packer/rpc/post_processor.go b/packer/rpc/post_processor.go index bec37a9c4..3f4948d1f 100644 --- a/packer/rpc/post_processor.go +++ b/packer/rpc/post_processor.go @@ -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) diff --git a/packer/rpc/post_processor_test.go b/packer/rpc/post_processor_test.go index e3d672549..eb7a2f7c8 100644 --- a/packer/rpc/post_processor_test.go +++ b/packer/rpc/post_processor_test.go @@ -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) }