From f851e56dbda8cdcd9f5edc7b696cd66417a18b99 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 6 Jun 2013 15:12:54 -0700 Subject: [PATCH] builder/vmware: Artifacts implemented --- builder/vmware/artifact.go | 26 ++++++++++++++++++++++++++ builder/vmware/artifact_test.go | 14 ++++++++++++++ builder/vmware/builder.go | 25 ++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 builder/vmware/artifact.go create mode 100644 builder/vmware/artifact_test.go diff --git a/builder/vmware/artifact.go b/builder/vmware/artifact.go new file mode 100644 index 000000000..6ebbf748c --- /dev/null +++ b/builder/vmware/artifact.go @@ -0,0 +1,26 @@ +package vmware + +import "fmt" + +// Artifact is the result of running the VMware builder, namely a set +// of files associated with the resulting machine. +type Artifact struct { + dir string + f []string +} + +func (*Artifact) BuilderId() string { + return BuilderId +} + +func (a *Artifact) Files() []string { + return a.f +} + +func (*Artifact) Id() string { + return "VM" +} + +func (a *Artifact) String() string { + return fmt.Sprintf("VM files in directory: %s", a.dir) +} diff --git a/builder/vmware/artifact_test.go b/builder/vmware/artifact_test.go new file mode 100644 index 000000000..3cf90c8e4 --- /dev/null +++ b/builder/vmware/artifact_test.go @@ -0,0 +1,14 @@ +package vmware + +import ( + "testing" + "github.com/mitchellh/packer/packer" +) + +func TestArtifact_Impl(t *testing.T) { + var raw interface{} + raw = &Artifact{} + if _, ok := raw.(packer.Artifact); !ok { + t.Fatal("Artifact must be a proper artifact") + } +} diff --git a/builder/vmware/builder.go b/builder/vmware/builder.go index d95f1eb33..935f15597 100644 --- a/builder/vmware/builder.go +++ b/builder/vmware/builder.go @@ -7,6 +7,8 @@ import ( "github.com/mitchellh/multistep" "github.com/mitchellh/packer/packer" "log" + "os" + "path/filepath" "time" ) @@ -114,7 +116,28 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook) packer.Artifact { b.runner = &multistep.BasicRunner{Steps: steps} b.runner.Run(state) - return nil + // If we were interrupted or cancelled, then just exit. + if _, ok := state[multistep.StateCancelled]; ok { + return nil + } + + if _, ok := state[multistep.StateHalted]; ok { + return nil + } + + // Compile the artifact list + files := make([]string, 0, 10) + visit := func(path string, info os.FileInfo, err error) error { + files = append(files, path) + return err + } + + if err := filepath.Walk(b.config.OutputDir, visit); err != nil { + ui.Error(fmt.Sprintf("Error collecting result files: %s", err)) + return nil + } + + return &Artifact{b.config.OutputDir, files} } func (b *Builder) Cancel() {