github.com/anchore/syft@v1.38.2/syft/pkg/cataloger/ruby/package.go (about) 1 package ruby 2 3 import ( 4 "context" 5 6 "github.com/anchore/packageurl-go" 7 "github.com/anchore/syft/syft/file" 8 "github.com/anchore/syft/syft/pkg" 9 "github.com/anchore/syft/syft/pkg/cataloger/internal/licenses" 10 ) 11 12 func newGemfileLockPackage(name, version string, locations ...file.Location) pkg.Package { 13 p := pkg.Package{ 14 Name: name, 15 Version: version, 16 PURL: packageURL(name, version), 17 Locations: file.NewLocationSet(locations...), 18 Language: pkg.Ruby, 19 Type: pkg.GemPkg, 20 } 21 22 p.SetID() 23 24 return p 25 } 26 27 func newGemspecPackage(ctx context.Context, resolver file.Resolver, m gemData, gemSpecLocation file.Location) pkg.Package { 28 p := pkg.Package{ 29 Name: m.Name, 30 Version: m.Version, 31 Locations: file.NewLocationSet(gemSpecLocation.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation)), 32 Licenses: pkg.NewLicenseSet(pkg.NewLicensesFromLocationWithContext(ctx, gemSpecLocation, m.Licenses...)...), 33 PURL: packageURL(m.Name, m.Version), 34 Language: pkg.Ruby, 35 Type: pkg.GemPkg, 36 Metadata: m.RubyGemspec, 37 } 38 39 p.SetID() 40 41 p = licenses.RelativeToPackage(ctx, resolver, p) 42 43 return p 44 } 45 46 func packageURL(name, version string) string { 47 var qualifiers packageurl.Qualifiers 48 49 return packageurl.NewPackageURL( 50 packageurl.TypeGem, 51 "", 52 name, 53 version, 54 qualifiers, 55 "", 56 ).ToString() 57 }