github.com/jdhenke/godel@v0.0.0-20161213181855-abeb3861bf0d/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 "", errors.Wrapf(err, "Failed to create path to %v", productPath)
    37  	}
    38  
    39  	if err := copyArtifact(paths.pomFilePath, productPath, stdout); err != nil {
    40  		return "", errors.Wrapf(err, "Failed to copy POM file")
    41  	}
    42  
    43  	if err := copyArtifact(paths.artifactPath, productPath, stdout); err != nil {
    44  		return "", errors.Wrapf(err, "Failed to copy artifact file")
    45  	}
    46  
    47  	return "", nil
    48  }
    49  
    50  func copyArtifact(src, dstDir string, stdout io.Writer) error {
    51  	dst := path.Join(dstDir, path.Base(src))
    52  	fmt.Fprintf(stdout, "Copying %v to %v...\n", src, dst)
    53  	return shutil.CopyFile(src, dst, false)
    54  }