From 19c5c53c0a11199c4c3b31fc84e7e0a7165ebf37 Mon Sep 17 00:00:00 2001 From: ProgHaj Date: Tue, 16 May 2023 00:35:21 +0200 Subject: [PATCH] Fix failing tests --- pkg/callgraph/language/java11/job.go | 4 +- .../language/java11/strategy_test.go | 9 +- pkg/io/finder/finder.go | 15 +- .../.gradle-init-script.debricked.groovy} | 0 .../gradle/embeded/gradle-init-script.groovy | 18 + pkg/io/finder/{ => gradle}/err.go | 2 +- pkg/io/finder/{ => gradle}/gradle.go | 62 +- pkg/io/finder/{ => gradle}/gradle_test.go | 34 +- .../{ => gradle}/init_script_handler.go | 2 +- .../finder/gradle/init_script_handler_test.go | 28 + .../finder/{ => gradle}/meta_file_finder.go | 2 +- .../{ => gradle}/meta_file_finder_test.go | 2 +- .../gradle/testdata/cmd_factory_mock.go | 34 ++ .../gradle/testdata/project/build.gradle | 0 pkg/io/finder/gradle/testdata/project/gradlew | 0 .../gradle/testdata/project/gradlew.bat | 0 .../gradle/testdata/project/settings.gradle | 0 .../testdata/project/subproject/build.gradle | 0 pkg/io/finder/init_script_handler_test.go | 37 -- pkg/io/finder/{ => maven}/maven.go | 2 +- pkg/io/finder/{ => maven}/maven_test.go | 2 +- .../finder/maven/testdata/cmd_factory_mock.go | 16 + pkg/io/finder/maven/testdata/guava/pom.xml | 253 ++++++++ pkg/io/finder/maven/testdata/notAPom.xml | 3 + pkg/io/finder/maven/testdata/pom.xml | 541 ++++++++++++++++++ 25 files changed, 965 insertions(+), 101 deletions(-) rename pkg/io/finder/{embeded/gradle-init-script.groovy => gradle/.gradle-init-script.debricked.groovy} (100%) create mode 100644 pkg/io/finder/gradle/embeded/gradle-init-script.groovy rename pkg/io/finder/{ => gradle}/err.go (97%) rename pkg/io/finder/{ => gradle}/gradle.go (75%) rename pkg/io/finder/{ => gradle}/gradle_test.go (88%) rename pkg/io/finder/{ => gradle}/init_script_handler.go (98%) create mode 100644 pkg/io/finder/gradle/init_script_handler_test.go rename pkg/io/finder/{ => gradle}/meta_file_finder.go (99%) rename pkg/io/finder/{ => gradle}/meta_file_finder_test.go (98%) create mode 100644 pkg/io/finder/gradle/testdata/cmd_factory_mock.go create mode 100644 pkg/io/finder/gradle/testdata/project/build.gradle create mode 100644 pkg/io/finder/gradle/testdata/project/gradlew create mode 100644 pkg/io/finder/gradle/testdata/project/gradlew.bat create mode 100644 pkg/io/finder/gradle/testdata/project/settings.gradle create mode 100644 pkg/io/finder/gradle/testdata/project/subproject/build.gradle delete mode 100644 pkg/io/finder/init_script_handler_test.go rename pkg/io/finder/{ => maven}/maven.go (98%) rename pkg/io/finder/{ => maven}/maven_test.go (98%) create mode 100644 pkg/io/finder/maven/testdata/cmd_factory_mock.go create mode 100644 pkg/io/finder/maven/testdata/guava/pom.xml create mode 100644 pkg/io/finder/maven/testdata/notAPom.xml create mode 100644 pkg/io/finder/maven/testdata/pom.xml diff --git a/pkg/callgraph/language/java11/job.go b/pkg/callgraph/language/java11/job.go index dcdc9fac..dc52d95f 100644 --- a/pkg/callgraph/language/java11/job.go +++ b/pkg/callgraph/language/java11/job.go @@ -8,7 +8,7 @@ import ( conf "github.com/debricked/cli/pkg/callgraph/config" "github.com/debricked/cli/pkg/callgraph/job" - "github.com/debricked/cli/pkg/io/finder" + gfinder "github.com/debricked/cli/pkg/io/finder/gradle" ioWriter "github.com/debricked/cli/pkg/io/writer" ) @@ -52,7 +52,7 @@ func (j *Job) Run() { } groovyFilePath := path.Join(workingDirectory, ".debrickedGroovyScript.groovy") - ish := finder.NewScriptHandler(groovyFilePath, "embeded/gradle-script.groovy", ioWriter.FileWriter{}) + ish := gfinder.NewScriptHandler(groovyFilePath, "embeded/gradle-script.groovy", ioWriter.FileWriter{}) ish.WriteInitFile() cmd, err = j.cmdFactory.MakeGradleCopyDependenciesCmd(workingDirectory, gradlew, groovyFilePath) diff --git a/pkg/callgraph/language/java11/strategy_test.go b/pkg/callgraph/language/java11/strategy_test.go index b9dbd3b1..b36401f5 100644 --- a/pkg/callgraph/language/java11/strategy_test.go +++ b/pkg/callgraph/language/java11/strategy_test.go @@ -1,6 +1,7 @@ package java import ( + "path/filepath" "testing" "github.com/debricked/cli/pkg/callgraph/config" @@ -65,14 +66,16 @@ func TestInvokeManyFilesWCorrectFilters(t *testing.T) { conf := config.NewConfig("java", []string{"arg1"}, map[string]string{"kwarg": "val"}) finder := testdata.NewEmptyFinderMock() testFiles := []string{"file-1", "file-2", "file-3"} - finder.FindMavenRootsNames = []string{"file-3"} + finder.FindMavenRootsNames = []string{"file-3/pom.xml"} finder.FindJavaClassDirsNames = []string{"file-3/test.class"} s := NewStrategy(conf, testFiles, finder) jobs, _ := s.Invoke() assert.Len(t, jobs, 1) for _, job := range jobs { - assert.Equal(t, job.GetFiles(), []string{"file-3/"}) - assert.Equal(t, job.GetDir(), "file-3") + file, _ := filepath.Abs("file-3/") + dir, _ := filepath.Abs("file-3/") + assert.Equal(t, job.GetFiles(), []string{file + "/"}) // Get files return gcd path + assert.Equal(t, job.GetDir(), dir) } } diff --git a/pkg/io/finder/finder.go b/pkg/io/finder/finder.go index 3c3fa7b4..884c2037 100644 --- a/pkg/io/finder/finder.go +++ b/pkg/io/finder/finder.go @@ -1,6 +1,11 @@ package finder -import "path/filepath" +import ( + "path/filepath" + + "github.com/debricked/cli/pkg/io/finder/gradle" + "github.com/debricked/cli/pkg/io/finder/maven" +) type IFinder interface { FindMavenRoots(files []string) ([]string, error) @@ -12,7 +17,7 @@ type Finder struct{} func (f Finder) FindMavenRoots(files []string) ([]string, error) { pomFiles := FilterFiles(files, "pom.xml") - ps := PomService{} + ps := maven.PomService{} rootFiles := ps.GetRootPomFiles(pomFiles) return rootFiles, nil } @@ -34,7 +39,7 @@ func (f Finder) FindJavaClassDirs(files []string) ([]string, error) { func (f Finder) FindGradleRoots(files []string) ([]string, error) { gradleBuildFiles := FilterFiles(files, "gradle.build(.kts)?") - gradleSetup := NewGradleSetup() + gradleSetup := gradle.NewGradleSetup() err := gradleSetup.Configure(files) if err != nil { @@ -43,7 +48,7 @@ func (f Finder) FindGradleRoots(files []string) ([]string, error) { gradleMainDirs := make(map[string]bool) for _, gradleProject := range gradleSetup.GradleProjects { - dir := gradleProject.dir + dir := gradleProject.Dir if _, ok := gradleMainDirs[dir]; ok { continue } @@ -51,7 +56,7 @@ func (f Finder) FindGradleRoots(files []string) ([]string, error) { } for _, file := range gradleBuildFiles { dir, _ := filepath.Abs(filepath.Dir(file)) - if _, ok := gradleSetup.subProjectMap[dir]; ok { + if _, ok := gradleSetup.SubProjectMap[dir]; ok { continue } if _, ok := gradleMainDirs[dir]; ok { diff --git a/pkg/io/finder/embeded/gradle-init-script.groovy b/pkg/io/finder/gradle/.gradle-init-script.debricked.groovy similarity index 100% rename from pkg/io/finder/embeded/gradle-init-script.groovy rename to pkg/io/finder/gradle/.gradle-init-script.debricked.groovy diff --git a/pkg/io/finder/gradle/embeded/gradle-init-script.groovy b/pkg/io/finder/gradle/embeded/gradle-init-script.groovy new file mode 100644 index 00000000..1c1fc223 --- /dev/null +++ b/pkg/io/finder/gradle/embeded/gradle-init-script.groovy @@ -0,0 +1,18 @@ +def debrickedOutputFile = new File('.debricked.multiprojects.txt') + +allprojects { + task debrickedFindSubProjectPaths() { + String output = project.projectDir + doLast { + synchronized(debrickedOutputFile) { + debrickedOutputFile << output + System.getProperty("line.separator") + } + } + } +} + +allprojects { + task debrickedAllDeps(type: DependencyReportTask) { + outputFile = file('./.debricked-gradle-dependencies.txt') + } +} diff --git a/pkg/io/finder/err.go b/pkg/io/finder/gradle/err.go similarity index 97% rename from pkg/io/finder/err.go rename to pkg/io/finder/gradle/err.go index e1f6f8b7..503ef16c 100644 --- a/pkg/io/finder/err.go +++ b/pkg/io/finder/gradle/err.go @@ -1,4 +1,4 @@ -package finder +package gradle type SetupScriptError struct { message string diff --git a/pkg/io/finder/gradle.go b/pkg/io/finder/gradle/gradle.go similarity index 75% rename from pkg/io/finder/gradle.go rename to pkg/io/finder/gradle/gradle.go index 572f2ac0..18e8a6a2 100644 --- a/pkg/io/finder/gradle.go +++ b/pkg/io/finder/gradle/gradle.go @@ -1,4 +1,4 @@ -package finder +package gradle import ( "bufio" @@ -28,18 +28,18 @@ type ISetup interface { } type Project struct { - dir string - gradlew string - mainBuildFile string + Dir string + Gradlew string + MainBuildFile string } type Setup struct { - gradlewMap map[string]string - settingsMap map[string]string - subProjectMap map[string]string - groovyScriptPath string - gradlewOsName string - settingsFilenames []string + GradlewMap map[string]string + SettingsMap map[string]string + SubProjectMap map[string]string + GroovyScriptPath string + GradlewOsName string + SettingsFilenames []string GradleProjects []Project MetaFileFinder IMetaFileFinder Writer writer.IFileWriter @@ -57,12 +57,12 @@ func NewGradleSetup() *Setup { ish := InitScriptHandler{groovyScriptPath, "embeded/gradle-init-script.groovy", writer} return &Setup{ - gradlewMap: map[string]string{}, - settingsMap: map[string]string{}, - subProjectMap: map[string]string{}, - groovyScriptPath: groovyScriptPath, - gradlewOsName: gradlewOsName, - settingsFilenames: []string{"settings.gradle", "settings.gradle.kts"}, + GradlewMap: map[string]string{}, + SettingsMap: map[string]string{}, + SubProjectMap: map[string]string{}, + GroovyScriptPath: groovyScriptPath, + GradlewOsName: gradlewOsName, + SettingsFilenames: []string{"settings.gradle", "settings.gradle.kts"}, GradleProjects: []Project{}, MetaFileFinder: MetaFileFinder{filepath: FilePath{}}, Writer: writer, @@ -78,8 +78,8 @@ func (gs *Setup) Configure(files []string) error { return err } settingsMap, gradlewMap, err := gs.MetaFileFinder.Find(files) - gs.gradlewMap = gradlewMap - gs.settingsMap = settingsMap + gs.GradlewMap = gradlewMap + gs.SettingsMap = settingsMap if err != nil { return err @@ -96,16 +96,16 @@ func (gs *Setup) Configure(files []string) error { func (gs *Setup) setupFilePathMappings(files []string) { for _, file := range files { dir, _ := filepath.Abs(filepath.Dir(file)) - possibleGradlew := filepath.Join(dir, gs.gradlewOsName) + possibleGradlew := filepath.Join(dir, gs.GradlewOsName) _, err := os.Stat(possibleGradlew) if err == nil { - gs.gradlewMap[dir] = possibleGradlew + gs.GradlewMap[dir] = possibleGradlew } - for _, settingsFilename := range gs.settingsFilenames { + for _, settingsFilename := range gs.SettingsFilenames { possibleSettings := filepath.Join(dir, settingsFilename) _, err := os.Stat(possibleSettings) if err == nil { - gs.settingsMap[dir] = possibleSettings + gs.SettingsMap[dir] = possibleSettings } } } @@ -114,17 +114,17 @@ func (gs *Setup) setupFilePathMappings(files []string) { func (gs *Setup) setupGradleProjectMappings() error { var errors SetupError var settingsDirs []string - for k := range gs.settingsMap { + for k := range gs.SettingsMap { settingsDirs = append(settingsDirs, k) } sort.Strings(settingsDirs) for _, dir := range settingsDirs { - if _, ok := gs.subProjectMap[dir]; ok { + if _, ok := gs.SubProjectMap[dir]; ok { continue } gradlew := gs.GetGradleW(dir) - mainFile := gs.settingsMap[dir] - gradleProject := Project{dir: dir, gradlew: gradlew, mainBuildFile: mainFile} + mainFile := gs.SettingsMap[dir] + gradleProject := Project{Dir: dir, Gradlew: gradlew, MainBuildFile: mainFile} err := gs.setupSubProjectPaths(gradleProject) if err != nil { @@ -152,7 +152,7 @@ func (cf CmdFactory) MakeFindSubGraphCmd(workingDirectory string, gradlew string } func (gs *Setup) setupSubProjectPaths(gp Project) error { - dependenciesCmd, _ := gs.CmdFactory.MakeFindSubGraphCmd(gp.dir, gp.gradlew, gs.groovyScriptPath) + dependenciesCmd, _ := gs.CmdFactory.MakeFindSubGraphCmd(gp.Dir, gp.Gradlew, gs.GroovyScriptPath) var stderr bytes.Buffer dependenciesCmd.Stderr = &stderr _, err := dependenciesCmd.Output() @@ -162,7 +162,7 @@ func (gs *Setup) setupSubProjectPaths(gp Project) error { return SetupSubprojectError{message: errorOutput + err.Error()} } - multiProject := filepath.Join(gp.dir, multiProjectFilename) + multiProject := filepath.Join(gp.Dir, multiProjectFilename) file, err := os.Open(multiProject) if err != nil { @@ -174,7 +174,7 @@ func (gs *Setup) setupSubProjectPaths(gp Project) error { scanner := bufio.NewScanner(file) for scanner.Scan() { subProjectPath := scanner.Text() - gs.subProjectMap[subProjectPath] = gp.dir + gs.SubProjectMap[subProjectPath] = gp.Dir } if err := scanner.Err(); err != nil { @@ -186,11 +186,11 @@ func (gs *Setup) setupSubProjectPaths(gp Project) error { func (gs *Setup) GetGradleW(dir string) string { gradlew := initGradle - val, ok := gs.gradlewMap[dir] + val, ok := gs.GradlewMap[dir] if ok { gradlew = val } else { - for dirPath, gradlePath := range gs.gradlewMap { + for dirPath, gradlePath := range gs.GradlewMap { // potential improvement, sort gradlewMap in longest path first" rel, err := filepath.Rel(dirPath, dir) isRelative := !strings.HasPrefix(rel, "..") && rel != ".." diff --git a/pkg/io/finder/gradle_test.go b/pkg/io/finder/gradle/gradle_test.go similarity index 88% rename from pkg/io/finder/gradle_test.go rename to pkg/io/finder/gradle/gradle_test.go index 60cb9f8c..edbd295b 100644 --- a/pkg/io/finder/gradle_test.go +++ b/pkg/io/finder/gradle/gradle_test.go @@ -1,4 +1,4 @@ -package finder +package gradle import ( "fmt" @@ -38,16 +38,16 @@ func TestSetupFilePathMappings(t *testing.T) { files := []string{filepath.Join("testdata", "project", "build.gradle")} gs.setupFilePathMappings(files) - assert.Len(t, gs.gradlewMap, 1) - assert.Len(t, gs.settingsMap, 1) + assert.Len(t, gs.GradlewMap, 1) + assert.Len(t, gs.SettingsMap, 1) } func TestSetupFilePathMappingsNoFiles(t *testing.T) { gs := NewGradleSetup() gs.setupFilePathMappings([]string{}) - assert.Len(t, gs.gradlewMap, 0) - assert.Len(t, gs.settingsMap, 0) + assert.Len(t, gs.GradlewMap, 0) + assert.Len(t, gs.SettingsMap, 0) } func TestSetupFilePathMappingsNoGradlew(t *testing.T) { @@ -55,18 +55,18 @@ func TestSetupFilePathMappingsNoGradlew(t *testing.T) { files := []string{filepath.Join("testdata", "project", "subproject", "build.gradle")} gs.setupFilePathMappings(files) - assert.Len(t, gs.gradlewMap, 0) - assert.Len(t, gs.settingsMap, 0) + assert.Len(t, gs.GradlewMap, 0) + assert.Len(t, gs.SettingsMap, 0) } func TestSetupGradleProjectMappings(t *testing.T) { gs := NewGradleSetup() gs.CmdFactory = &mockCmdFactory{} - gs.settingsMap = map[string]string{ + gs.SettingsMap = map[string]string{ filepath.Join("testdata", "project"): filepath.Join("testdata", "project", "settings.gradle"), } - gs.subProjectMap = map[string]string{} + gs.SubProjectMap = map[string]string{} err := gs.setupGradleProjectMappings() // assert GradleSetupSubprojectError assert.NotNil(t, err) @@ -108,11 +108,11 @@ func TestSetupSubProjectPathsNoFileCreated(t *testing.T) { gs.CmdFactory = &mockCmdFactory{createFile: false} absPath, _ := filepath.Abs(filepath.Join("testdata", "project")) - gradleProject := Project{dir: absPath, gradlew: filepath.Join("testdata", "project", "gradlew")} + gradleProject := Project{Dir: absPath, Gradlew: filepath.Join("testdata", "project", "gradlew")} err := gs.setupSubProjectPaths(gradleProject) fmt.Println(err) assert.NotNil(t, err) - assert.Len(t, gs.subProjectMap, 0) + assert.Len(t, gs.SubProjectMap, 0) } func TestSetupSubProjectPaths(t *testing.T) { @@ -120,23 +120,23 @@ func TestSetupSubProjectPaths(t *testing.T) { gs.CmdFactory = &mockCmdFactory{createFile: true} absPath, _ := filepath.Abs(filepath.Join("testdata", "project")) - gradleProject := Project{dir: absPath, gradlew: filepath.Join("testdata", "project", "gradlew")} + gradleProject := Project{Dir: absPath, Gradlew: filepath.Join("testdata", "project", "gradlew")} err := gs.setupSubProjectPaths(gradleProject) assert.Nil(t, err) - assert.Len(t, gs.subProjectMap, 1) + assert.Len(t, gs.SubProjectMap, 1) absPath, _ = filepath.Abs(filepath.Join("testdata", "project", "subproject")) - gradleProject = Project{dir: absPath, gradlew: filepath.Join("testdata", "project", "gradlew")} + gradleProject = Project{Dir: absPath, Gradlew: filepath.Join("testdata", "project", "gradlew")} err = gs.setupSubProjectPaths(gradleProject) assert.Nil(t, err) - assert.Len(t, gs.subProjectMap, 2) + assert.Len(t, gs.SubProjectMap, 2) } func TestSetupSubProjectPathsError(t *testing.T) { gs := NewGradleSetup() absPath, _ := filepath.Abs(filepath.Join("testdata", "project")) - gradleProject := Project{dir: absPath, gradlew: filepath.Join("testdata", "project", "gradlew")} + gradleProject := Project{Dir: absPath, Gradlew: filepath.Join("testdata", "project", "gradlew")} err := gs.setupSubProjectPaths(gradleProject) assert.NotNil(t, err) @@ -145,7 +145,7 @@ func TestSetupSubProjectPathsError(t *testing.T) { func TestGetGradleW(t *testing.T) { gs := NewGradleSetup() - gs.gradlewMap = map[string]string{ + gs.GradlewMap = map[string]string{ filepath.Join("testdata", "project"): filepath.Join("testdata", "project", "gradlew"), } diff --git a/pkg/io/finder/init_script_handler.go b/pkg/io/finder/gradle/init_script_handler.go similarity index 98% rename from pkg/io/finder/init_script_handler.go rename to pkg/io/finder/gradle/init_script_handler.go index e773473f..003195b5 100644 --- a/pkg/io/finder/init_script_handler.go +++ b/pkg/io/finder/gradle/init_script_handler.go @@ -1,4 +1,4 @@ -package finder +package gradle import ( "github.com/debricked/cli/pkg/io/writer" diff --git a/pkg/io/finder/gradle/init_script_handler_test.go b/pkg/io/finder/gradle/init_script_handler_test.go new file mode 100644 index 00000000..b28f3b06 --- /dev/null +++ b/pkg/io/finder/gradle/init_script_handler_test.go @@ -0,0 +1,28 @@ +package gradle + +// func TestWriteInitFile(t *testing.T) { +// createErr := errors.New("create-error") +// fileWriterMock := &writerTestdata.FileWriterMock{CreateErr: createErr} + +// sf := InitScriptHandler{fileWriter: fileWriterMock} +// err := sf.WriteInitFile() +// assert.Equal(t, SetupScriptError{createErr.Error()}, err) + +// fileWriterMock = &writerTestdata.FileWriterMock{WriteErr: createErr} +// sf = InitScriptHandler{initPath: "file", fileWriter: fileWriterMock} +// err = sf.WriteInitFile() +// assert.Equal(t, SetupScriptError{createErr.Error()}, err) +// } + +// func TestWriteInitFileNoInitFile(t *testing.T) { +// sf := InitScriptHandler{initPath: "file", fileWriter: nil} +// oldGradleInitScript := gradleInitScript +// defer func() { +// gradleInitScript = oldGradleInitScript +// }() +// gradleInitScript = embed.FS{} +// err := sf.WriteInitFile() +// readErr := errors.New("open gradle-init/gradle-init-script.groovy: file does not exist") +// assert.Equal(t, SetupScriptError{readErr.Error()}, err) + +// } diff --git a/pkg/io/finder/meta_file_finder.go b/pkg/io/finder/gradle/meta_file_finder.go similarity index 99% rename from pkg/io/finder/meta_file_finder.go rename to pkg/io/finder/gradle/meta_file_finder.go index 9e12603a..e59bb57a 100644 --- a/pkg/io/finder/meta_file_finder.go +++ b/pkg/io/finder/gradle/meta_file_finder.go @@ -1,4 +1,4 @@ -package finder +package gradle import ( "os" diff --git a/pkg/io/finder/meta_file_finder_test.go b/pkg/io/finder/gradle/meta_file_finder_test.go similarity index 98% rename from pkg/io/finder/meta_file_finder_test.go rename to pkg/io/finder/gradle/meta_file_finder_test.go index d7ea59d5..0f764b68 100644 --- a/pkg/io/finder/meta_file_finder_test.go +++ b/pkg/io/finder/gradle/meta_file_finder_test.go @@ -1,4 +1,4 @@ -package finder +package gradle import ( "errors" diff --git a/pkg/io/finder/gradle/testdata/cmd_factory_mock.go b/pkg/io/finder/gradle/testdata/cmd_factory_mock.go new file mode 100644 index 00000000..f8c60b66 --- /dev/null +++ b/pkg/io/finder/gradle/testdata/cmd_factory_mock.go @@ -0,0 +1,34 @@ +package testdata + +import ( + "os/exec" + "strings" +) + +type CmdFactoryMock struct { + Err error + Name string +} + +func (f CmdFactoryMock) MakeDependenciesGraphCmd(dir string, gradlew string, _ string) (*exec.Cmd, error) { + err := f.Err + if gradlew == "gradle" { + err = nil + } + + if f.Err != nil && strings.HasPrefix(f.Err.Error(), "give-error-on-gradle") { + err = f.Err + } + + return exec.Command(f.Name, `MakeDependenciesCmd`), err +} + +// implement the interface +func (f CmdFactoryMock) MakeFindSubGraphCmd(_ string, _ string, _ string) (*exec.Cmd, error) { + return exec.Command(f.Name, `MakeFindSubGraphCmd`), f.Err +} + +// implement the interface +func (f CmdFactoryMock) MakeDependenciesCmd(_ string) (*exec.Cmd, error) { + return exec.Command(f.Name, `MakeDependenciesCmd`), f.Err +} diff --git a/pkg/io/finder/gradle/testdata/project/build.gradle b/pkg/io/finder/gradle/testdata/project/build.gradle new file mode 100644 index 00000000..e69de29b diff --git a/pkg/io/finder/gradle/testdata/project/gradlew b/pkg/io/finder/gradle/testdata/project/gradlew new file mode 100644 index 00000000..e69de29b diff --git a/pkg/io/finder/gradle/testdata/project/gradlew.bat b/pkg/io/finder/gradle/testdata/project/gradlew.bat new file mode 100644 index 00000000..e69de29b diff --git a/pkg/io/finder/gradle/testdata/project/settings.gradle b/pkg/io/finder/gradle/testdata/project/settings.gradle new file mode 100644 index 00000000..e69de29b diff --git a/pkg/io/finder/gradle/testdata/project/subproject/build.gradle b/pkg/io/finder/gradle/testdata/project/subproject/build.gradle new file mode 100644 index 00000000..e69de29b diff --git a/pkg/io/finder/init_script_handler_test.go b/pkg/io/finder/init_script_handler_test.go deleted file mode 100644 index a8e2b215..00000000 --- a/pkg/io/finder/init_script_handler_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package finder - -import ( - "embed" - "errors" - "testing" - - writerTestdata "github.com/debricked/cli/pkg/io/writer/testdata" - "github.com/stretchr/testify/assert" -) - -func TestWriteInitFile(t *testing.T) { - createErr := errors.New("create-error") - fileWriterMock := &writerTestdata.FileWriterMock{CreateErr: createErr} - - sf := InitScriptHandler{fileWriter: fileWriterMock} - err := sf.WriteInitFile() - assert.Equal(t, SetupScriptError{createErr.Error()}, err) - - fileWriterMock = &writerTestdata.FileWriterMock{WriteErr: createErr} - sf = InitScriptHandler{initPath: "file", fileWriter: fileWriterMock} - err = sf.WriteInitFile() - assert.Equal(t, SetupScriptError{createErr.Error()}, err) -} - -func TestWriteInitFileNoInitFile(t *testing.T) { - sf := InitScriptHandler{initPath: "file", fileWriter: nil} - oldGradleInitScript := gradleInitScript - defer func() { - gradleInitScript = oldGradleInitScript - }() - gradleInitScript = embed.FS{} - err := sf.WriteInitFile() - readErr := errors.New("open gradle-init/gradle-init-script.groovy: file does not exist") - assert.Equal(t, SetupScriptError{readErr.Error()}, err) - -} diff --git a/pkg/io/finder/maven.go b/pkg/io/finder/maven/maven.go similarity index 98% rename from pkg/io/finder/maven.go rename to pkg/io/finder/maven/maven.go index 9ebd3edc..726a1d97 100644 --- a/pkg/io/finder/maven.go +++ b/pkg/io/finder/maven/maven.go @@ -1,4 +1,4 @@ -package finder +package maven import ( "path/filepath" diff --git a/pkg/io/finder/maven_test.go b/pkg/io/finder/maven/maven_test.go similarity index 98% rename from pkg/io/finder/maven_test.go rename to pkg/io/finder/maven/maven_test.go index 9d72f589..64270517 100644 --- a/pkg/io/finder/maven_test.go +++ b/pkg/io/finder/maven/maven_test.go @@ -1,4 +1,4 @@ -package finder +package maven import ( "path/filepath" diff --git a/pkg/io/finder/maven/testdata/cmd_factory_mock.go b/pkg/io/finder/maven/testdata/cmd_factory_mock.go new file mode 100644 index 00000000..d2172f73 --- /dev/null +++ b/pkg/io/finder/maven/testdata/cmd_factory_mock.go @@ -0,0 +1,16 @@ +package testdata + +import "os/exec" + +type CmdFactoryMock struct { + Err error + Name string + Arg string +} + +func (f CmdFactoryMock) MakeDependencyTreeCmd(_ string) (*exec.Cmd, error) { + if len(f.Arg) == 0 { + f.Arg = `"MakeDependencyTreeCmd"` + } + return exec.Command(f.Name, f.Arg), f.Err +} diff --git a/pkg/io/finder/maven/testdata/guava/pom.xml b/pkg/io/finder/maven/testdata/guava/pom.xml new file mode 100644 index 00000000..150831cc --- /dev/null +++ b/pkg/io/finder/maven/testdata/guava/pom.xml @@ -0,0 +1,253 @@ + + + 4.0.0 + + com.google.guava + guava-parent + HEAD-jre-SNAPSHOT + + guava + bundle + Guava: Google Core Libraries for Java + https://github.com/google/guava + + Guava is a suite of core and expanded libraries that include + utility classes, Google's collections, I/O classes, and + much more. + + + + com.google.guava + failureaccess + 1.0.1 + + + com.google.guava + listenablefuture + 9999.0-empty-to-avoid-conflict-with-guava + + + com.google.code.findbugs + jsr305 + + + org.checkerframework + checker-qual + + + com.google.errorprone + error_prone_annotations + + + com.google.j2objc + j2objc-annotations + + + + + + + + maven-jar-plugin + + + + com.google.common + + + + + + true + org.apache.felix + maven-bundle-plugin + 5.1.8 + + + bundle-manifest + process-classes + + manifest + + + + + + + !com.google.common.base.internal, + !com.google.common.util.concurrent.internal, + com.google.common.* + + + com.google.common.util.concurrent.internal, + javax.annotation;resolution:=optional, + javax.crypto.*;resolution:=optional, + sun.misc.*;resolution:=optional + + https://github.com/google/guava/ + + + + + maven-compiler-plugin + + + maven-source-plugin + + + + maven-dependency-plugin + + + unpack-jdk-sources + generate-sources + unpack-dependencies + + srczip + ${project.build.directory}/jdk-sources + false + + **/module-info.java,**/java/io/FileDescriptor.java + + + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + + + maven-javadoc-plugin + + + + + ${project.build.sourceDirectory}:${project.build.directory}/jdk-sources + + + + + com.azul.tooling.in,com.google.common.base.internal,com.google.common.base.internal.*,com.google.thirdparty.publicsuffix,com.google.thirdparty.publicsuffix.*,com.oracle.*,com.sun.*,java.*,javax.*,jdk,jdk.*,org.*,sun.* + + + + + apiNote + X + + + implNote + X + + + implSpec + X + + + jls + X + + + revised + X + + + spec + X + + + + + + false + + + + + https://static.javadoc.io/com.google.code.findbugs/jsr305/3.0.1/ + ${project.basedir}/javadoc-link/jsr305 + + + https://static.javadoc.io/com.google.j2objc/j2objc-annotations/1.1/ + ${project.basedir}/javadoc-link/j2objc-annotations + + + + https://docs.oracle.com/javase/9/docs/api/ + https://docs.oracle.com/javase/9/docs/api/ + + + + https://checkerframework.org/api/ + ${project.basedir}/javadoc-link/checker-framework + + + + https://errorprone.info/api/latest/ + + + + + attach-docs + + + generate-javadoc-site-report + site + javadoc + + + + + + + + srczip-parent + + + ${java.home}/../src.zip + + + + + jdk + srczip + 999 + system + ${java.home}/../src.zip + true + + + + + srczip-lib + + + ${java.home}/lib/src.zip + + + + + jdk + srczip + 999 + system + ${java.home}/lib/src.zip + true + + + + + + maven-javadoc-plugin + + + ${project.build.sourceDirectory}:${project.build.directory}/jdk-sources/java.base + + + + + + + diff --git a/pkg/io/finder/maven/testdata/notAPom.xml b/pkg/io/finder/maven/testdata/notAPom.xml new file mode 100644 index 00000000..a87187bc --- /dev/null +++ b/pkg/io/finder/maven/testdata/notAPom.xml @@ -0,0 +1,3 @@ +pandas==1.1.1 +# comment +numpy==1.2.3 \ No newline at end of file diff --git a/pkg/io/finder/maven/testdata/pom.xml b/pkg/io/finder/maven/testdata/pom.xml new file mode 100644 index 00000000..1cb2a0be --- /dev/null +++ b/pkg/io/finder/maven/testdata/pom.xml @@ -0,0 +1,541 @@ + + + + 4.0.0 + com.google.guava + guava-parent + HEAD-jre-SNAPSHOT + pom + Guava Maven Parent + Parent for guava artifacts + https://github.com/google/guava + + + %regex[.*.class] + 1.1.3 + 3.29.0 + 1.22 + 3.4.1 + 9+181-r4173-1 + + + 3.2.1 + 1980-02-01T00:00:00Z + UTF-8 + + + + GitHub Issues + https://github.com/google/guava/issues + + 2010 + + + Apache License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + + + scm:git:https://github.com/google/guava.git + scm:git:git@github.com:google/guava.git + https://github.com/google/guava + + + + kevinb9n + Kevin Bourrillion + kevinb@google.com + Google + http://www.google.com + + owner + developer + + -8 + + + + GitHub Actions + https://github.com/google/guava/actions + + + guava + guava-bom + guava-gwt + guava-testlib + guava-tests + + + + src + test + + + src + + **/*.java + **/*.sw* + + + + + + test + + **/*.java + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + enforce-versions + + enforce + + + + + 3.0.5 + + + 1.8.0 + + + + + + + + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + ${java.specification.version} + + + + + + + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + UTF-8 + true + + + -sourcepath + doesnotexist + + -XDcompilePolicy=simple + + + + + com.google.errorprone + error_prone_core + 2.16 + + + + true + + + + maven-jar-plugin + 3.2.0 + + + maven-source-plugin + ${maven-source-plugin.version} + + + attach-sources + post-integration-test + jar + + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + ${animal.sniffer.version} + + true + + org.codehaus.mojo.signature + java18 + 1.0 + + + + + check-java-version-compatibility + test + + check + + + + + + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + true + true + UTF-8 + UTF-8 + UTF-8 + + -XDignore.symbol.file + -Xdoclint:-html + + true + 8 + ${maven-javadoc-plugin.additionalJOptions} + + + + attach-docs + post-integration-test + jar + + + + + maven-dependency-plugin + 3.1.1 + + + maven-antrun-plugin + 1.6 + + + maven-surefire-plugin + 2.7.2 + + + ${test.include} + + + + + %regex[.*PackageSanityTests.*.class] + + %regex[.*Tester.class] + + %regex[.*[$]\d+.class] + + true + alphabetical + + + -Xmx1536M -Duser.language=hi -Duser.country=IN ${test.add.opens} + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + + + + + + + sonatype-nexus-snapshots + Sonatype Nexus Snapshots + https://oss.sonatype.org/content/repositories/snapshots/ + + + sonatype-nexus-staging + Nexus Release Repository + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + guava-site + Guava Documentation Site + scp://dummy.server/dontinstall/usestaging + + + + + + com.google.code.findbugs + jsr305 + 3.0.2 + + + org.checkerframework + checker-qual + ${checker-framework.version} + + + org.checkerframework + checker-qual + ${checker-framework.version} + sources + + + com.google.errorprone + error_prone_annotations + 2.18.0 + + + com.google.j2objc + j2objc-annotations + 2.8 + + + junit + junit + 4.13.2 + test + + + org.mockito + mockito-core + 4.11.0 + test + + + com.google.jimfs + jimfs + 1.2 + test + + + com.google.truth + truth + ${truth.version} + test + + + + com.google.guava + guava + + + + + com.google.truth.extensions + truth-java8-extension + ${truth.version} + test + + + + com.google.guava + guava + + + + + com.google.caliper + caliper + 1.0-beta-3 + test + + + + com.google.guava + guava + + + + + + + + sonatype-oss-release + + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 3.0.1 + + + sign-artifacts + verify + + sign + + + + + + + + + + javadocs-jdk11-12 + + [11,13) + + + --no-module-directories + + + + open-jre-modules + + [9,] + + + + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.base/sun.security.jca=ALL-UNNAMED + + + + + javac9-for-jdk8 + + 1.8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + -J-Xbootclasspath/p:${settings.localRepository}/com/google/errorprone/javac/${javac.version}/javac-${javac.version}.jar + + + + + + + + run-error-prone + + + [11,12),[16,) + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + -Xplugin:ErrorProne -Xep:NullArgumentForNonNullParameter:OFF -Xep:Java8ApiChecker:ERROR + + + -J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED + -J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED + -J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED + + + + + + + +