packer: PostProcessor takes a UI [GH-20]

This commit is contained in:
Mitchell Hashimoto 2013-06-18 20:38:21 -07:00
parent 44087ca7df
commit 9e78cbaa89
7 changed files with 16 additions and 10 deletions

View File

@ -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

View File

@ -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()) {

View File

@ -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
}

View File

@ -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)
}

View File

@ -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
}

View File

@ -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)

View File

@ -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)
}