From 9c113698bbc44babeb477ace9c0445dc4462bb5e Mon Sep 17 00:00:00 2001 From: mcoops Date: Thu, 26 Aug 2021 02:55:39 +1000 Subject: [PATCH] ruby: add local gem vendor folder to avoid perm issues maven: fix the maven test case tests: fix all cases Signed-off-by: mcoops --- deplist_test.go | 147 +++++++++++++++++++++++++++--------------- internal/scan/ruby.go | 15 ++++- test/testRepo/pom.xml | 23 ++++++- 3 files changed, 129 insertions(+), 56 deletions(-) diff --git a/deplist_test.go b/deplist_test.go index 8f686b3..cf5cfe6 100644 --- a/deplist_test.go +++ b/deplist_test.go @@ -38,73 +38,122 @@ func BuildWant() []Dependency { "internal/testlog", "os", "fmt", + "path", + "io/fs", + "internal/unsafeheader", "github.com/openshift/api/config/v1", "golang.org/x/text/unicode", "github.com/mcoops/deplist", } npmSet1 := []string{ - "angular", - "d3", - "d3-array", - "d3-axis", + "loose-envify", + "iconv-lite", "d3-brush", + "d3-polygon", + "d3-zoom", + "d3-path", "d3-chord", - "d3-color", - "d3-contour", - "d3-delaunay", - "delaunator", - "d3-dispatch", - "d3-drag", - "d3-dsv", - "commander", - "iconv-lite", - } - - npmSet2 := []string{ - "safer-buffer", "rw", "d3-ease", - "d3-fetch", - "d3-force", - "d3-format", - "d3-geo", + "object-assign", + "rw", + "d3-scale-chromatic", + "d3-brush", "d3-hierarchy", - "d3-interpolate", - "d3-path", - "d3-polygon", - "d3-quadtree", - "d3-random", + "commander", + "d3-time", + "d3-time-format", + "d3-dsv", "d3-scale", + "is-plain-object", + "d3-quadtree", + "tiny-warning", + "d3-hierarchy", + "d3-dsv", + "d3-timer", "d3-scale-chromatic", - "d3-selection", - "d3-shape", - "d3-time", "d3-time-format", + "d3-array", + "d3-axis", "d3-timer", - "d3-transition", - "d3-zoom", + "d3-ease", + "d3-color", "prismjs", - "clipboard", - "good-listener", - "delegate", - "select", - "tiny-emitter", - "react", - "loose-envify", + "d3-force", + "iconv-lite", + "angular", + "d3-delaunay", + "rxjs", + "d3-zoom", + "d3-scale", + "d3-interpolate", + "d3-path", + "d3-array", + "d3-time", "js-tokens", - "object-assign", - "prop-types", + "d3-format", + "safer-buffer", + "d3-contour", + "d3-geo", + "safer-buffer", "react-is", - "rxjs", + "d3-format", + "d3-interpolate", + "d3-dispatch", + "d3-force", + "d3-color", + "d3-transition", + "prop-types", + "tiny-emitter", + "d3-polygon", + "d3-chord", + "d3-fetch", + "d3-dispatch", + "d3-contour", "tslib", + "good-listener", + "d3", + "d3-axis", + "d3-ease", + "delegate", + "d3-drag", + "delaunator", + "commander", + "d3-color", + "delaunator", + "d3-timer", + "d3-drag", + "d3-geo", "slate", - "@types/esrever", + "d3-interpolate", + "d3-random", + "select", "esrever", + "d3-transition", + "clipboard", + "d3-dispatch", + "d3-format", + "d3-path", + "d3-array", + "d3-random", + "d3-fetch", + "d3-quadtree", + "d3-shape", + "d3-delaunay", + "d3-time", + "d3-shape", "immer", - "is-plain-object", - "tiny-warning", + "@types/esrever", + "d3-time-format", + "d3-selection", + "d3-quadtree", + "d3-selection", + "react", "tether", + "d3-interpolate", + "d3-dsv", + "d3-array", } rubySet := []string{ @@ -209,15 +258,7 @@ func BuildWant() []Dependency { } deps = append(deps, d) } - deps = append(deps, Dependency{DepType: 2, Path: "com.amazonaws:aws-lambda-java-core"}) // java - - for _, n := range npmSet2 { - d := Dependency{ - DepType: 3, - Path: n, - } - deps = append(deps, d) - } + deps = append(deps, Dependency{DepType: 2, Path: "com.amazonaws:aws-lambda-java-core:jar", Version: "1.0.0"}) // java for _, n := range rubySet { d := Dependency{ diff --git a/internal/scan/ruby.go b/internal/scan/ruby.go index a6f9dcc..00e566f 100644 --- a/internal/scan/ruby.go +++ b/internal/scan/ruby.go @@ -1,6 +1,8 @@ package scan import ( + "io/ioutil" + "os" "os/exec" "path/filepath" "strings" @@ -11,10 +13,20 @@ func GetRubyDeps(path string) (map[string]string, error) { dirPath := filepath.Dir(path) + // override the gem path otherwise might hit perm issues and it's annoying + gem_path, err := ioutil.TempDir("", "gem_vendor") + if err != nil { + return nil, err + } + + // cleanup after ourselves + defer os.RemoveAll(gem_path) + //Make sure that the Gemfile we are loading is supported by the version of bundle currently installed. cmd := exec.Command("bundle", "update", "--bundler") cmd.Dir = dirPath - _, err := cmd.Output() + cmd.Env = append(cmd.Env, "GEM_HOME="+gem_path) + _, err = cmd.Output() if err != nil { return nil, err } @@ -22,6 +34,7 @@ func GetRubyDeps(path string) (map[string]string, error) { cmd = exec.Command("bundle", "list") cmd.Dir = dirPath + cmd.Env = append(cmd.Env, "GEM_HOME="+gem_path) data, err := cmd.Output() diff --git a/test/testRepo/pom.xml b/test/testRepo/pom.xml index 2f4855a..54195aa 100644 --- a/test/testRepo/pom.xml +++ b/test/testRepo/pom.xml @@ -14,8 +14,7 @@ UTF-8 - 1.7 - 1.7 + 3.0.2 @@ -35,6 +34,26 @@ + + org.apache.maven.plugins + maven-dependency-plugin + ${maven-dependency-plugin.version} + + + org.apache.maven.plugins + maven-enforcer-plugin + ${maven-enforcer-plugin.version} + + + + [3.0.2,) + + + [1.8,) + + + + maven-clean-plugin