diff --git a/internal/callgraph/language/java/callgraph.go b/internal/callgraph/language/java/callgraph.go index e6e0bcae..6633dfd8 100644 --- a/internal/callgraph/language/java/callgraph.go +++ b/internal/callgraph/language/java/callgraph.go @@ -1,6 +1,7 @@ package java import ( + "fmt" "regexp" "github.com/debricked/cli/internal/callgraph/cgexec" @@ -74,13 +75,16 @@ func (cg *Callgraph) javaVersion(path string) (string, error) { cmd := cgexec.NewCommand(osCmd) err = cgexec.RunCommand(*cmd, cg.ctx) + if err != nil { + return "", err + } javaVersionRegex := regexp.MustCompile(`\b(\d+)\.\d+\.\d+\b`) match := javaVersionRegex.FindStringSubmatch(cmd.GetStdOut().String()) if len(match) > 1 { return match[1], nil + } else { + return "", fmt.Errorf("no version found in 'java --version' output, are you using a non-numeric version?") } - - return "", err } func (cg *Callgraph) RunCallGraph(callgraphJarPath string) error { diff --git a/internal/callgraph/language/java/callgraph_test.go b/internal/callgraph/language/java/callgraph_test.go index 4a79492e..94d3e5bf 100644 --- a/internal/callgraph/language/java/callgraph_test.go +++ b/internal/callgraph/language/java/callgraph_test.go @@ -9,26 +9,13 @@ import ( "github.com/stretchr/testify/assert" ) -func TestRunCallGraphWithSetupMock(t *testing.T) { - - cmdMock := testdata.NewEchoCmdFactory() - fsMock := ioTestData.FileSystemMock{} - arcMock := ioTestData.ArchiveMock{} - swMock := testdata.MockSootHandler{} - cg := NewCallgraph(cmdMock, ".", []string{"."}, ".", ".", fsMock, arcMock, nil, swMock) - - err := cg.RunCallGraphWithSetup() - - assert.Nil(t, err) -} - func TestRunCallGraphWithSetupSootWrapperError(t *testing.T) { cmdMock := testdata.NewEchoCmdFactory() fsMock := ioTestData.FileSystemMock{} arcMock := ioTestData.ArchiveMock{} - swMock := testdata.MockSootHandler{GetSootWrapperError: fmt.Errorf("")} - cg := NewCallgraph(cmdMock, ".", []string{"."}, ".", ".", fsMock, arcMock, nil, swMock) + shMock := testdata.MockSootHandler{GetSootWrapperError: fmt.Errorf("")} + cg := NewCallgraph(cmdMock, ".", []string{"."}, ".", ".", fsMock, arcMock, nil, shMock) err := cg.RunCallGraphWithSetup() @@ -40,8 +27,8 @@ func TestRunCallGraphWithSetupSootVersionError(t *testing.T) { cmdMock := testdata.CmdFactoryMock{JavaVersionErr: fmt.Errorf("version error")} fsMock := ioTestData.FileSystemMock{} arcMock := ioTestData.ArchiveMock{} - swMock := testdata.MockSootHandler{} - cg := NewCallgraph(cmdMock, ".", []string{"."}, ".", ".", fsMock, arcMock, nil, swMock) + shMock := testdata.MockSootHandler{} + cg := NewCallgraph(cmdMock, ".", []string{"."}, ".", ".", fsMock, arcMock, nil, shMock) err := cg.RunCallGraphWithSetup() @@ -52,8 +39,8 @@ func TestRunCallGraphMock(t *testing.T) { cmdMock := testdata.NewEchoCmdFactory() fsMock := ioTestData.FileSystemMock{} arcMock := ioTestData.ArchiveMock{} - swMock := testdata.MockSootHandler{} - cg := NewCallgraph(cmdMock, ".", []string{"."}, ".", ".", fsMock, arcMock, nil, swMock) + shMock := testdata.MockSootHandler{} + cg := NewCallgraph(cmdMock, ".", []string{"."}, ".", ".", fsMock, arcMock, nil, shMock) err := cg.RunCallGraph(".") @@ -65,8 +52,8 @@ func TestRunCallGraphErrorMock(t *testing.T) { cmdMock.CallGraphGenErr = fmt.Errorf("error") fsMock := ioTestData.FileSystemMock{} arcMock := ioTestData.ArchiveMock{} - swMock := testdata.MockSootHandler{} - cg := NewCallgraph(cmdMock, ".", []string{"."}, ".", ".", fsMock, arcMock, nil, swMock) + shMock := testdata.MockSootHandler{} + cg := NewCallgraph(cmdMock, ".", []string{"."}, ".", ".", fsMock, arcMock, nil, shMock) err := cg.RunCallGraph(".") diff --git a/internal/callgraph/language/java/soot_handler.go b/internal/callgraph/language/java/soot_handler.go index e611a1c3..c8e6ae43 100644 --- a/internal/callgraph/language/java/soot_handler.go +++ b/internal/callgraph/language/java/soot_handler.go @@ -78,7 +78,6 @@ func (sh SootHandler) downloadCompressedSootWrapper(fs ioFs.IFileSystem, zipFile version, ".zip", }, "") - fmt.Println("URL=", fullURLFile) client := http.Client{ CheckRedirect: func(r *http.Request, via []*http.Request) error { diff --git a/internal/callgraph/language/java/testdata/cmd_factory_mock.go b/internal/callgraph/language/java/testdata/cmd_factory_mock.go index d4af5ea8..a38a0161 100644 --- a/internal/callgraph/language/java/testdata/cmd_factory_mock.go +++ b/internal/callgraph/language/java/testdata/cmd_factory_mock.go @@ -40,7 +40,10 @@ func (f CmdFactoryMock) MakeBuildMavenCmd(workingDirectory string, ctx cgexec.IC } func (f CmdFactoryMock) MakeJavaVersionCmd(workingDirectory string, ctx cgexec.IContext) (*exec.Cmd, error) { - return exec.Command(f.JavaVersionName, "JavaVersion"), f.JavaVersionErr + return exec.Command( + f.JavaVersionName, + "\"openjdk 23.0.1 2024-10-15\nOpenJDK Runtime Environment Homebrew (build 23.0.1)\nOpenJDK 64-Bit Server VM Homebrew (build 23.0.1, mixed mode, sharing)\"", + ), f.JavaVersionErr } type MockSootHandler struct { diff --git a/scripts/install.sh b/scripts/install.sh index fb119a7c..7c6907a4 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -7,7 +7,7 @@ if ! command -v git >/dev/null 2>&1 then echo -e "Failed to find git, thus also the version. Version will be set to v0.0.0" fi -set -e +set +e version=${DEBRICKED_VERSION:-$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)} set -e ldFlags="-X main.version=${version}"