deps

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2021 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Licensed to Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Apache Software Foundation (ASF) licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Apache Software Foundation (ASF) licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Apache Software Foundation (ASF) licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Apache Software Foundation (ASF) licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Apache Software Foundation (ASF) licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Apache Software Foundation (ASF) licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Apache Software Foundation (ASF) licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Licensed to Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Apache Software Foundation (ASF) licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const PkgFileName = "package.json"
View Source
const (
	Unknown string = "Unknown"
)

Variables

Functions

func Check

func Check(mainLicenseSpdxID string, config *ConfigDeps) error

func GetLicenseFromURL

func GetLicenseFromURL(url string) string

func Resolve

func Resolve(config *ConfigDeps, report *Report) error

func SeemLicense

func SeemLicense(content string) bool

SeemLicense determine whether the content of the file may be a license file

Types

type ConfigDeps

type ConfigDeps struct {
	Files []string `yaml:"files"`
}

func (*ConfigDeps) Finalize

func (config *ConfigDeps) Finalize(configFile string) error

type Dependency

type Dependency struct {
	GroupID                               []string
	ArtifactID, Version, Packaging, Scope string
	TransitiveDeps                        []*Dependency
}

func LoadDependencies

func LoadDependencies(data []byte) []*Dependency

func LoadDependenciesTree

func LoadDependenciesTree(data []byte) []*Dependency

func (*Dependency) Clone

func (dep *Dependency) Clone() *Dependency

func (*Dependency) Count

func (dep *Dependency) Count() int

func (*Dependency) Jar

func (dep *Dependency) Jar() string

func (*Dependency) Path

func (dep *Dependency) Path() string

func (*Dependency) Pom

func (dep *Dependency) Pom() string

func (*Dependency) String

func (dep *Dependency) String() string

type GoModResolver

type GoModResolver struct {
	Resolver
}

func (*GoModResolver) CanResolve

func (resolver *GoModResolver) CanResolve(file string) bool

func (*GoModResolver) Resolve

func (resolver *GoModResolver) Resolve(goModFile string, report *Report) error

Resolve resolves licenses of all dependencies declared in the go.mod file.

func (*GoModResolver) ResolvePackageLicense

func (resolver *GoModResolver) ResolvePackageLicense(module *packages.Module, report *Report) error

func (*GoModResolver) ResolvePackages

func (resolver *GoModResolver) ResolvePackages(modules []*packages.Module, report *Report) error

ResolvePackages resolves the licenses of the given packages.

type JarResolver

type JarResolver struct{}

func (*JarResolver) CanResolve

func (resolver *JarResolver) CanResolve(jarFile string) bool

func (*JarResolver) IdentifyLicense

func (resolver *JarResolver) IdentifyLicense(path, dep, content, version string, report *Report) error

func (*JarResolver) ReadFileFromZip

func (resolver *JarResolver) ReadFileFromZip(archiveFile *zip.File) (*bytes.Buffer, error)

func (*JarResolver) Resolve

func (resolver *JarResolver) Resolve(jarFile string, report *Report) error

func (*JarResolver) ResolveJar

func (resolver *JarResolver) ResolveJar(state *State, jarFile, version string, report *Report) error

type Lcs

type Lcs struct {
	Type string `json:"type"`
	URL  string `json:"url"`
}

Lcs represents the license style in package.json

type MavenPomResolver

type MavenPomResolver struct {
	JarResolver
	// contains filtered or unexported fields
}

func (*MavenPomResolver) CanResolve

func (resolver *MavenPomResolver) CanResolve(mavenPomFile string) bool

CanResolve determine whether the file can be resolve by name of the file

func (*MavenPomResolver) CheckMVN

func (resolver *MavenPomResolver) CheckMVN() error

CheckMVN check available maven tools, find local repositories and download all dependencies

func (*MavenPomResolver) DownloadDeps

func (resolver *MavenPomResolver) DownloadDeps() error

func (*MavenPomResolver) FindLocalRepository

func (resolver *MavenPomResolver) FindLocalRepository() error

func (*MavenPomResolver) FindMaven

func (resolver *MavenPomResolver) FindMaven(execName string) error

func (*MavenPomResolver) LoadDependencies

func (resolver *MavenPomResolver) LoadDependencies() ([]*Dependency, error)

func (*MavenPomResolver) ReadHeaderCommentsFromPom

func (resolver *MavenPomResolver) ReadHeaderCommentsFromPom(pomFile string) (string, error)

func (*MavenPomResolver) ReadLicensesFromPom

func (resolver *MavenPomResolver) ReadLicensesFromPom(pomFile string) (*PomFile, error)

func (*MavenPomResolver) Resolve

func (resolver *MavenPomResolver) Resolve(mavenPomFile string, report *Report) error

Resolve resolves licenses of all dependencies declared in the pom.xml file.

func (*MavenPomResolver) ResolveDependencies

func (resolver *MavenPomResolver) ResolveDependencies(deps []*Dependency, report *Report) error

ResolveDependencies resolves the licenses of the given dependencies

func (*MavenPomResolver) ResolveLicense

func (resolver *MavenPomResolver) ResolveLicense(state *State, dep *Dependency, report *Report) error

ResolveLicense search all possible locations of the license, such as pom file, jar package

func (*MavenPomResolver) ResolveLicenseFromPom

func (resolver *MavenPomResolver) ResolveLicenseFromPom(state *State, dep *Dependency, report *Report) (err error)

ResolveLicenseFromPom search for license in the pom file, which may appear in the header comments or in license element of xml

type NpmResolver

type NpmResolver struct {
	Resolver
}

func (*NpmResolver) CanResolve

func (resolver *NpmResolver) CanResolve(file string) bool

CanResolve checks whether the given file is the npm package file

func (*NpmResolver) GetInstalledPkgs

func (resolver *NpmResolver) GetInstalledPkgs(pkgDir string) []*Package

GetInstalledPkgs gathers all the installed packages' names and paths it uses a package directory's relative path from the node_modules directory, to infer its package name

func (*NpmResolver) InstallPkgs

func (resolver *NpmResolver) InstallPkgs()

InstallPkgs runs command 'npm install' to install node packages

func (*NpmResolver) ListPkgPaths

func (resolver *NpmResolver) ListPkgPaths() (io.Reader, error)

ListPkgPaths runs npm command to list all the production only packages' absolute paths, one path per line Note that although the flag `--long` can show more information line like a package's name, its realization and printing format is not uniform in different npm-cli versions

func (*NpmResolver) NeedSkipInstallPkgs

func (resolver *NpmResolver) NeedSkipInstallPkgs() bool

NeedSkipInstallPkgs queries whether to skip the procedure of installing or updating packages

func (*NpmResolver) ParsePkgFile

func (resolver *NpmResolver) ParsePkgFile(pkgFile string) (*Package, error)

ParsePkgFile parses the content of the package file

func (*NpmResolver) Resolve

func (resolver *NpmResolver) Resolve(pkgFile string, report *Report) error

Resolve resolves licenses of all dependencies declared in the package.json file.

func (*NpmResolver) ResolveLcsFile

func (resolver *NpmResolver) ResolveLcsFile(result *Result, pkgPath string) error

ResolveLcsFile tries to find the license file to identify the license

func (*NpmResolver) ResolveLicenseField

func (resolver *NpmResolver) ResolveLicenseField(rawData []byte) (string, bool)

ResolveLicenseField parses and validates the "license" field in package.json file

func (*NpmResolver) ResolveLicensesField

func (resolver *NpmResolver) ResolveLicensesField(licenses []Lcs) (string, bool)

ResolveLicensesField parses and validates the "licenses" field in package.json file Additionally, the output is converted into the SPDX license expression syntax version 2.0 string, like "ISC OR GPL-3.0"

func (*NpmResolver) ResolvePackageLicense

func (resolver *NpmResolver) ResolvePackageLicense(pkgName, pkgPath string) *Result

ResolvePackageLicense resolves the licenses of the given packages. First, try to find and parse the package's package.json file to check the license file If the previous step fails, then try to identify the package's LICENSE file It's a necessary procedure to check the LICENSE file, because the resolver needs to record the license content

func (*NpmResolver) ResolvePkgFile

func (resolver *NpmResolver) ResolvePkgFile(result *Result, pkgPath string) error

ResolvePkgFile tries to find and parse the package.json file to capture the license field

type Package

type Package struct {
	Name     string          `json:"name"`
	License  json.RawMessage `json:"license"`
	Licenses []Lcs           `json:"licenses"`
	Path     string          `json:"-"`
	Version  string          `json:"version"`
}

Package represents package.json License field has inconsistent styles, so we just store the byte array here to postpone unmarshalling

type PomFile

type PomFile struct {
	XMLName  xml.Name      `xml:"project"`
	Licenses []*XMLLicense `xml:"licenses>license,omitempty"`
}

PomFile is used to extract license from the pom.xml file

func (*PomFile) AllLicenses

func (pom *PomFile) AllLicenses() string

AllLicenses return all licenses found in pom.xml file

func (*PomFile) Raw

func (pom *PomFile) Raw() string

Raw return raw data

type Report

type Report struct {
	Resolved []*Result
	Skipped  []*Result
}

Report is a collection of resolved Result.

func (*Report) Resolve

func (report *Report) Resolve(result *Result)

Resolve marks the dependency's license is resolved.

func (*Report) Skip

func (report *Report) Skip(result *Result)

Skip marks the dependency's license is skipped for some reasons.

func (*Report) String

func (report *Report) String() string

type Resolver

type Resolver interface {
	CanResolve(string) bool
	Resolve(string, *Report) error
}

type Result

type Result struct {
	Dependency      string
	LicenseFilePath string
	LicenseContent  string
	LicenseSpdxID   string
	ResolveErrors   []error
	Version         string
}

Result is a single item that represents a resolved dependency license.

type SpdxID

type SpdxID string

type State

type State int
const (
	FoundLicenseInPomHeader State = 1 << iota
	FoundLicenseInJarLicenseFile
	FoundLicenseInJarManifestFile
	NotFound State = 0
)

func (*State) String

func (s *State) String() string

type XMLLicense

type XMLLicense struct {
	Name         string `xml:"name,omitempty"`
	URL          string `xml:"url,omitempty"`
	Distribution string `xml:"distribution,omitempty"`
	Comments     string `xml:"comments,omitempty"`
}

func (*XMLLicense) Item

func (l *XMLLicense) Item() string

func (*XMLLicense) Raw

func (l *XMLLicense) Raw() string

Jump to

Keyboard shortcuts

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