github.com/joshdk/godel@v0.0.0-20170529232908-862138a45aee/apps/distgo/cmd/dist/dister.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 dist
    16  
    17  import (
    18  	"fmt"
    19  	"io"
    20  	"path"
    21  
    22  	"github.com/palantir/pkg/specdir"
    23  
    24  	"github.com/palantir/godel/apps/distgo/params"
    25  )
    26  
    27  type Dister interface {
    28  	NumArtifacts() int
    29  	ArtifactPathsInOutputDir(buildSpec params.ProductBuildSpec) []string
    30  	Dist(buildSpecWithDeps params.ProductBuildSpecWithDeps, distCfg params.Dist, outputProductDir string, spec specdir.LayoutSpec, values specdir.TemplateValues, stdout io.Writer) (Packager, error)
    31  	DistPackageType() string
    32  }
    33  
    34  func ToDister(info params.DistInfo) Dister {
    35  	switch info.Type() {
    36  	default:
    37  		panic(fmt.Errorf("unrecognized type: %v", info.Type()))
    38  	case params.SLSDistType:
    39  		return (*slsDister)(info.(*params.SLSDistInfo))
    40  	case params.BinDistType:
    41  		return (*binDister)(info.(*params.BinDistInfo))
    42  	case params.ManualDistType:
    43  		return (*manualDister)(info.(*params.ManualDistInfo))
    44  	case params.OSArchBinDistType:
    45  		return (*osArchsBinDister)(info.(*params.OSArchsBinDistInfo))
    46  	case params.RPMDistType:
    47  		return (*rpmDister)(info.(*params.RPMDistInfo))
    48  	}
    49  }
    50  
    51  func FullArtifactsPaths(dister Dister, buildSpec params.ProductBuildSpec, distCfg params.Dist) []string {
    52  	var outPaths []string
    53  	for _, currPath := range dister.ArtifactPathsInOutputDir(buildSpec) {
    54  		outPaths = append(outPaths, path.Join(buildSpec.ProjectDir, distCfg.OutputDir, currPath))
    55  	}
    56  	return outPaths
    57  }