Refine license searching from groupIDFromJavaMetadata to allow for having the artfactId in the groupId (#2313)

Signed-off-by: Colm O hEigeartaigh <coheigea@apache.org>
This commit is contained in:
Colm O hEigeartaigh 2023-11-15 15:04:31 +00:00 committed by GitHub
parent e04d90fc9a
commit 3e8a2304e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -268,6 +268,16 @@ func findLicenseFromJavaMetadata(name string, manifest *pkg.JavaManifest, versio
log.Tracef("unable to get parent pom from Maven central: %v", err)
}
if len(pomLicenses) == 0 {
// Try removing the last part of the groupId, as sometimes it duplicates the artifactId
packages := strings.Split(groupID, ".")
groupID = strings.Join(packages[:len(packages)-1], ".")
pomLicenses, err = recursivelyFindLicensesFromParentPom(groupID, name, version, j.cfg)
if err != nil {
log.Tracef("unable to get parent pom from Maven central: %v", err)
}
}
if len(pomLicenses) > 0 {
pkgLicenses := pkg.NewLicensesFromLocation(j.location, pomLicenses...)
if pkgLicenses != nil {