示例#1
0
func findResolver(name, dst string) (Resolver, error) {
	if name != "" {
		return findResolverByName(name)
	}

	cb, _ := cookbook.NewCookbook(".")

	// If the current folder is a cookbook and its dependencies have
	// already been resolved, only update this cookbook with rsync.
	// TODO: improve this check by comparing timestamps etc.
	if cb.Name != "" && util.FileExist(dst) {
		return dir.Resolver{}, nil
	}

	if util.FileExist("Berksfile") {
		return berkshelf.Resolver{}, nil
	}

	if util.FileExist("Cheffile") {
		return librarian.Resolver{}, nil
	}

	if cb.Name != "" {
		return dir.Resolver{}, nil
	}

	log.Error("Berksfile, Cheffile, or metadata.rb must exist in current directory")
	return nil, errors.New("cookbooks could not be found")
}
示例#2
0
// Files returns the names of all cookbook files. Other files are ignored.
func (cb Cookbook) Files() []string {
	fileList := [...]string{
		"README.md",
		"metadata.json",
		"metadata.rb",
		"attributes",
		"definitions",
		"files",
		"libraries",
		"providers",
		"recipes",
		"resources",
		"templates",
	}

	var files []string
	for _, f := range fileList {
		name := path.Join(cb.Path, f)
		if util.FileExist(name) {
			files = append(files, name)
		}
	}

	return files
}
示例#3
0
func useBundler() bool {
	if _, err := exec.LookPath("bundle"); err != nil {
		// Bundler not installed
		return false
	}
	if !util.FileExist("Gemfile") {
		// No Gemfile found
		return false
	}
	return true
}
示例#4
0
// NewCookbook returns a Cookbook that is located at cookbookPath.
func NewCookbook(cookbookPath string) (*Cookbook, error) {
	cb := Cookbook{Path: cookbookPath}

	metadataPath := path.Join(cookbookPath, metadata.Filename)
	if util.FileExist(metadataPath) {
		metadata, err := metadata.ParseFile(metadataPath)
		if err != nil {
			return nil, err
		}
		cb.Name = metadata.Name
		cb.Version = metadata.Version
	}

	return &cb, nil
}
示例#5
0
func TestResolve(t *testing.T) {
	util.InDir("../../testdata", func() {
		cookbookPath := "test-cookbooks"
		defer os.RemoveAll(cookbookPath)

		assert.NoError(t, Resolver{}.Resolve(cookbookPath))

		expectFiles := []string{
			"practicingruby/README.md",
			"practicingruby/attributes",
			"practicingruby/metadata.rb",
			"practicingruby/recipes",
		}
		for _, f := range expectFiles {
			assert.True(t, util.FileExist(path.Join(cookbookPath, f)))
		}
	})
}