github.com/noqcks/syft@v0.0.0-20230920222752-a9e2c4e288e5/syft/pkg/cataloger/dart/package.go (about) 1 package dart 2 3 import ( 4 "github.com/anchore/packageurl-go" 5 "github.com/anchore/syft/syft/file" 6 "github.com/anchore/syft/syft/pkg" 7 ) 8 9 func newPubspecLockPackage(name string, raw pubspecLockPackage, locations ...file.Location) pkg.Package { 10 metadata := pkg.DartPubMetadata{ 11 Name: name, 12 Version: raw.Version, 13 HostedURL: raw.getHostedURL(), 14 VcsURL: raw.getVcsURL(), 15 } 16 17 p := pkg.Package{ 18 Name: name, 19 Version: raw.Version, 20 Locations: file.NewLocationSet(locations...), 21 PURL: packageURL(metadata), 22 Language: pkg.Dart, 23 Type: pkg.DartPubPkg, 24 MetadataType: pkg.DartPubMetadataType, 25 Metadata: metadata, 26 } 27 28 p.SetID() 29 30 return p 31 } 32 33 func packageURL(m pkg.DartPubMetadata) string { 34 var qualifiers packageurl.Qualifiers 35 36 if m.HostedURL != "" { 37 qualifiers = append(qualifiers, packageurl.Qualifier{ 38 Key: "hosted_url", 39 Value: m.HostedURL, 40 }) 41 } else if m.VcsURL != "" { // Default to using Hosted if somehow both are provided 42 qualifiers = append(qualifiers, packageurl.Qualifier{ 43 Key: "vcs_url", 44 Value: m.VcsURL, 45 }) 46 } 47 48 return packageurl.NewPackageURL( 49 packageurl.TypePub, 50 "", 51 m.Name, 52 m.Version, 53 qualifiers, 54 "", 55 ).ToString() 56 }