2016-10-18 18:29:29 +03:00
|
|
|
// Copyright 2016 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2017-01-27 23:39:07 +03:00
|
|
|
package dep
|
2016-10-18 18:29:29 +03:00
|
|
|
|
|
|
|
import (
|
2016-12-07 04:04:34 +03:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2017-05-10 19:21:00 +03:00
|
|
|
"github.com/golang/dep/internal/fs"
|
2017-05-10 07:13:22 +03:00
|
|
|
"github.com/golang/dep/internal/gps"
|
2016-10-18 18:29:29 +03:00
|
|
|
)
|
|
|
|
|
2017-05-31 22:48:48 +03:00
|
|
|
// Analyzer implements gps.ProjectAnalyzer.
|
2017-04-15 08:23:16 +03:00
|
|
|
type Analyzer struct{}
|
2016-10-18 18:29:29 +03:00
|
|
|
|
2017-05-28 00:19:40 +03:00
|
|
|
// HasDepMetadata determines if a dep manifest exists at the specified path.
|
|
|
|
func (a Analyzer) HasDepMetadata(path string) bool {
|
2017-01-27 23:39:07 +03:00
|
|
|
mf := filepath.Join(path, ManifestName)
|
2017-05-28 00:19:40 +03:00
|
|
|
fileOK, err := fs.IsRegular(mf)
|
|
|
|
return err == nil && fileOK
|
|
|
|
}
|
|
|
|
|
2017-05-31 22:48:48 +03:00
|
|
|
// DeriveManifestAndLock reads and returns the manifest at path/ManifestName or nil if one is not found.
|
|
|
|
// The Lock is always nil for now.
|
2017-05-28 00:19:40 +03:00
|
|
|
func (a Analyzer) DeriveManifestAndLock(path string, n gps.ProjectRoot) (gps.Manifest, gps.Lock, error) {
|
|
|
|
if !a.HasDepMetadata(path) {
|
2016-12-07 04:04:34 +03:00
|
|
|
return nil, nil, nil
|
|
|
|
}
|
2017-05-28 00:19:40 +03:00
|
|
|
|
|
|
|
f, err := os.Open(filepath.Join(path, ManifestName))
|
2016-12-07 04:04:34 +03:00
|
|
|
if err != nil {
|
2017-02-20 01:36:16 +03:00
|
|
|
return nil, nil, err
|
2016-12-07 04:04:34 +03:00
|
|
|
}
|
2017-01-24 20:20:30 +03:00
|
|
|
defer f.Close()
|
|
|
|
|
2017-05-10 07:57:14 +03:00
|
|
|
// Ignore warnings irrelevant to user.
|
|
|
|
m, _, err := readManifest(f)
|
2016-12-07 04:04:34 +03:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2017-07-25 07:22:22 +03:00
|
|
|
|
2016-12-07 04:04:34 +03:00
|
|
|
return m, nil, nil
|
2016-10-18 18:29:29 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 19:56:28 +03:00
|
|
|
// Info returns Analyzer's name and version info.
|
|
|
|
func (a Analyzer) Info() gps.ProjectAnalyzerInfo {
|
|
|
|
return gps.ProjectAnalyzerInfo{
|
|
|
|
Name: "dep",
|
|
|
|
Version: 1,
|
|
|
|
}
|
2016-10-18 18:29:29 +03:00
|
|
|
}
|