mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 08:53:15 +01:00
Merge pull request #366 from zhill/issue-331
Use sorted artifacts for consistent SBoM output in table, cyclonedx, and json presenters
This commit is contained in:
commit
557ad8be49
@ -34,7 +34,7 @@ func NewCycloneDxDocument(catalog *pkg.Catalog, srcMetadata source.Metadata) Cyc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// attach components
|
// attach components
|
||||||
for p := range catalog.Enumerate() {
|
for _, p := range catalog.Sorted() {
|
||||||
component := CycloneDxComponent{
|
component := CycloneDxComponent{
|
||||||
Type: "library", // TODO: this is not accurate
|
Type: "library", // TODO: this is not accurate
|
||||||
Name: p.Name,
|
Name: p.Name,
|
||||||
|
|||||||
@ -25,7 +25,7 @@ func (pres *TablePresenter) Present(output io.Writer) error {
|
|||||||
rows := make([][]string, 0)
|
rows := make([][]string, 0)
|
||||||
|
|
||||||
columns := []string{"Name", "Version", "Type"}
|
columns := []string{"Name", "Version", "Type"}
|
||||||
for p := range pres.catalog.Enumerate() {
|
for _, p := range pres.catalog.Sorted() {
|
||||||
row := []string{
|
row := []string{
|
||||||
p.Name,
|
p.Name,
|
||||||
p.Version,
|
p.Version,
|
||||||
|
|||||||
@ -164,6 +164,9 @@ func (c *Catalog) Sorted(types ...Type) []*Package {
|
|||||||
sort.SliceStable(pkgs, func(i, j int) bool {
|
sort.SliceStable(pkgs, func(i, j int) bool {
|
||||||
if pkgs[i].Name == pkgs[j].Name {
|
if pkgs[i].Name == pkgs[j].Name {
|
||||||
if pkgs[i].Version == pkgs[j].Version {
|
if pkgs[i].Version == pkgs[j].Version {
|
||||||
|
if pkgs[i].Type == pkgs[j].Type {
|
||||||
|
return pkgs[i].Locations[0].String() < pkgs[j].Locations[0].String()
|
||||||
|
}
|
||||||
return pkgs[i].Type < pkgs[j].Type
|
return pkgs[i].Type < pkgs[j].Type
|
||||||
}
|
}
|
||||||
return pkgs[i].Version < pkgs[j].Version
|
return pkgs[i].Version < pkgs[j].Version
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user