Skip to content

Commit

Permalink
find pom for .war and .ear files
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 3285583 commit f419b0a
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func (p *javaServiceClient) GetDependencies(ctx context.Context) (map[uri.URI][]
ll = make(map[uri.URI][]konveyor.DepDAGItem, 0)
// for binaries we only find JARs embedded in archive
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)
}
} else {
ll, err = p.GetDependenciesDAG(ctx)
if err != nil {
Expand Down Expand Up @@ -215,7 +220,7 @@ func (p *javaServiceClient) GetDependenciesFallback(ctx context.Context, locatio
artifactIdKey: *d.ArtifactID,
pomPathKey: path,
}
if *d.Version != "" {
if d.Version != nil {
if strings.Contains(*d.Version, "$") {
version := strings.TrimSuffix(strings.TrimPrefix(*d.Version, "${"), "}")
p.log.V(10).Info("Searching for property in properties",
Expand Down Expand Up @@ -562,6 +567,7 @@ type walker struct {
m2RepoPath string
initialPath string
seen map[string]bool
pomPath string
}

func (w *walker) walkDirForJar(path string, info fs.DirEntry, err error) error {
Expand Down Expand Up @@ -634,6 +640,34 @@ 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")
w := walker{
deps: ll,
depToLabels: p.depToLabels,
m2RepoPath: "",
seen: map[string]bool{},
initialPath: pathMeta,
pomPath: "",
}
filepath.WalkDir(pathMeta, w.walkDirForPom)
return w.pomPath
}

func (w *walker) walkDirForPom(path string, info fs.DirEntry, err error) error {
if info == nil {
return nil
}
if info.IsDir() {
return filepath.WalkDir(filepath.Join(path, info.Name()), w.walkDirForPom)
}
if strings.Contains(info.Name(), "pom.xml") {
w.pomPath = path
return nil
}
return nil
}

// parseDepString parses a java dependency string
func (p *javaServiceClient) parseDepString(dep, localRepoPath, pomPath string) (provider.Dep, error) {
d := provider.Dep{}
Expand Down

0 comments on commit f419b0a

Please sign in to comment.