diff --git a/.gitignore b/.gitignore index 3744d443..6defe176 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ coverage.out coverage.html node_modules debricked +debricked.exe dist/ /debricked-go-dependencies.txt /gomod.debricked.lock @@ -22,6 +23,10 @@ test/resolve/testdata/nuget/**/obj debricked.fingerprints.wfp test/resolve/testdata/gomod/gomod.debricked.lock test/resolve/testdata/maven/maven.debricked.lock +test/callgraph/**/maven.debricked.lock +internal/file/testdata/**/gomod.debricked.lock +internal/file/testdata/**/yarn-error.log +internal/scan/testdata/**/yarn.lock test/resolve/testdata/gradle/*/** **.gradle-init-script.debricked.groovy test/resolve/testdata/gradle/gradle.debricked.lock diff --git a/internal/resolution/pm/gradle/setup.go b/internal/resolution/pm/gradle/setup.go index f7134fd9..ec5de7f7 100644 --- a/internal/resolution/pm/gradle/setup.go +++ b/internal/resolution/pm/gradle/setup.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/debricked/cli/internal/resolution/pm/writer" + internalOs "github.com/debricked/cli/internal/runtime/os" ) const ( @@ -43,7 +44,7 @@ type Setup struct { func NewGradleSetup() *Setup { groovyScriptPath, _ := filepath.Abs(gradleInitScriptFileName) gradlewOsName := "gradlew" - if runtime.GOOS == "windows" { + if runtime.GOOS == internalOs.Windows { gradlewOsName = "gradlew.bat" } diff --git a/internal/resolution/pm/pip/cmd_factory.go b/internal/resolution/pm/pip/cmd_factory.go index bcb7918c..1fdf4904 100644 --- a/internal/resolution/pm/pip/cmd_factory.go +++ b/internal/resolution/pm/pip/cmd_factory.go @@ -2,7 +2,10 @@ package pip import ( "os/exec" + "runtime" "strings" + + "github.com/debricked/cli/internal/runtime/os" ) type ICmdFactory interface { @@ -60,11 +63,17 @@ func (cmdf CmdFactory) MakeInstallCmd(command string, file string) (*exec.Cmd, e } func (cmdf CmdFactory) MakeCatCmd(file string) (*exec.Cmd, error) { - path, err := cmdf.execPath.LookPath("cat") + command := "cat" + args := []string{command} + if runtime.GOOS == os.Windows { + command = "powershell.exe" + args = []string{command, "type"} + } + path, err := cmdf.execPath.LookPath(command) return &exec.Cmd{ Path: path, - Args: []string{"cat", file}, + Args: append(args, file), }, err } diff --git a/internal/resolution/pm/pip/cmd_factory_test.go b/internal/resolution/pm/pip/cmd_factory_test.go index 5246420b..b48298ca 100644 --- a/internal/resolution/pm/pip/cmd_factory_test.go +++ b/internal/resolution/pm/pip/cmd_factory_test.go @@ -2,6 +2,7 @@ package pip import ( "errors" + "runtime" "testing" "github.com/stretchr/testify/assert" @@ -86,12 +87,16 @@ func TestMakeInstallCmd(t *testing.T) { func TestMakeCatCmd(t *testing.T) { fileName := "test-file" + expectedCommand := "cat" + if runtime.GOOS == "windows" { + expectedCommand = "type" + } cmd, _ := CmdFactory{ execPath: ExecPath{}, }.MakeCatCmd(fileName) assert.NotNil(t, cmd) args := cmd.Args - assert.Contains(t, args, "cat") + assert.Contains(t, args, expectedCommand) assert.Contains(t, args, fileName) } func TestMakeListCmd(t *testing.T) { diff --git a/internal/resolution/pm/pip/job.go b/internal/resolution/pm/pip/job.go index 87efdc17..cbf469be 100644 --- a/internal/resolution/pm/pip/job.go +++ b/internal/resolution/pm/pip/job.go @@ -10,6 +10,7 @@ import ( "github.com/debricked/cli/internal/resolution/job" "github.com/debricked/cli/internal/resolution/pm/util" "github.com/debricked/cli/internal/resolution/pm/writer" + internalOs "github.com/debricked/cli/internal/runtime/os" ) const ( @@ -157,7 +158,7 @@ func (j *Job) runInstallCmd() ([]byte, error) { var command string if j.venvPath != "" { binDir := "bin" - if runtime.GOOS == "windows" { + if runtime.GOOS == internalOs.Windows { binDir = "Scripts" } command = filepath.Join(j.venvPath, binDir, pip) diff --git a/internal/runtime/os/os.go b/internal/runtime/os/os.go new file mode 100644 index 00000000..3aa81a3e --- /dev/null +++ b/internal/runtime/os/os.go @@ -0,0 +1,5 @@ +package os + +const ( + Windows = "windows" +)