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:
Alex Goodman 2021-04-01 11:04:34 -04:00 committed by GitHub
commit 557ad8be49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 2 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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