collector

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MulanPSL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CombinePackage

func CombinePackage(p1, p2 *model.Package) *model.Package

CombinePackage combines two packages into one package

func EqualPackage

func EqualPackage(p1, p2 *model.Package) bool

EqualPackage checks two packages are equal

func OrganizePackage

func OrganizePackage(pkgs []model.Package) []model.Package

OrganizePackage remove and merge duplicate packages

func SortPackage

func SortPackage(pkgs []model.Package) []model.Package

SortPackage sorts packages by PURL

func StrictMode

func StrictMode() bool

StrictMode is for check package

Types

type BaseCollector

type BaseCollector struct {
	Name     string
	PurlType string
	Parsers  []FileParser
	Requests []Request
}

BaseCollector provide common properties and behaviors inherited by other collectors

func (*BaseCollector) Collect

func (c *BaseCollector) Collect() ([]model.Package, error)

func (*BaseCollector) GetName

func (c *BaseCollector) GetName() string

func (*BaseCollector) GetParsers

func (c *BaseCollector) GetParsers() []FileParser

func (*BaseCollector) GetPurlType

func (c *BaseCollector) GetPurlType() string

func (*BaseCollector) GetRequests

func (c *BaseCollector) GetRequests() []Request

func (*BaseCollector) TryToAccept

func (c *BaseCollector) TryToAccept(file File)

type Collector

type Collector interface {
	// GetName uniquely describes a Collector
	GetName() string
	// GetPurlType return a string value according to the package url spec. For details,
	// ref https://github.com/package-url/purl-spec
	GetPurlType() string
	// GetParsers return inner FileParsers
	GetParsers() []FileParser
	// TryToAccept try to match the given file using inner FileParsers respectively, accept the file if matched
	TryToAccept(file File)
	// GetRequests return requests generated at TryToAccept phase
	GetRequests() []Request
	// Collect analyze the accepted files and return discovered packages
	Collect() (pkgs []model.Package, err error)
}

Collector contains a group of FileParsers, and define common method among the FileParsers

type DependencyTree

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

DependencyTree maintains the package list and dependencies, and provides some useful methods

func NewDependencyTree

func NewDependencyTree() *DependencyTree

func (*DependencyTree) AddDependency

func (tree *DependencyTree) AddDependency(mainPurl, depPurl string)

AddDependency adds a dependency, will add the dependency's PURL to the dependency list of the main package, and the main package must exist

func (*DependencyTree) AddPackage

func (tree *DependencyTree) AddPackage(pkg *model.Package)

AddPackage adds package to the list, check whether the package exists through PURL, if exists, the package properties will be combined

func (*DependencyTree) GetDependencies

func (tree *DependencyTree) GetDependencies(purl string) []model.Package

GetDependencies get a package's dependency list via PURL

func (*DependencyTree) GetPackage

func (tree *DependencyTree) GetPackage(purl string) *model.Package

GetPackage get a package via PURL

func (*DependencyTree) GetPackagesByName

func (tree *DependencyTree) GetPackagesByName(name string) []model.Package

GetPackagesByName get packages via name

func (*DependencyTree) GetRootPackages

func (tree *DependencyTree) GetRootPackages() []model.Package

GetRootPackages get root packages

func (*DependencyTree) IsExist

func (tree *DependencyTree) IsExist(purl string) bool

IsExist Check if package exists via PURL

func (*DependencyTree) ToList

func (tree *DependencyTree) ToList() []model.Package

ToList returns a list of all packages

type File

type File interface {
	FullName() string
	Dir() string
	FileName() string
	Mime() string
	Stat() os.FileInfo
}

File define file basic information

func NewFileMeta

func NewFileMeta(path string) File

type FileMatcher

type FileMatcher interface {
	Match(file File) bool
	Description() string
}

FileMatcher is a file parser, check whether a file matches a rule

type FileMeta

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

FileMeta contains file basic information

func (*FileMeta) Dir

func (s *FileMeta) Dir() string

func (*FileMeta) FileName

func (s *FileMeta) FileName() string

func (*FileMeta) FullName

func (s *FileMeta) FullName() string

func (*FileMeta) Mime

func (s *FileMeta) Mime() string

func (*FileMeta) Stat

func (s *FileMeta) Stat() os.FileInfo

type FileMimeMatcher

type FileMimeMatcher struct {
	Mimes []string
}

FileMimeMatcher match a file by file mime

func (*FileMimeMatcher) Description

func (f *FileMimeMatcher) Description() string

func (*FileMimeMatcher) Match

func (f *FileMimeMatcher) Match(file File) bool

type FileNameMatcher

type FileNameMatcher struct {
	Names []string
}

FileNameMatcher match a file by file name

func (*FileNameMatcher) Description

func (f *FileNameMatcher) Description() string

func (*FileNameMatcher) Match

func (f *FileNameMatcher) Match(file File) bool

type FileParser

type FileParser interface {
	// Matcher return the specified file parser
	Matcher() FileMatcher
	// Parse the given path and return discovered packages
	Parse(path string) (pkgs []model.Package, err error)
}

FileParser specify a FileMatcher to match files, and parse the recognizable files to discover packages

type FilePatternMatcher

type FilePatternMatcher struct {
	// the pattern ref https://pkg.go.dev/path/filepath#Match
	Patterns []string
}

FilePatternMatcher match a file by file pattern

func (*FilePatternMatcher) Description

func (f *FilePatternMatcher) Description() string

func (*FilePatternMatcher) Match

func (f *FilePatternMatcher) Match(file File) bool

type FileRegexpMatcher

type FileRegexpMatcher struct {
	Regexps []*regexp.Regexp
}

FileRegexpMatcher match a file by regexp

func (*FileRegexpMatcher) Description

func (f *FileRegexpMatcher) Description() string

func (*FileRegexpMatcher) Match

func (f *FileRegexpMatcher) Match(file File) bool

type MainPkgParser

type MainPkgParser interface {
	ParseMain(path string) (pkg *model.Package, err error)
}

MainPkgParser parse a file and generate main package

type Request

type Request struct {
	File   File
	Parser FileParser
}

Request represents a file and parser pair, and the parser can recognize and parse the file

Directories

Path Synopsis
mvn

Jump to

Keyboard shortcuts

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