order locations by container layer order (#3858)

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
Alex Goodman
2025-05-13 00:02:07 -04:00
committed by GitHub
parent e3e69596bd
commit 59b880f26a
18 changed files with 1589 additions and 83 deletions
@@ -13,7 +13,7 @@ import (
"github.com/anchore/syft/syft/pkg"
)
func EncodeComponent(p pkg.Package) cyclonedx.Component {
func EncodeComponent(p pkg.Package, locationSorter func(a, b file.Location) int) cyclonedx.Component {
props := EncodeProperties(p, "syft:package")
if p.Metadata != nil {
@@ -25,7 +25,7 @@ func EncodeComponent(p pkg.Package) cyclonedx.Component {
}
props = append(props, encodeCPEs(p)...)
locations := p.Locations.ToSlice()
locations := p.Locations.ToSlice(locationSorter)
if len(locations) > 0 {
props = append(props, EncodeProperties(locations, "syft:location")...)
}