From 9ba411d789ff7c303eeb42474200fcfea0d6b5df Mon Sep 17 00:00:00 2001 From: filip Date: Thu, 21 Nov 2024 12:49:11 +0100 Subject: [PATCH] use current version for soot-wrapper jar --- internal/callgraph/config/config.go | 16 ++++++++++++- internal/callgraph/generator.go | 1 + internal/callgraph/generator_test.go | 8 +++---- .../callgraph/language/golang/job_test.go | 16 ++++++------- .../language/golang/strategy_test.go | 10 ++++---- internal/callgraph/language/java/job_test.go | 24 +++++++++---------- .../callgraph/language/java/soot_handler.go | 18 +++++++------- .../language/java/soot_handler_test.go | 21 ++++++++-------- internal/callgraph/language/java/strategy.go | 11 +++++++-- .../callgraph/language/java/strategy_test.go | 10 ++++---- .../callgraph/strategy/strategy_factory.go | 8 ++++++- .../strategy/strategy_factory_test.go | 4 ++-- .../testdata/strategy_mock_factory.go | 16 +++++++++++-- internal/cmd/callgraph/callgraph.go | 3 ++- internal/scan/scanner.go | 5 ++-- scripts/install.sh | 2 +- 16 files changed, 109 insertions(+), 64 deletions(-) diff --git a/internal/callgraph/config/config.go b/internal/callgraph/config/config.go index bec4c743..42db413d 100644 --- a/internal/callgraph/config/config.go +++ b/internal/callgraph/config/config.go @@ -6,6 +6,7 @@ type IConfig interface { Kwargs() map[string]string Build() bool PackageManager() string + Version() string } type Config struct { @@ -14,15 +15,24 @@ type Config struct { kwargs map[string]string build bool packageManager string + version string } -func NewConfig(language string, args []string, kwargs map[string]string, build bool, packageManager string) Config { +func NewConfig( + language string, + args []string, + kwargs map[string]string, + build bool, + packageManager string, + version string, +) Config { return Config{ language, args, kwargs, build, packageManager, + version, } } @@ -45,3 +55,7 @@ func (c Config) Build() bool { func (c Config) PackageManager() string { return c.packageManager } + +func (c Config) Version() string { + return c.version +} diff --git a/internal/callgraph/generator.go b/internal/callgraph/generator.go index 55c71a9c..4db68086 100644 --- a/internal/callgraph/generator.go +++ b/internal/callgraph/generator.go @@ -16,6 +16,7 @@ type DebrickedOptions struct { Inclusions []string Configs []config.IConfig Timeout int + Version string } type IGenerator interface { diff --git a/internal/callgraph/generator_test.go b/internal/callgraph/generator_test.go index b764d4a0..1ed55b61 100644 --- a/internal/callgraph/generator_test.go +++ b/internal/callgraph/generator_test.go @@ -30,7 +30,7 @@ func TestGenerate(t *testing.T) { ) configs := []config.IConfig{ - config.NewConfig("java", []string{}, map[string]string{"pm": "maven"}, true, "maven"), + config.NewConfig("java", []string{}, map[string]string{"pm": "maven"}, true, "maven", ""), } ctx, _ := ctxTestdata.NewContextMock() err := g.Generate( @@ -51,7 +51,7 @@ func TestGenerateWithTimer(t *testing.T) { ) configs := []config.IConfig{ - config.NewConfig("java", []string{}, map[string]string{"pm": "maven"}, true, "maven"), + config.NewConfig("java", []string{}, map[string]string{"pm": "maven"}, true, "maven", ""), } err := g.GenerateWithTimer( DebrickedOptions{ @@ -73,7 +73,7 @@ func TestGenerateInvokeError(t *testing.T) { ) configs := []config.IConfig{ - config.NewConfig("java", []string{}, map[string]string{"pm": "maven"}, true, "maven"), + config.NewConfig("java", []string{}, map[string]string{"pm": "maven"}, true, "maven", ""), } ctx, _ := ctxTestdata.NewContextMock() err := g.Generate( @@ -94,7 +94,7 @@ func TestGenerateScheduleError(t *testing.T) { ) configs := []config.IConfig{ - config.NewConfig("java", []string{}, map[string]string{"pm": "maven"}, true, "maven"), + config.NewConfig("java", []string{}, map[string]string{"pm": "maven"}, true, "maven", ""), } ctx, _ := ctxTestdata.NewContextMock() err := g.Generate( diff --git a/internal/callgraph/language/golang/job_test.go b/internal/callgraph/language/golang/job_test.go index d8ec0d21..576cb318 100644 --- a/internal/callgraph/language/golang/job_test.go +++ b/internal/callgraph/language/golang/job_test.go @@ -47,7 +47,7 @@ func TestRun(t *testing.T) { } }() - config := conf.NewConfig("golang", nil, nil, true, "go") + config := conf.NewConfig("golang", nil, nil, true, "go", "") ctx, _ := ctxTestdata.NewContextMock() rootFileDir := filepath.Dir("testdata/fixture/app.go") @@ -65,7 +65,7 @@ func TestRun(t *testing.T) { func TestRunCallgraphMockError(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} - config := conf.NewConfig("golang", nil, nil, true, "go") + config := conf.NewConfig("golang", nil, nil, true, "go", "") ctx, _ := ctxTestdata.NewContextMock() callgraphMock := testdata.CallgraphMock{RunCallGraphError: fmt.Errorf("error")} @@ -83,7 +83,7 @@ func TestRunCallgraphMockError(t *testing.T) { func TestRunPostProcessZipFileError(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} - config := conf.NewConfig("golang", nil, nil, true, "go") + config := conf.NewConfig("golang", nil, nil, true, "go", "") ctx, _ := ctxTestdata.NewContextMock() archiveMock := ioTestData.ArchiveMock{ZipFileError: fmt.Errorf("error")} fs := io.FileSystem{} @@ -98,7 +98,7 @@ func TestRunPostProcessZipFileError(t *testing.T) { func TestRunPostProcessB64Error(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} - config := conf.NewConfig("golang", nil, nil, true, "go") + config := conf.NewConfig("golang", nil, nil, true, "go", "") ctx, _ := ctxTestdata.NewContextMock() fs := io.FileSystem{} @@ -114,7 +114,7 @@ func TestRunPostProcessB64Error(t *testing.T) { func TestRunPostProcessCleanupError(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} - config := conf.NewConfig("golang", nil, nil, true, "go") + config := conf.NewConfig("golang", nil, nil, true, "go", "") ctx, _ := ctxTestdata.NewContextMock() fs := io.FileSystem{} @@ -130,7 +130,7 @@ func TestRunPostProcessCleanupError(t *testing.T) { func TestRunPostProcessCleanupNoFileExistError(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} - config := conf.NewConfig("golang", nil, nil, true, "go") + config := conf.NewConfig("golang", nil, nil, true, "go", "") ctx, _ := ctxTestdata.NewContextMock() fs := io.FileSystem{} @@ -148,7 +148,7 @@ func TestRunPostProcessCleanupNoFileExistError(t *testing.T) { func TestRunWithErrorsIsNotExistFalse(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} - config := conf.NewConfig("golang", nil, nil, true, "go") + config := conf.NewConfig("golang", nil, nil, true, "go", "") ctx, _ := ctxTestdata.NewContextMock() fs := ioTestData.FileSystemMock{} @@ -170,7 +170,7 @@ func TestRunWithErrorsIsNotExistFalse(t *testing.T) { func TestRunWithErrorsIsNotExistTrue(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} - config := conf.NewConfig("golang", nil, nil, true, "go") + config := conf.NewConfig("golang", nil, nil, true, "go", "") ctx, _ := ctxTestdata.NewContextMock() fs := ioTestData.FileSystemMock{} diff --git a/internal/callgraph/language/golang/strategy_test.go b/internal/callgraph/language/golang/strategy_test.go index fa1e1ec3..d453b4ab 100644 --- a/internal/callgraph/language/golang/strategy_test.go +++ b/internal/callgraph/language/golang/strategy_test.go @@ -22,7 +22,7 @@ func TestNewStrategy(t *testing.T) { s = NewStrategy(nil, []string{"file-1", "file-2"}, []string{}, []string{}, nil, nil) assert.NotNil(t, s) - conf := config.NewConfig("golang", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "go") + conf := config.NewConfig("golang", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "go", "") finder := testdata.NewEmptyFinderMock() testFiles := []string{"file-1"} finder.FindRootsNames = testFiles @@ -39,7 +39,7 @@ func TestInvokeNoFiles(t *testing.T) { } func TestInvokeOneFile(t *testing.T) { - conf := config.NewConfig("golang", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "go") + conf := config.NewConfig("golang", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "go", "") finder := testdata.NewEmptyFinderMock() testFiles := []string{"file-1"} finder.FindRootsNames = testFiles @@ -51,7 +51,7 @@ func TestInvokeOneFile(t *testing.T) { } func TestInvokeManyFiles(t *testing.T) { - conf := config.NewConfig("golang", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "go") + conf := config.NewConfig("golang", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "go", "") finder := testdata.NewEmptyFinderMock() testFiles := []string{"file-1", "file-2"} finder.FindRootsNames = testFiles @@ -62,7 +62,7 @@ func TestInvokeManyFiles(t *testing.T) { } func TestInvokeWithErrors(t *testing.T) { - conf := config.NewConfig("golang", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "go") + conf := config.NewConfig("golang", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "go", "") finder := testdata.NewEmptyFinderMock() testFiles := []string{"file-1", "file-2"} finder.FindRootsNames = testFiles @@ -82,7 +82,7 @@ func TestInvokeWithErrors(t *testing.T) { } func TestInvokeNoRoots(t *testing.T) { - conf := config.NewConfig("golang", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "go") + conf := config.NewConfig("golang", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "go", "") finder := testdata.NewEmptyFinderMock() testFiles := []string{} finder.FindRootsNames = testFiles diff --git a/internal/callgraph/language/java/job_test.go b/internal/callgraph/language/java/job_test.go index 5bc9ddfa..1d4ebcce 100644 --- a/internal/callgraph/language/java/job_test.go +++ b/internal/callgraph/language/java/job_test.go @@ -55,7 +55,7 @@ func TestRunMakeMavenCopyDependenciesCmdErr(t *testing.T) { fs := io.FileSystem{} shMock := testdata.MockSootHandler{} - config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven") + config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven", "") ctx, _ := ctxTestdata.NewContextMock() j := NewJob(dir, files, cmdFactoryMock, fileWriterMock, archiveMock, config, ctx, fs, shMock) @@ -69,7 +69,7 @@ func TestRunMakeMavenCopyDependenciesCmdErr(t *testing.T) { func TestRun(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} cmdFactoryMock := testdata.NewEchoCmdFactory() - config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven") + config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven", "") ctx, _ := ctxTestdata.NewContextMock() fsMock := ioTestData.FileSystemMock{} @@ -91,7 +91,7 @@ func TestRun(t *testing.T) { func TestRunCallgraphMock(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} cmdFactoryMock := testdata.NewEchoCmdFactory() - config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven") + config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven", "") ctx, _ := ctxTestdata.NewContextMock() callgraphMock := testdata.CallgraphMock{} @@ -111,7 +111,7 @@ func TestRunCallgraphMock(t *testing.T) { func TestRunCallgraphMockError(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} cmdFactoryMock := testdata.NewEchoCmdFactory() - config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven") + config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven", "") ctx, _ := ctxTestdata.NewContextMock() callgraphMock := testdata.CallgraphMock{RunCallGraphWithSetupError: fmt.Errorf("error")} @@ -131,7 +131,7 @@ func TestRunCallgraphMockError(t *testing.T) { func TestRunPostProcessMock(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} cmdFactoryMock := testdata.NewEchoCmdFactory() - config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven") + config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven", "") ctx, _ := ctxTestdata.NewContextMock() fsMock := ioTestData.FileSystemMock{} @@ -151,7 +151,7 @@ func TestRunPostProcessMock(t *testing.T) { func TestRunPostProcessZipFileError(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} cmdFactoryMock := testdata.NewEchoCmdFactory() - config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven") + config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven", "") ctx, _ := ctxTestdata.NewContextMock() archiveMock := ioTestData.ArchiveMock{ZipFileError: fmt.Errorf("error")} fs := io.FileSystem{} @@ -167,7 +167,7 @@ func TestRunPostProcessZipFileError(t *testing.T) { func TestRunPostProcessB64Error(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} cmdFactoryMock := testdata.NewEchoCmdFactory() - config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven") + config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven", "") ctx, _ := ctxTestdata.NewContextMock() fs := io.FileSystem{} @@ -184,7 +184,7 @@ func TestRunPostProcessB64Error(t *testing.T) { func TestRunPostProcessCleanupError(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} cmdFactoryMock := testdata.NewEchoCmdFactory() - config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven") + config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven", "") ctx, _ := ctxTestdata.NewContextMock() fs := io.FileSystem{} shMock := testdata.MockSootHandler{} @@ -201,7 +201,7 @@ func TestRunPostProcessCleanupError(t *testing.T) { func TestRunPostProcessCleanupNoFileExistError(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} cmdFactoryMock := testdata.NewEchoCmdFactory() - config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven") + config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven", "") ctx, _ := ctxTestdata.NewContextMock() fs := io.FileSystem{} @@ -220,7 +220,7 @@ func TestRunPostProcessCleanupNoFileExistError(t *testing.T) { func TestRunPostProcessFromRoot(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} cmdFactoryMock := testdata.NewEchoCmdFactory() - config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven") + config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven", "") ctx, _ := ctxTestdata.NewContextMock() fs := io.FileSystem{} @@ -242,7 +242,7 @@ func TestRunWithErrorsIsNotExistFalse(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} cmdFactoryMock := testdata.NewEchoCmdFactory() - config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven") + config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven", "") ctx, _ := ctxTestdata.NewContextMock() fs := ioTestData.FileSystemMock{} @@ -267,7 +267,7 @@ func TestRunWithErrorsIsNotExistTrue(t *testing.T) { fileWriterMock := &ioTestData.FileWriterMock{} cmdFactoryMock := testdata.NewEchoCmdFactory() - config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven") + config := conf.NewConfig("java", nil, map[string]string{"pm": maven}, true, "maven", "") ctx, _ := ctxTestdata.NewContextMock() fs := ioTestData.FileSystemMock{} diff --git a/internal/callgraph/language/java/soot_handler.go b/internal/callgraph/language/java/soot_handler.go index 942f24d0..be786a0f 100644 --- a/internal/callgraph/language/java/soot_handler.go +++ b/internal/callgraph/language/java/soot_handler.go @@ -17,12 +17,12 @@ type ISootHandler interface { GetSootWrapper(version string, fs ioFs.IFileSystem, arc ioFs.IArchive) (string, error) } -type SootHandler struct{} +type SootHandler struct{ cliVersion string } //go:embed embedded/SootWrapper.jar var jarCallGraph embed.FS -func initializeSootWrapper(fs ioFs.IFileSystem, tempDir string) (string, error) { +func (sh SootHandler) initializeSootWrapper(fs ioFs.IFileSystem, tempDir string) (string, error) { jarFile, err := fs.FsOpenEmbed(jarCallGraph, "embedded/SootWrapper.jar") if err != nil { return "", err @@ -46,7 +46,7 @@ func initializeSootWrapper(fs ioFs.IFileSystem, tempDir string) (string, error) return tempJarFile, nil } -func downloadSootWrapper(arc ioFs.IArchive, fs ioFs.IFileSystem, path string, version string) error { +func (sh SootHandler) downloadSootWrapper(arc ioFs.IArchive, fs ioFs.IFileSystem, path string, version string) error { dir, err := fs.MkdirTemp(".tmp") if err != nil { @@ -61,7 +61,7 @@ func downloadSootWrapper(arc ioFs.IArchive, fs ioFs.IFileSystem, path string, ve } defer zipFile.Close() - err = downloadCompressedSootWrapper(fs, zipFile, version) + err = sh.downloadCompressedSootWrapper(fs, zipFile, version) if err != nil { return err @@ -70,9 +70,11 @@ func downloadSootWrapper(arc ioFs.IArchive, fs ioFs.IFileSystem, path string, ve return arc.UnzipFile(zipPath, path) } -func downloadCompressedSootWrapper(fs ioFs.IFileSystem, zipFile *os.File, version string) error { +func (sh SootHandler) downloadCompressedSootWrapper(fs ioFs.IFileSystem, zipFile *os.File, version string) error { fullURLFile := strings.Join([]string{ - "https://github.com/debricked/cli/releases/download/v2.2.0/soot-wrapper-", + "https://github.com/debricked/cli/releases/download/", + sh.cliVersion, + "/soot-wrapper-", version, ".zip", }, "") @@ -118,7 +120,7 @@ func (sh SootHandler) GetSootWrapper(version string, fs ioFs.IFileSystem, arc io } if _, err := fs.Stat(path); fs.IsNotExist(err) { if versionInt >= 21 { - return initializeSootWrapper(fs, debrickedDir) + return sh.initializeSootWrapper(fs, debrickedDir) } if versionInt >= 17 { version = "17" @@ -126,7 +128,7 @@ func (sh SootHandler) GetSootWrapper(version string, fs ioFs.IFileSystem, arc io version = "11" } // Handling correct jar to install - return path, downloadSootWrapper(arc, fs, path, version) + return path, sh.downloadSootWrapper(arc, fs, path, version) } return path, nil diff --git a/internal/callgraph/language/java/soot_handler_test.go b/internal/callgraph/language/java/soot_handler_test.go index 76f28c1c..0d925a03 100644 --- a/internal/callgraph/language/java/soot_handler_test.go +++ b/internal/callgraph/language/java/soot_handler_test.go @@ -10,11 +10,13 @@ import ( "github.com/stretchr/testify/assert" ) +var sootHandler = SootHandler{} + func TestInitializeSootWrapper(t *testing.T) { fsMock := ioTestData.FileSystemMock{} tempDir, err := fsMock.MkdirTemp(".tmp") assert.NoError(t, err) - path, err := initializeSootWrapper(fsMock, tempDir) + path, err := sootHandler.initializeSootWrapper(fsMock, tempDir) assert.NotNil(t, path) assert.NoError(t, err) } @@ -24,7 +26,7 @@ func TestInitializeSootWrapperOpenEmbedError(t *testing.T) { fsMock := ioTestData.FileSystemMock{FsOpenEmbedError: fmt.Errorf(errString)} //nolint tempDir, err := fsMock.MkdirTemp(".tmp") assert.NoError(t, err) - _, err = initializeSootWrapper(fsMock, tempDir) + _, err = sootHandler.initializeSootWrapper(fsMock, tempDir) assert.Error(t, err) assert.Equal(t, err.Error(), errString) } @@ -34,7 +36,7 @@ func TestInitializeSootWrapperFsReadAllError(t *testing.T) { fsMock := ioTestData.FileSystemMock{FsReadAllError: fmt.Errorf(errString)} //nolint tempDir, err := fsMock.MkdirTemp(".tmp") assert.NoError(t, err) - _, err = initializeSootWrapper(fsMock, tempDir) + _, err = sootHandler.initializeSootWrapper(fsMock, tempDir) assert.Error(t, err) assert.Equal(t, err.Error(), errString) } @@ -44,7 +46,7 @@ func TestInitializeSootWrapperFsWriteFileError(t *testing.T) { fsMock := ioTestData.FileSystemMock{FsWriteFileError: fmt.Errorf(errString)} //nolint tempDir, err := fsMock.MkdirTemp(".tmp") assert.NoError(t, err) - _, err = initializeSootWrapper(fsMock, tempDir) + _, err = sootHandler.initializeSootWrapper(fsMock, tempDir) assert.Error(t, err) assert.Equal(t, err.Error(), errString) } @@ -52,7 +54,7 @@ func TestInitializeSootWrapperFsWriteFileError(t *testing.T) { func TestDownloadSootWrapper(t *testing.T) { fsMock := ioTestData.FileSystemMock{} arcMock := ioTestData.ArchiveMock{} - err := downloadSootWrapper(arcMock, fsMock, "soot-wrapper.jar", "11") + err := sootHandler.downloadSootWrapper(arcMock, fsMock, "soot-wrapper.jar", "11") assert.NoError(t, err, "expected no error for downloading soot-wrapper jar") } @@ -60,7 +62,7 @@ func TestDownloadSootWrapperMkdirTempError(t *testing.T) { errString := "mkdir temp error" fsMock := ioTestData.FileSystemMock{MkdirTempError: fmt.Errorf(errString)} //nolint arcMock := ioTestData.ArchiveMock{} - err := downloadSootWrapper(arcMock, fsMock, "soot-wrapper.jar", "11") + err := sootHandler.downloadSootWrapper(arcMock, fsMock, "soot-wrapper.jar", "11") assert.Error(t, err) assert.Equal(t, err.Error(), errString) } @@ -69,7 +71,7 @@ func TestDownloadSootWrapperCreateError(t *testing.T) { errString := "create error" fsMock := ioTestData.FileSystemMock{CreateError: fmt.Errorf(errString)} //nolint arcMock := ioTestData.ArchiveMock{} - err := downloadSootWrapper(arcMock, fsMock, "soot-wrapper.jar", "11") + err := sootHandler.downloadSootWrapper(arcMock, fsMock, "soot-wrapper.jar", "11") assert.Error(t, err) assert.Equal(t, err.Error(), errString) } @@ -78,7 +80,7 @@ func TestDownloadSootWrapperUnzipError(t *testing.T) { errString := "create error" fsMock := ioTestData.FileSystemMock{} arcMock := ioTestData.ArchiveMock{UnzipFileError: fmt.Errorf(errString)} //nolint - err := downloadSootWrapper(arcMock, fsMock, "soot-wrapper.jar", "11") + err := sootHandler.downloadSootWrapper(arcMock, fsMock, "soot-wrapper.jar", "11") assert.Error(t, err) assert.Equal(t, err.Error(), errString) } @@ -92,14 +94,13 @@ func TestDownloadCompressedSootWrapper(t *testing.T) { assert.NoError(t, err, "trying to create file") defer file.Close() - err = downloadCompressedSootWrapper(fs, file, "11") + err = sootHandler.downloadCompressedSootWrapper(fs, file, "11") assert.NoError(t, err, "expected no error for downloading soot-wrapper") } func TestGetSootWrapper(t *testing.T) { fs := ioTestData.FileSystemMock{} arc := ioTestData.ArchiveMock{} - sootHandler := SootHandler{} tests := []struct { name string version string diff --git a/internal/callgraph/language/java/strategy.go b/internal/callgraph/language/java/strategy.go index 0fab532d..96801369 100644 --- a/internal/callgraph/language/java/strategy.go +++ b/internal/callgraph/language/java/strategy.go @@ -98,7 +98,7 @@ func (s Strategy) Invoke() ([]job.IJob, error) { s.config, s.ctx, io.FileSystem{}, - SootHandler{}, + SootHandler{s.config.Version()}, ), ) } @@ -106,7 +106,14 @@ func (s Strategy) Invoke() ([]job.IJob, error) { return jobs, nil } -func NewStrategy(config conf.IConfig, paths []string, exclusions []string, inclusions []string, finder finder.IFinder, ctx cgexec.IContext) Strategy { +func NewStrategy( + config conf.IConfig, + paths []string, + exclusions []string, + inclusions []string, + finder finder.IFinder, + ctx cgexec.IContext, +) Strategy { return Strategy{config, CmdFactory{}, paths, exclusions, inclusions, finder, ctx} } diff --git a/internal/callgraph/language/java/strategy_test.go b/internal/callgraph/language/java/strategy_test.go index 360ef540..8d39d3c4 100644 --- a/internal/callgraph/language/java/strategy_test.go +++ b/internal/callgraph/language/java/strategy_test.go @@ -25,7 +25,7 @@ func TestNewStrategy(t *testing.T) { s = NewStrategy(nil, []string{"file-1", "file-2"}, []string{}, []string{}, nil, nil) assert.NotNil(t, s) - conf := config.NewConfig("java", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "maven") + conf := config.NewConfig("java", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "maven", "v2.0.0") finder := testdata.NewEmptyFinderMock() testFiles := []string{"file-1"} finder.FindRootsNames = testFiles @@ -42,7 +42,7 @@ func TestInvokeNoFiles(t *testing.T) { } func TestInvokeOneFile(t *testing.T) { - conf := config.NewConfig("java", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "maven") + conf := config.NewConfig("java", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "maven", "v2.0.0") finder := testdata.NewEmptyFinderMock() testFiles := []string{"file-1"} finder.FindRootsNames = testFiles @@ -53,7 +53,7 @@ func TestInvokeOneFile(t *testing.T) { } func TestInvokeManyFiles(t *testing.T) { - conf := config.NewConfig("java", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "maven") + conf := config.NewConfig("java", []string{"arg1"}, map[string]string{"kwarg": "val"}, true, "maven", "v2.0.0") finder := testdata.NewEmptyFinderMock() testFiles := []string{"file-1", "file-2"} finder.FindRootsNames = testFiles @@ -64,7 +64,7 @@ func TestInvokeManyFiles(t *testing.T) { } func TestInvokeManyFilesWCorrectFilters(t *testing.T) { - conf := config.NewConfig("java", []string{"arg1"}, map[string]string{"kwarg": "val"}, false, "maven") + conf := config.NewConfig("java", []string{"arg1"}, map[string]string{"kwarg": "val"}, false, "maven", "v2.0.0") finder := testdata.NewEmptyFinderMock() testFiles := []string{"file-1", "file-2", "file-3"} finder.FindRootsNames = []string{"file-3/pom.xml"} @@ -83,7 +83,7 @@ func TestInvokeManyFilesWCorrectFilters(t *testing.T) { } func TestBuildProjectsError(t *testing.T) { - conf := config.NewConfig("java", []string{"arg1"}, map[string]string{"kwarg": "val"}, false, "maven") + conf := config.NewConfig("java", []string{"arg1"}, map[string]string{"kwarg": "val"}, false, "maven", "v2.0.0") finder := testdata.NewEmptyFinderMock() testFiles := []string{"file-1", "file-2", "file-3"} finder.FindRootsNames = []string{"file-3/pom.xml"} diff --git a/internal/callgraph/strategy/strategy_factory.go b/internal/callgraph/strategy/strategy_factory.go index 88820769..596d0b89 100644 --- a/internal/callgraph/strategy/strategy_factory.go +++ b/internal/callgraph/strategy/strategy_factory.go @@ -21,7 +21,13 @@ func NewStrategyFactory() Factory { return Factory{} } -func (sf Factory) Make(config conf.IConfig, paths []string, exclusions []string, inclusions []string, ctx cgexec.IContext) (IStrategy, error) { +func (sf Factory) Make( + config conf.IConfig, + paths []string, + exclusions []string, + inclusions []string, + ctx cgexec.IContext, +) (IStrategy, error) { name := config.Language() switch name { case java.Name: diff --git a/internal/callgraph/strategy/strategy_factory_test.go b/internal/callgraph/strategy/strategy_factory_test.go index 6e991423..76f9bf17 100644 --- a/internal/callgraph/strategy/strategy_factory_test.go +++ b/internal/callgraph/strategy/strategy_factory_test.go @@ -16,14 +16,14 @@ func TestNewStrategyFactory(t *testing.T) { func TestMakeErr(t *testing.T) { f := NewStrategyFactory() - conf := config.NewConfig("test", nil, nil, true, "") + conf := config.NewConfig("test", nil, nil, true, "", "") s, err := f.Make(conf, nil, nil, nil, nil) assert.Nil(t, s) assert.ErrorContains(t, err, "failed to make strategy from test") } func TestMake(t *testing.T) { - conf := config.NewConfig(java.Name, nil, nil, true, "") + conf := config.NewConfig(java.Name, nil, nil, true, "", "") cases := map[string]IStrategy{ java.Name: java.NewStrategy(conf, []string{}, []string{}, []string{}, javafinder.JavaFinder{}, nil), } diff --git a/internal/callgraph/strategy/testdata/strategy_mock_factory.go b/internal/callgraph/strategy/testdata/strategy_mock_factory.go index 2cba3b70..33ee6357 100644 --- a/internal/callgraph/strategy/testdata/strategy_mock_factory.go +++ b/internal/callgraph/strategy/testdata/strategy_mock_factory.go @@ -13,7 +13,13 @@ func NewStrategyFactoryMock() FactoryMock { return FactoryMock{} } -func (sf FactoryMock) Make(config config.IConfig, paths []string, exclusions []string, inclusions []string, ctx cgexec.IContext) (strategy.IStrategy, error) { +func (sf FactoryMock) Make( + config config.IConfig, + paths []string, + exclusions []string, + inclusions []string, + ctx cgexec.IContext, +) (strategy.IStrategy, error) { return NewStrategyMock(config, paths, testdata.FinderMock{}, ctx), nil } @@ -23,6 +29,12 @@ func NewStrategyFactoryErrorMock() FactoryErrorMock { return FactoryErrorMock{} } -func (sf FactoryErrorMock) Make(config config.IConfig, paths []string, exclusions []string, inclusions []string, ctx cgexec.IContext) (strategy.IStrategy, error) { +func (sf FactoryErrorMock) Make( + config config.IConfig, + paths []string, + exclusions []string, + inclusions []string, + ctx cgexec.IContext, +) (strategy.IStrategy, error) { return NewStrategyErrorMock(config, paths, testdata.FinderMock{}, ctx), nil } diff --git a/internal/cmd/callgraph/callgraph.go b/internal/cmd/callgraph/callgraph.go index b8d970c5..1438717f 100644 --- a/internal/cmd/callgraph/callgraph.go +++ b/internal/cmd/callgraph/callgraph.go @@ -127,9 +127,10 @@ func RunE(callgraph callgraph.IGenerator) func(_ *cobra.Command, args []string) } configs := []conf.IConfig{} + version := viper.GetString("version") for _, language := range languages { - configs = append(configs, conf.NewConfig(language, args, map[string]string{}, !buildDisabled, languageMap[language])) + configs = append(configs, conf.NewConfig(language, args, map[string]string{}, !buildDisabled, languageMap[language], version)) } options := cg.DebrickedOptions{ diff --git a/internal/scan/scanner.go b/internal/scan/scanner.go index 5567ac19..71ee64bd 100644 --- a/internal/scan/scanner.go +++ b/internal/scan/scanner.go @@ -72,6 +72,7 @@ type DebrickedOptions struct { MinFingerprintContentLength int TagCommitAsRelease bool Experimental bool + Version string } func NewDebrickedScanner( @@ -238,8 +239,8 @@ func (dScanner *DebrickedScanner) scan(options DebrickedOptions, gitMetaObject g if options.CallGraph { debug.Log("Running scanFingerprint...", options.Debug) configs := []config.IConfig{ - config.NewConfig("java", []string{}, map[string]string{"pm": "maven"}, true, "maven"), - config.NewConfig("golang", []string{}, map[string]string{"pm": "go"}, true, "go"), + config.NewConfig("java", []string{}, map[string]string{"pm": "maven"}, true, "maven", options.Version), + config.NewConfig("golang", []string{}, map[string]string{"pm": "go"}, true, "go", options.Version), } timeout := options.CallGraphGenerateTimeout path := options.Path diff --git a/scripts/install.sh b/scripts/install.sh index bec535d2..62d78a48 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -4,7 +4,7 @@ if ! command -v git &> /dev/null then echo -e "Failed to find git, thus also the version. Version will be set to v0.0.0" fi -version=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match) +version=${VERSION:-$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)} ldFlags="-X main.version=${version}" go install -ldflags "${ldFlags}" ./cmd/debricked go generate -v -x ./cmd/debricked