github.com/joshdk/godel@v0.0.0-20170529232908-862138a45aee/apps/distgo/cmd/publish/local_publish.go (about) 1 // Copyright 2016 Palantir Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package publish 16 17 import ( 18 "fmt" 19 "io" 20 "os" 21 "path" 22 23 "github.com/pkg/errors" 24 "github.com/termie/go-shutil" 25 26 "github.com/palantir/godel/apps/distgo/params" 27 ) 28 29 type LocalPublishInfo struct { 30 Path string 31 } 32 33 func (l *LocalPublishInfo) Publish(buildSpec params.ProductBuildSpec, paths ProductPaths, stdout io.Writer) ([]string, error) { 34 productPath := path.Join(l.Path, paths.productPath) 35 if err := os.MkdirAll(productPath, 0755); err != nil { 36 return nil, errors.Wrapf(err, "Failed to create path to %v", productPath) 37 } 38 39 if _, err := copyArtifact(paths.pomFilePath, productPath, stdout); err != nil { 40 return nil, errors.Wrapf(err, "Failed to copy POM file") 41 } 42 43 var outputPaths []string 44 for _, currArtifactPath := range paths.artifactPaths { 45 outputPath, err := copyArtifact(currArtifactPath, productPath, stdout) 46 if err != nil { 47 return outputPaths, errors.Wrapf(err, "Failed to copy artifact file") 48 } 49 outputPaths = append(outputPaths, outputPath) 50 } 51 return outputPaths, nil 52 } 53 54 func copyArtifact(src, dstDir string, stdout io.Writer) (string, error) { 55 dst := path.Join(dstDir, path.Base(src)) 56 fmt.Fprintf(stdout, "Copying %v to %v\n", src, dst) 57 return dst, shutil.CopyFile(src, dst, false) 58 }