Skip to content

Commit

Permalink
use current version for soot-wrapper jar
Browse files Browse the repository at this point in the history
  • Loading branch information
filip-debricked committed Nov 21, 2024
1 parent 7f11131 commit 9ba411d
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 64 deletions.
16 changes: 15 additions & 1 deletion internal/callgraph/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type IConfig interface {
Kwargs() map[string]string
Build() bool
PackageManager() string
Version() string
}

type Config struct {
Expand All @@ -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,
}
}

Expand All @@ -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
}
1 change: 1 addition & 0 deletions internal/callgraph/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type DebrickedOptions struct {
Inclusions []string
Configs []config.IConfig
Timeout int
Version string
}

type IGenerator interface {
Expand Down
8 changes: 4 additions & 4 deletions internal/callgraph/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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{
Expand All @@ -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(
Expand All @@ -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(
Expand Down
16 changes: 8 additions & 8 deletions internal/callgraph/language/golang/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")}

Expand All @@ -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{}
Expand All @@ -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{}

Expand All @@ -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{}

Expand All @@ -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{}

Expand All @@ -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{}
Expand All @@ -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{}
Expand Down
10 changes: 5 additions & 5 deletions internal/callgraph/language/golang/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions internal/callgraph/language/java/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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{}
Expand All @@ -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{}

Expand All @@ -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")}

Expand All @@ -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{}
Expand All @@ -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{}
Expand All @@ -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{}

Expand All @@ -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{}
Expand All @@ -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{}

Expand All @@ -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{}

Expand All @@ -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{}
Expand All @@ -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{}
Expand Down
18 changes: 10 additions & 8 deletions internal/callgraph/language/java/soot_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {

Expand All @@ -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
Expand All @@ -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",
}, "")
Expand Down Expand Up @@ -118,15 +120,15 @@ 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"
} else {
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
Expand Down
Loading

0 comments on commit 9ba411d

Please sign in to comment.