github.com/golang/dep@v0.5.4/analyzer.go (about) 1 // Copyright 2016 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package dep 6 7 import ( 8 "os" 9 "path/filepath" 10 11 "github.com/golang/dep/gps" 12 "github.com/golang/dep/internal/fs" 13 ) 14 15 // Analyzer implements gps.ProjectAnalyzer. 16 type Analyzer struct{} 17 18 // HasDepMetadata determines if a dep manifest exists at the specified path. 19 func (a Analyzer) HasDepMetadata(path string) bool { 20 mf := filepath.Join(path, ManifestName) 21 fileOK, err := fs.IsRegular(mf) 22 return err == nil && fileOK 23 } 24 25 // DeriveManifestAndLock reads and returns the manifest at path/ManifestName or nil if one is not found. 26 // The Lock is always nil for now. 27 func (a Analyzer) DeriveManifestAndLock(path string, n gps.ProjectRoot) (gps.Manifest, gps.Lock, error) { 28 if !a.HasDepMetadata(path) { 29 return nil, nil, nil 30 } 31 32 f, err := os.Open(filepath.Join(path, ManifestName)) 33 if err != nil { 34 return nil, nil, err 35 } 36 defer f.Close() 37 38 // Ignore warnings irrelevant to user. 39 m, _, err := readManifest(f) 40 if err != nil { 41 return nil, nil, err 42 } 43 44 return m, nil, nil 45 } 46 47 // Info returns Analyzer's name and version info. 48 func (a Analyzer) Info() gps.ProjectAnalyzerInfo { 49 return gps.ProjectAnalyzerInfo{ 50 Name: "dep", 51 Version: 1, 52 } 53 }