checklicenses

package
v0.0.0-...-8023e94 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: BSD-2-Clause Imports: 23 Imported by: 0

README

Run:

$ fx set . --release $ fx build $ fx check-licenses

Test:

TBD

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckLicenseAllowList

func CheckLicenseAllowList(license *License, path string) bool

func Walk

func Walk(ctx context.Context, config *Config) error

Walk gathers all Licenses then checks for a match within each filtered file

Types

type Config

type Config struct {
	SkipDirs                     []string               `json:"skipDirs"`
	DontSkipDirs                 []string               `json:"dontSkipDirs"`
	SkipFiles                    []string               `json:"skipFiles"`
	ProhibitedLicenseTypes       []string               `json:"prohibitedLicenseTypes"`
	TextExtensionList            []string               `json:"textExtensionList"`
	StrictTextExtensionList      []string               `json:"strictTextExtensionList"`
	ExitOnDirRestrictedLicense   bool                   `json:"exitOnDirRestrictedLicense"`
	ExitOnProhibitedLicenseTypes bool                   `json:"exitOnProhibitedLicenseTypes"`
	ExitOnUnlicensedFiles        bool                   `json:"exitOnUnlicensedFiles"`
	StrictAnalysis               bool                   `json:"strictAnalysis"`
	OutputLicenseFile            bool                   `json:"outputLicenseFile"`
	MaxReadSize                  int                    `json:"maxReadSize"`
	OutputFilePrefix             string                 `json:"outputFilePrefix"`
	OutputFileExtensions         []string               `json:"outputFileExtensions"`
	SingleLicenseFiles           []string               `json:"singleLicenseFiles"`
	StopLicensePropagation       []string               `json:"stopLicensePropagation"`
	LicensePatternDir            string                 `json:"licensePatternDir"`
	CustomProjectLicenses        []CustomProjectLicense `json:"customProjectLicenses"`
	FlutterLicenses              []string               `json:"flutterLicenses"`
	NoticeTxtFiles               []string               `json:"noticeTxtFiles"`
	BaseDir                      string                 `json:"baseDir"`
	Target                       string                 `json:"target"`
	LogLevel                     string                 `json:"logLevel"`
	LicenseAllowList             map[string][]string    `json:"licenseAllowList"`
}

Config values are populated from the the json file at the default or user-specified path

func NewConfig

func NewConfig(path string) (*Config, error)

Init populates Config object with values found in the json config file.

Both SkipFiles and SingleLicenseFiles are lowered.

func (*Config) Merge

func (c *Config) Merge(other *Config)

Merge two Config struct objects into one.

  • List fields are concatenated together.
  • boolean fields will be true if either one is true. (left || right)
  • Regular fields will be equal to the left struct field ("c") if it's not equal to the default value ("" for strings, 0 for ints), otherwise they will be set to the right struct field.

type CustomProjectLicense

type CustomProjectLicense struct {
	ProjectRoot     string
	LicenseLocation string
}

type File

type File struct {
	Name     string
	Path     string     `json:"path"`
	Symlink  string     `json:"symlink"`
	Parent   *FileTree  `json:"-"`
	Licenses []*License `json:"licenses"`
}

func NewFile

func NewFile(path string, parent *FileTree) (*File, error)

func (*File) Equal

func (f *File) Equal(other *File) bool

func (*File) MarshalJSON

func (f *File) MarshalJSON() ([]byte, error)

Use a custom Marshal function to make Files easier to read in JSON: reduce associated license information down to a string list.

func (*File) String

func (f *File) String() string

type FileTree

type FileTree struct {
	Name               string                `json:"name"`
	Path               string                `json:"path"`
	SingleLicenseFiles map[string][]*License `json:"project licenses"`
	Files              []*File               `json:"files"`
	Children           []*FileTree           `json:"children"`
	Parent             *FileTree             `json:"-"`
	StrictAnalysis     bool                  `json:"strict analysis"`

	sync.RWMutex
}

FileTree is an in memory representation of the state of the repository.

func NewFileTree

func NewFileTree(ctx context.Context, root string, parent *FileTree, config *Config, metrics *Metrics) (*FileTree, error)

NewFileTree returns an instance of FileTree, given the input configuration file.

func (*FileTree) Equal

func (ft *FileTree) Equal(other *FileTree) bool

type License

type License struct {
	Category  string `json:"category"`
	ValidType bool   `json:"valid license"`

	sync.Mutex

	AllowedDirs     []string
	BadLicenseUsage []string
	// contains filtered or unexported fields
}

License contains a searchable regex pattern for finding license text in source files and LICENSE files across the repository.

func NewLicense

func NewLicense(path string, config *Config) (*License, error)

func (*License) Equal

func (l *License) Equal(other *License) bool

func (*License) Search

func (l *License) Search(data []byte, path string) bool

type Licenses

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

Licenses is an object that facilitates operations on each License object in bulk

func NewLicenses

func NewLicenses(ctx context.Context, config *Config) (*Licenses, error)

NewLicenses returns a Licenses object with each license pattern loaded from the .lic folder location specified in Config

func (*Licenses) GetFilesWithBadLicenseUsage

func (l *Licenses) GetFilesWithBadLicenseUsage() []string

func (*Licenses) GetFilesWithProhibitedLicenses

func (l *Licenses) GetFilesWithProhibitedLicenses() []string

func (*Licenses) MatchFile

func (l *Licenses) MatchFile(data []byte, path string, metrics *Metrics) (bool, *License)

MatchFile returns true if any License matches input data along with the license that matched. It returns false and nil if there were no matches.

func (*Licenses) MatchSingleLicenseFile

func (l *Licenses) MatchSingleLicenseFile(data []byte, path string, metrics *Metrics, ft *FileTree)

type Match

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

Match is used to store a single match result alongside the License along with a list of all matching files

func (*Match) GetText

func (l *Match) GetText() string

type Metrics

type Metrics struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Metrics is used for instrumentation

func NewMetrics

func NewMetrics() *Metrics

type UnlicensedFiles

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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