本文整理汇总了Golang中github.com/Masterminds/glide/dependency.NewResolver函数的典型用法代码示例。如果您正苦于以下问题:Golang NewResolver函数的具体用法?Golang NewResolver怎么用?Golang NewResolver使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewResolver函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: List
// List lists all of the dependencies of the current project.
//
// Params:
// - dir (string): basedir
// - deep (bool): whether to do a deep scan or a shallow scan
// - format (string): The format to output (text, json, json-pretty)
func List(basedir string, deep bool, format string) {
basedir, err := filepath.Abs(basedir)
if err != nil {
msg.Die("Could not read directory: %s", err)
}
r, err := dependency.NewResolver(basedir)
if err != nil {
msg.Die("Could not create a resolver: %s", err)
}
h := &dependency.DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}, Prefix: "vendor"}
r.Handler = h
localPkgs, _, err := r.ResolveLocal(deep)
if err != nil {
msg.Die("Error listing dependencies: %s", err)
}
sort.Strings(localPkgs)
installed := make([]string, len(localPkgs))
for i, pkg := range localPkgs {
relPkg, err := filepath.Rel(basedir, pkg)
if err != nil {
// msg.Warn("Failed to Rel path: %s", err)
relPkg = pkg
}
installed[i] = relPkg
}
l := PackageList{
Installed: installed,
Missing: h.Missing,
Gopath: h.Gopath,
}
outputList(l, format)
}
开发者ID:albrow,项目名称:glide,代码行数:41,代码来源:list.go
示例2: List
func (i *Installer) List(conf *cfg.Config) []*cfg.Dependency {
base := "."
vpath := i.VendorPath()
ic := newImportCache()
v := &VersionHandler{
Destination: vpath,
Use: ic,
Imported: make(map[string]bool),
Conflicts: make(map[string]bool),
Config: conf,
}
// Update imports
res, err := dependency.NewResolver(base)
if err != nil {
msg.Die("Failed to create a resolver: %s", err)
}
res.Config = conf
res.VersionHandler = v
msg.Info("Resolving imports")
_, err = allPackages(conf.Imports, res)
if err != nil {
msg.Die("Failed to retrieve a list of dependencies: %s", err)
}
msg.Warn("devImports not resolved.")
return conf.Imports
}
开发者ID:litixsoft,项目名称:lxb,代码行数:32,代码来源:installer.go
示例3: Update
// Update updates all dependencies.
//
// It begins with the dependencies in the config file, but also resolves
// transitive dependencies. The returned lockfile has all of the dependencies
// listed, but the version reconciliation has not been done.
//
// In other words, all versions in the Lockfile will be empty.
func (i *Installer) Update(conf *cfg.Config) error {
base := "."
vpath := i.VendorPath()
ic := newImportCache()
m := &MissingPackageHandler{
destination: vpath,
cache: i.UseCache,
cacheGopath: i.UseCacheGopath,
useGopath: i.UseGopath,
home: i.Home,
force: i.Force,
updateVendored: i.UpdateVendored,
Config: conf,
Use: ic,
updated: i.Updated,
}
v := &VersionHandler{
Destination: vpath,
Use: ic,
Imported: make(map[string]bool),
Conflicts: make(map[string]bool),
Config: conf,
}
// Update imports
res, err := dependency.NewResolver(base)
if err != nil {
msg.Die("Failed to create a resolver: %s", err)
}
res.Config = conf
res.Handler = m
res.VersionHandler = v
res.ResolveAllFiles = i.ResolveAllFiles
msg.Info("Resolving imports")
_, err = allPackages(conf.Imports, res)
if err != nil {
msg.Die("Failed to retrieve a list of dependencies: %s", err)
}
if len(conf.DevImports) > 0 {
msg.Warn("dev imports not resolved.")
}
err = ConcurrentUpdate(conf.Imports, vpath, i, conf)
return err
}
开发者ID:treejames,项目名称:glide-1,代码行数:58,代码来源:installer.go
示例4: ListDeps
// ListDeps lists all of the dependencies of the current project.
//
// Params:
// - dir (string): basedir
// - deep (bool): whether to do a deep scan or a shallow scan
//
// Returns:
//
func ListDeps(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
basedir := p.Get("dir", ".").(string)
deep := p.Get("deep", true).(bool)
basedir, err := filepath.Abs(basedir)
if err != nil {
return nil, err
}
r, err := dependency.NewResolver(basedir)
if err != nil {
return nil, err
}
h := &dependency.DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}}
r.Handler = h
sortable, err := r.ResolveLocal(deep)
if err != nil {
return nil, err
}
sort.Strings(sortable)
fmt.Println("INSTALLED packages:")
for _, k := range sortable {
v, err := filepath.Rel(basedir, k)
if err != nil {
msg.Warn("Failed to Rel path: %s", err)
v = k
}
fmt.Printf("\t%s\n", v)
}
if len(h.Missing) > 0 {
fmt.Println("\nMISSING packages:")
for _, pkg := range h.Missing {
fmt.Printf("\t%s\n", pkg)
}
}
if len(h.Gopath) > 0 {
fmt.Println("\nGOPATH packages:")
for _, pkg := range h.Gopath {
fmt.Printf("\t%s\n", pkg)
}
}
return nil, nil
}
开发者ID:andrewzeneski,项目名称:glide,代码行数:56,代码来源:tree.go
示例5: List
// List lists all of the dependencies of the current project.
//
// Params:
// - dir (string): basedir
// - deep (bool): whether to do a deep scan or a shallow scan
func List(basedir string, deep bool) {
basedir, err := filepath.Abs(basedir)
if err != nil {
msg.Die("Could not read directory: %s", err)
}
r, err := dependency.NewResolver(basedir)
if err != nil {
msg.Die("Could not create a resolver: %s", err)
}
h := &dependency.DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}}
r.Handler = h
sortable, err := r.ResolveLocal(deep)
if err != nil {
msg.Die("Error listing dependencies: %s", err)
}
msg.Info("Sorting...")
sort.Strings(sortable)
msg.Puts("INSTALLED packages:")
for _, k := range sortable {
v, err := filepath.Rel(basedir, k)
if err != nil {
//msg.Warn("Failed to Rel path: %s", err)
v = k
}
msg.Puts("\t%s", v)
}
if len(h.Missing) > 0 {
msg.Puts("\nMISSING packages:")
for _, pkg := range h.Missing {
msg.Puts("\t%s", pkg)
}
}
if len(h.Gopath) > 0 {
msg.Puts("\nGOPATH packages:")
for _, pkg := range h.Gopath {
msg.Puts("\t%s", pkg)
}
}
}
开发者ID:karfield,项目名称:glide,代码行数:50,代码来源:list.go
示例6: List
// List resolves the complete dependency tree and returns a list of dependencies.
func (i *Installer) List(conf *cfg.Config) []*cfg.Dependency {
base := "."
ic := newImportCache()
v := &VersionHandler{
Use: ic,
Imported: make(map[string]bool),
Conflicts: make(map[string]bool),
Config: conf,
}
// Update imports
res, err := dependency.NewResolver(base)
if err != nil {
msg.Die("Failed to create a resolver: %s", err)
}
res.Config = conf
res.VersionHandler = v
res.ResolveAllFiles = i.ResolveAllFiles
msg.Info("Resolving imports")
_, _, err = res.ResolveLocal(false)
if err != nil {
msg.Die("Failed to resolve local packages: %s", err)
}
_, err = allPackages(conf.Imports, res, false)
if err != nil {
msg.Die("Failed to retrieve a list of dependencies: %s", err)
}
if len(conf.DevImports) > 0 {
msg.Warn("dev imports not resolved.")
}
return conf.Imports
}
开发者ID:akutz,项目名称:glide,代码行数:39,代码来源:installer.go
示例7: guessDeps
// guessDeps attempts to resolve all of the dependencies for a given project.
//
// base is the directory to start with.
// skipImport will skip running the automatic imports.
//
// FIXME: This function is likely a one-off that has a more standard alternative.
// It's also long and could use a refactor.
func guessDeps(base string, skipImport bool) *cfg.Config {
buildContext, err := util.GetBuildContext()
if err != nil {
msg.Die("Failed to build an import context: %s", err)
}
name := buildContext.PackageName(base)
msg.Info("Generating a YAML configuration file and guessing the dependencies")
config := new(cfg.Config)
// Get the name of the top level package
config.Name = name
// Import by looking at other package managers and looking over the
// entire directory structure.
// Attempt to import from other package managers.
if !skipImport {
guessImportDeps(base, config)
}
importLen := len(config.Imports)
if importLen == 0 {
msg.Info("Scanning code to look for dependencies")
} else {
msg.Info("Scanning code to look for dependencies not found in import")
}
// Resolve dependencies by looking at the tree.
r, err := dependency.NewResolver(base)
if err != nil {
msg.Die("Error creating a dependency resolver: %s", err)
}
h := &dependency.DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}}
r.Handler = h
sortable, err := r.ResolveLocal(false)
if err != nil {
msg.Die("Error resolving local dependencies: %s", err)
}
sort.Strings(sortable)
vpath := r.VendorDir
if !strings.HasSuffix(vpath, "/") {
vpath = vpath + string(os.PathSeparator)
}
for _, pa := range sortable {
n := strings.TrimPrefix(pa, vpath)
root, subpkg := util.NormalizeName(n)
if !config.HasDependency(root) && root != config.Name {
msg.Info("--> Found reference to %s\n", n)
d := &cfg.Dependency{
Name: root,
}
if len(subpkg) > 0 {
d.Subpackages = []string{subpkg}
}
config.Imports = append(config.Imports, d)
} else if config.HasDependency(root) {
if len(subpkg) > 0 {
subpkg = strings.TrimPrefix(subpkg, "/")
d := config.Imports.Get(root)
if !d.HasSubpackage(subpkg) {
msg.Info("--> Adding sub-package %s to %s\n", subpkg, root)
d.Subpackages = append(d.Subpackages, subpkg)
}
}
}
}
if len(config.Imports) == importLen && importLen != 0 {
msg.Info("--> Code scanning found no additional imports")
}
return config
}
开发者ID:treejames,项目名称:glide-1,代码行数:88,代码来源:create.go
示例8: Update
// Update updates all dependencies.
//
// It begins with the dependencies in the config file, but also resolves
// transitive dependencies. The returned lockfile has all of the dependencies
// listed, but the version reconciliation has not been done.
//
// In other words, all versions in the Lockfile will be empty.
func (i *Installer) Update(conf *cfg.Config) error {
base := "."
ic := newImportCache()
m := &MissingPackageHandler{
home: i.Home,
force: i.Force,
Config: conf,
Use: ic,
updated: i.Updated,
}
v := &VersionHandler{
Use: ic,
Imported: make(map[string]bool),
Conflicts: make(map[string]bool),
Config: conf,
}
// Update imports
res, err := dependency.NewResolver(base)
res.ResolveTest = i.ResolveTest
if err != nil {
msg.Die("Failed to create a resolver: %s", err)
}
res.Config = conf
res.Handler = m
res.VersionHandler = v
res.ResolveAllFiles = i.ResolveAllFiles
msg.Info("Resolving imports")
imps, timps, err := res.ResolveLocal(false)
if err != nil {
msg.Die("Failed to resolve local packages: %s", err)
}
var deps cfg.Dependencies
var tdeps cfg.Dependencies
for _, v := range imps {
n := res.Stripv(v)
if conf.HasIgnore(n) {
continue
}
rt, sub := util.NormalizeName(n)
if sub == "" {
sub = "."
}
d := deps.Get(rt)
if d == nil {
nd := &cfg.Dependency{
Name: rt,
Subpackages: []string{sub},
}
deps = append(deps, nd)
} else if !d.HasSubpackage(sub) {
d.Subpackages = append(d.Subpackages, sub)
}
}
if i.ResolveTest {
for _, v := range timps {
n := res.Stripv(v)
if conf.HasIgnore(n) {
continue
}
rt, sub := util.NormalizeName(n)
if sub == "" {
sub = "."
}
d := deps.Get(rt)
if d == nil {
d = tdeps.Get(rt)
}
if d == nil {
nd := &cfg.Dependency{
Name: rt,
Subpackages: []string{sub},
}
tdeps = append(tdeps, nd)
} else if !d.HasSubpackage(sub) {
d.Subpackages = append(d.Subpackages, sub)
}
}
}
_, err = allPackages(deps, res, false)
if err != nil {
msg.Die("Failed to retrieve a list of dependencies: %s", err)
}
if i.ResolveTest {
msg.Debug("Resolving test dependencies")
_, err = allPackages(tdeps, res, true)
if err != nil {
//.........这里部分代码省略.........
开发者ID:akutz,项目名称:glide,代码行数:101,代码来源:installer.go
示例9: guessDeps
// guessDeps attempts to resolve all of the dependencies for a given project.
//
// base is the directory to start with.
// skipImport will skip running the automatic imports.
//
// FIXME: This function is likely a one-off that has a more standard alternative.
// It's also long and could use a refactor.
func guessDeps(base string, skipImport bool) *cfg.Config {
buildContext, err := util.GetBuildContext()
if err != nil {
msg.Die("Failed to build an import context: %s", err)
}
name := buildContext.PackageName(base)
msg.Info("Generating a YAML configuration file and guessing the dependencies")
config := new(cfg.Config)
// Get the name of the top level package
config.Name = name
// Import by looking at other package managers and looking over the
// entire directory structure.
// Attempt to import from other package managers.
if !skipImport {
msg.Info("Attempting to import from other package managers (use --skip-import to skip)")
deps := []*cfg.Dependency{}
absBase, err := filepath.Abs(base)
if err != nil {
msg.Die("Failed to resolve location of %s: %s", base, err)
}
if d, ok := guessImportGodep(absBase); ok {
msg.Info("Importing Godep configuration")
msg.Warn("Godep uses commit id versions. Consider using Semantic Versions with Glide")
deps = d
} else if d, ok := guessImportGPM(absBase); ok {
msg.Info("Importing GPM configuration")
deps = d
} else if d, ok := guessImportGB(absBase); ok {
msg.Info("Importing GB configuration")
deps = d
}
for _, i := range deps {
msg.Info("Found imported reference to %s\n", i.Name)
config.Imports = append(config.Imports, i)
}
}
// Resolve dependencies by looking at the tree.
r, err := dependency.NewResolver(base)
if err != nil {
msg.Die("Error creating a dependency resolver: %s", err)
}
h := &dependency.DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}}
r.Handler = h
sortable, err := r.ResolveLocal(false)
if err != nil {
msg.Die("Error resolving local dependencies: %s", err)
}
sort.Strings(sortable)
vpath := r.VendorDir
if !strings.HasSuffix(vpath, "/") {
vpath = vpath + string(os.PathSeparator)
}
for _, pa := range sortable {
n := strings.TrimPrefix(pa, vpath)
root, subpkg := util.NormalizeName(n)
if !config.HasDependency(root) {
msg.Info("Found reference to %s\n", n)
d := &cfg.Dependency{
Name: root,
}
if len(subpkg) > 0 {
d.Subpackages = []string{subpkg}
}
config.Imports = append(config.Imports, d)
} else {
if len(subpkg) > 0 {
subpkg = strings.TrimPrefix(subpkg, "/")
d := config.Imports.Get(root)
if !d.HasSubpackage(subpkg) {
msg.Info("Adding sub-package %s to %s\n", subpkg, root)
d.Subpackages = append(d.Subpackages, subpkg)
}
}
}
}
return config
}
开发者ID:karfield,项目名称:glide,代码行数:99,代码来源:create.go
示例10: GuessDeps
// GuessDeps tries to get the dependencies for the current directory.
//
// Params
// - dirname (string): Directory to use as the base. Default: "."
// - skipImport (book): Whether to skip importing from Godep, GPM, and gb
func GuessDeps(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
buildContext, err := util.GetBuildContext()
if err != nil {
return nil, err
}
base := p.Get("dirname", ".").(string)
skipImport := p.Get("skipImport", false).(bool)
name := guessPackageName(buildContext, base)
Info("Generating a YAML configuration file and guessing the dependencies")
config := new(cfg.Config)
// Get the name of the top level package
config.Name = name
// Import by looking at other package managers and looking over the
// entire directory structure.
// Attempt to import from other package managers.
if !skipImport {
Info("Attempting to import from other package managers (use --skip-import to skip)")
deps := []*cfg.Dependency{}
absBase, err := filepath.Abs(base)
if err != nil {
return nil, err
}
if d, ok := guessImportGodep(absBase); ok {
Info("Importing Godep configuration")
Warn("Godep uses commit id versions. Consider using Semantic Versions with Glide")
deps = d
} else if d, ok := guessImportGPM(absBase); ok {
Info("Importing GPM configuration")
deps = d
} else if d, ok := guessImportGB(absBase); ok {
Info("Importing GB configuration")
deps = d
}
for _, i := range deps {
Info("Found imported reference to %s\n", i.Name)
config.Imports = append(config.Imports, i)
}
}
// Resolve dependencies by looking at the tree.
r, err := dependency.NewResolver(base)
if err != nil {
return nil, err
}
h := &dependency.DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}}
r.Handler = h
sortable, err := r.ResolveLocal(false)
if err != nil {
return nil, err
}
sort.Strings(sortable)
vpath := r.VendorDir
if !strings.HasSuffix(vpath, "/") {
vpath = vpath + string(os.PathSeparator)
}
for _, pa := range sortable {
n := strings.TrimPrefix(pa, vpath)
root := util.GetRootFromPackage(n)
if !config.HasDependency(root) {
Info("Found reference to %s\n", n)
d := &cfg.Dependency{
Name: root,
}
subpkg := strings.TrimPrefix(n, root)
if len(subpkg) > 0 && subpkg != "/" {
d.Subpackages = []string{subpkg}
}
config.Imports = append(config.Imports, d)
} else {
subpkg := strings.TrimPrefix(n, root)
if len(subpkg) > 0 && subpkg != "/" {
subpkg = strings.TrimPrefix(subpkg, "/")
d := config.Imports.Get(root)
f := false
for _, v := range d.Subpackages {
if v == subpkg {
f = true
}
}
if !f {
Info("Adding sub-package %s to %s\n", subpkg, root)
d.Subpackages = append(d.Subpackages, subpkg)
//.........这里部分代码省略.........
开发者ID:rudle,项目名称:glide,代码行数:101,代码来源:guess_deps.go
注:本文中的github.com/Masterminds/glide/dependency.NewResolver函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论