Issue #297: Adds exclude property for directories in local codebase to exclude from scanning.
diff --git a/cfg/cfg.go b/cfg/cfg.go index 93ae060..93a309b 100644 --- a/cfg/cfg.go +++ b/cfg/cfg.go
@@ -19,6 +19,8 @@ // homepage: https://www.mattfarina.com // ignore: // - appengine +// exclude: +// - node_modules // import: // - package: gopkg.in/yaml.v2 // - package: github.com/Masterminds/vcs @@ -43,6 +45,8 @@ // owners of a security issue without filing a public bug. // - ignore: A list of packages for Glide to ignore importing. These are package // names to ignore rather than directories. +// - exclude: A list of directories in the local codebase to exclude from +// scanning for dependencies. // - import: A list of packages to import. Each package can include: // - package: The name of the package to import and the only non-optional item. // - version: A semantic version, semantic version range, branch, tag, or
diff --git a/cfg/config.go b/cfg/config.go index 88bdc71..db9297c 100644 --- a/cfg/config.go +++ b/cfg/config.go
@@ -41,6 +41,10 @@ // those to skip. Ignore []string `yaml:"ignore,omitempty"` + // Exclude contains a list of directories in the local application to + // exclude from scanning for dependencies. + Exclude []string `yaml:"exclude,omitempty"` + // Imports contains a list of all non-development imports for a project. For // more detail on how these are captured see the Dependency type. Imports Dependencies `yaml:"import"` @@ -58,6 +62,7 @@ License string `yaml:"license,omitempty"` Owners Owners `yaml:"owners,omitempty"` Ignore []string `yaml:"ignore,omitempty"` + Exclude []string `yaml:"exclude,omitempty"` Imports Dependencies `yaml:"import"` DevImports Dependencies `yaml:"devimport,omitempty"` } @@ -90,6 +95,7 @@ c.License = newConfig.License c.Owners = newConfig.Owners c.Ignore = newConfig.Ignore + c.Exclude = newConfig.Exclude c.Imports = newConfig.Imports c.DevImports = newConfig.DevImports @@ -108,6 +114,7 @@ License: c.License, Owners: c.Owners, Ignore: c.Ignore, + Exclude: c.Exclude, } i, err := c.Imports.Clone().DeDupe() if err != nil { @@ -154,6 +161,17 @@ return false } +// HasExclude returns true if the given name is listed on the exclude list. +func (c *Config) HasExclude(ex string) bool { + for _, v := range c.Exclude { + if v == ex { + return true + } + } + + return false +} + // Clone performs a deep clone of the Config instance func (c *Config) Clone() *Config { n := &Config{} @@ -163,6 +181,7 @@ n.License = c.License n.Owners = c.Owners.Clone() n.Ignore = c.Ignore + n.Exclude = c.Exclude n.Imports = c.Imports.Clone() n.DevImports = c.DevImports.Clone() return n
diff --git a/dependency/resolver.go b/dependency/resolver.go index 6c00a41..a0ba011 100644 --- a/dependency/resolver.go +++ b/dependency/resolver.go
@@ -232,6 +232,12 @@ if err != nil && err != filepath.SkipDir { return err } + pt := strings.TrimPrefix(path, r.basedir+string(os.PathSeparator)) + pt = strings.TrimSuffix(pt, string(os.PathSeparator)) + if r.Config.HasExclude(pt) { + msg.Debug("Excluding %s", pt) + return filepath.SkipDir + } if !fi.IsDir() { return nil }
diff --git a/docs/glide.yaml.md b/docs/glide.yaml.md index 784910b..5bec302 100644 --- a/docs/glide.yaml.md +++ b/docs/glide.yaml.md
@@ -14,6 +14,8 @@ homepage: https://www.mattfarina.com ignore: - appengine + exclude: + - node_modules import: - package: gopkg.in/yaml.v2 - package: github.com/Masterminds/vcs @@ -31,6 +33,7 @@ - license: The license is either an [SPDX license](http://spdx.org/licenses/) string or the filepath to the license. This allows automation and consumers to easily identify the license. - `owners`: The owners is a list of one or more owners for the project. This can be a person or organization and is useful for things like notifying the owners of a security issue without filing a public bug. - `ignore`: A list of packages for Glide to ignore importing. These are package names to ignore rather than directories. +- `exclude`: A list of directories in the local codebase to exclude from scanning for dependencies. - `import`: A list of packages to import. Each package can include: - `package`: The name of the package to import and the only non-optional item. Package names follow the same patterns the `go` tool does. That means: - Package names that map to a VCS remote location end in .git, .bzr, .hg, or .svn. For example, `example.com/foo/pkg.git/subpkg`.