licensing

package
v0.74.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 17 Imported by: 35

Documentation

Index

Constants

View Source
const (
	LicenseTextPrefix   = "text://"
	LicenseFilePrefix   = "file://"
	CustomLicensePrefix = "CUSTOM License"
)

Variables

View Source
var LicenseFileNames = set.NewCaseInsensitive("license", "licence", "copyright")

LicenseFileNames are the base names (case-insensitive, without extension) of files commonly used to hold a license, e.g. LICENSE, LICENCE, COPYRIGHT.

Functions

func Classify

func Classify(filePath string, r io.Reader, confidenceLevel float64) (*types.LicenseFile, error)

Classify detects and classifies the license found in a file

func LaxSplitLicenses added in v0.56.0

func LaxSplitLicenses(str string) []string

Split license string considering spaces as separator e.g. MPL 2.0 GPL2+ => {"MPL2.0", "GPL2+"}

func NormalizeLicenseExpression added in v0.69.0

func NormalizeLicenseExpression(exp expr.Expression) expr.Expression

func NormalizeLicenseURL added in v0.74.0

func NormalizeLicenseURL(u string) string

NormalizeLicenseURL builds a matching key for a license URL. It drops an http or https scheme, a "www." prefix, a trailing slash and a document extension. It also unifies opensource.org's "/licenses/" and "/license/" paths. A Wayback Machine snapshot is replaced by the URL it captured. Only the host is lowercased. RFC 3986, section 6.2.2.1 makes the path, query and fragment case-sensitive.

func NormalizeLicenses added in v0.69.0

func NormalizeLicenses(licenses []string) []string

func SPDXLicenseIDByURL added in v0.74.0

func SPDXLicenseIDByURL(rawURL string) (string, bool)

SPDXLicenseIDByURL maps an upstream license URL (e.g. from an OSGi Bundle-License header or a pom <url>) to its canonical SPDX license ID, and returns false if no SPDX license claims that URL. The URL is normalized here, so it is passed in as it appears in the metadata.

func SplitLicenses added in v0.44.0

func SplitLicenses(str string) []string

func TrimLicenseText added in v0.56.0

func TrimLicenseText(text string) string

Types

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

func NewScanner

func NewScanner(categories map[types.LicenseCategory][]string) Scanner

func (*Scanner) Scan

func (s *Scanner) Scan(licenseName string) (types.LicenseCategory, string)

func (*Scanner) ScanTextLicense added in v0.63.0

func (s *Scanner) ScanTextLicense(licenseText string) (types.LicenseCategory, string)

ScanTextLicense checks license names from `categories` as glob patterns and matches licenseText against those patterns. If a match is found, it returns `unknown` category and severity.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL