Skip to content

Commit

Permalink
find all poms
Browse files Browse the repository at this point in the history
Signed-off-by: Emily McMullan <[email protected]>
  • Loading branch information
eemcmullan committed Sep 26, 2024
1 parent f419b0a commit d8e1d0a
Showing 1 changed file with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io"
"io/fs"
"maps"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -90,6 +91,8 @@ func (p *javaServiceClient) findGradleBuild() string {
}

func (p *javaServiceClient) GetDependencies(ctx context.Context) (map[uri.URI][]*provider.Dep, error) {
p.log.V(4).Info("running dependency analysis")

if p.GetBuildTool() == gradle {
p.log.V(2).Info("gradle found - retrieving dependencies")
m := map[uri.URI][]*provider.Dep{}
Expand Down Expand Up @@ -122,8 +125,15 @@ func (p *javaServiceClient) GetDependencies(ctx context.Context) (map[uri.URI][]
p.discoverDepsFromJars(p.config.DependencyPath, ll)
if len(ll) == 0 {
p.log.Info("unable to get dependencies from jars, looking for pom")
pomPath := p.discoverPom(p.config.DependencyPath, ll)
return p.GetDependenciesFallback(ctx, pomPath)
pomPaths := p.discoverPoms(p.config.DependencyPath, ll)
for _, path := range pomPaths {
dep, err := p.GetDependenciesFallback(ctx, path)
if err != nil {
return m, err
}
maps.Copy(m, dep)
}
return m, nil
}
} else {
ll, err = p.GetDependenciesDAG(ctx)
Expand Down Expand Up @@ -248,6 +258,10 @@ func (p *javaServiceClient) GetDependenciesFallback(ctx context.Context, locatio
}
deps = append(deps, &dep)
}
if len(deps) == 0 {
p.log.V(1).Info("unable to get dependencies from pom.xml in fallback", "pom", path)
return nil, nil
}

m := map[uri.URI][]*provider.Dep{}
m[uri.File(path)] = deps
Expand Down Expand Up @@ -567,7 +581,7 @@ type walker struct {
m2RepoPath string
initialPath string
seen map[string]bool
pomPath string
pomPaths []string
}

func (w *walker) walkDirForJar(path string, info fs.DirEntry, err error) error {
Expand Down Expand Up @@ -640,18 +654,17 @@ func (w *walker) walkDirForJar(path string, info fs.DirEntry, err error) error {
return nil
}

func (p *javaServiceClient) discoverPom(path string, ll map[uri.URI][]konveyor.DepDAGItem) string {
pathMeta := filepath.Join(path, "META-INF")
func (p *javaServiceClient) discoverPoms(pathStart string, ll map[uri.URI][]konveyor.DepDAGItem) []string {
w := walker{
deps: ll,
depToLabels: p.depToLabels,
m2RepoPath: "",
seen: map[string]bool{},
initialPath: pathMeta,
pomPath: "",
initialPath: pathStart,
pomPaths: []string{},
}
filepath.WalkDir(pathMeta, w.walkDirForPom)
return w.pomPath
filepath.WalkDir(pathStart, w.walkDirForPom)
return w.pomPaths
}

func (w *walker) walkDirForPom(path string, info fs.DirEntry, err error) error {
Expand All @@ -662,8 +675,7 @@ func (w *walker) walkDirForPom(path string, info fs.DirEntry, err error) error {
return filepath.WalkDir(filepath.Join(path, info.Name()), w.walkDirForPom)
}
if strings.Contains(info.Name(), "pom.xml") {
w.pomPath = path
return nil
w.pomPaths = append(w.pomPaths, path)
}
return nil
}
Expand Down

0 comments on commit d8e1d0a

Please sign in to comment.