github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/pkg/cataloger/ruby/package.go (about)

     1  package ruby
     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 newGemfileLockPackage(name, version string, locations ...file.Location) pkg.Package {
    10  	p := pkg.Package{
    11  		Name:      name,
    12  		Version:   version,
    13  		PURL:      packageURL(name, version),
    14  		Locations: file.NewLocationSet(locations...),
    15  		Language:  pkg.Ruby,
    16  		Type:      pkg.GemPkg,
    17  	}
    18  
    19  	p.SetID()
    20  
    21  	return p
    22  }
    23  
    24  func newGemspecPackage(m gemData, gemSpecLocation file.Location) pkg.Package {
    25  	p := pkg.Package{
    26  		Name:      m.Name,
    27  		Version:   m.Version,
    28  		Locations: file.NewLocationSet(gemSpecLocation.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation)),
    29  		Licenses:  pkg.NewLicenseSet(pkg.NewLicensesFromLocation(gemSpecLocation, m.Licenses...)...),
    30  		PURL:      packageURL(m.Name, m.Version),
    31  		Language:  pkg.Ruby,
    32  		Type:      pkg.GemPkg,
    33  		Metadata:  m.RubyGemspec,
    34  	}
    35  
    36  	p.SetID()
    37  
    38  	return p
    39  }
    40  
    41  func packageURL(name, version string) string {
    42  	var qualifiers packageurl.Qualifiers
    43  
    44  	return packageurl.NewPackageURL(
    45  		packageurl.TypeGem,
    46  		"",
    47  		name,
    48  		version,
    49  		qualifiers,
    50  		"",
    51  	).ToString()
    52  }