github.com/lineaje-labs/syft@v0.98.1-0.20231227153149-9e393f60ff1b/syft/file/license.go (about)

     1  package file
     2  
     3  import (
     4  	"github.com/anchore/syft/syft/license"
     5  	"github.com/lineaje-labs/syft/internal/log"
     6  )
     7  
     8  type License struct {
     9  	Value           string
    10  	SPDXExpression  string
    11  	Type            license.Type
    12  	LicenseEvidence *LicenseEvidence // evidence from license classifier
    13  }
    14  
    15  type LicenseEvidence struct {
    16  	Confidence int
    17  	Offset     int
    18  	Extent     int
    19  }
    20  
    21  func NewLicense(value string) License {
    22  	spdxExpression, err := license.ParseExpression(value)
    23  	if err != nil {
    24  		log.Trace("unable to parse license expression: %s, %w", value, err)
    25  	}
    26  
    27  	return License{
    28  		Value:          value,
    29  		SPDXExpression: spdxExpression,
    30  		Type:           license.Concluded,
    31  	}
    32  }