mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
35 lines
1.0 KiB
Go
35 lines
1.0 KiB
Go
package poweruser
|
|
|
|
import (
|
|
"sort"
|
|
|
|
"github.com/anchore/syft/syft/file"
|
|
"github.com/anchore/syft/syft/source"
|
|
)
|
|
|
|
type JSONFileClassifications struct {
|
|
Location source.Location `json:"location"`
|
|
Classification file.Classification `json:"classification"`
|
|
}
|
|
|
|
func NewJSONFileClassifications(data map[source.Location][]file.Classification) []JSONFileClassifications {
|
|
results := make([]JSONFileClassifications, 0)
|
|
for location, classifications := range data {
|
|
for _, classification := range classifications {
|
|
results = append(results, JSONFileClassifications{
|
|
Location: location,
|
|
Classification: classification,
|
|
})
|
|
}
|
|
}
|
|
|
|
// sort by real path then virtual path to ensure the result is stable across multiple runs
|
|
sort.SliceStable(results, func(i, j int) bool {
|
|
if results[i].Location.RealPath == results[j].Location.RealPath {
|
|
return results[i].Location.VirtualPath < results[j].Location.VirtualPath
|
|
}
|
|
return results[i].Location.RealPath < results[j].Location.RealPath
|
|
})
|
|
return results
|
|
}
|