context

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2017 License: BSD-3-Clause Imports: 33 Imported by: 0

Documentation

Overview

Package context gathers the status of packages and stores it in Context. A new Context needs to be pointed to the root of the project and any project owned vendor file.

Package context gathers the status of packages and stores it in Context. A new Context needs to be pointed to the root of the project and any project owned vendor file.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrMissingGOROOT returns if the GOROOT was not found.
	ErrMissingGOROOT = errors.New("Unable to determine GOROOT.")
	// ErrMissingGOPATH returns if no GOPATH was found.
	ErrMissingGOPATH = errors.New("Missing GOPATH. Check your environment variable GOPATH.")
)

Functions

func Get

func Get(logger io.Writer, pkgspecName string, insecure bool) (*pkgspec.Pkg, error)

func LicenseDiscover

func LicenseDiscover(root, startIn, overridePath string, list map[string]License) error

LicenseDiscover looks for license files in a given path.

func RemovePackage

func RemovePackage(path, root string, tree bool) error

RemovePackage removes the specified folder files. If folder is empty when done (no nested folders, remove the folder and any empty parent folders.

Types

type Conflict

type Conflict struct {
	Canonical string
	Local     string
	Operation []*Operation
	OpIndex   int
	Resolved  bool
}

Conflict reports packages that are scheduled to conflict.

func ResolveAutoLongestPath

func ResolveAutoLongestPath(cc []*Conflict) []*Conflict

ResolveAutoLongestPath finds the longest local path in each conflict and set it to be used.

func ResolveAutoShortestPath

func ResolveAutoShortestPath(cc []*Conflict) []*Conflict

ResolveAutoShortestPath finds the shortest local path in each conflict and set it to be used.

type Context

type Context struct {
	Logger   io.Writer // Write to the verbose log.
	Insecure bool      // Allow insecure network operations

	GopathList []string // List of GOPATHs in environment. Includes "src" dir.
	Goroot     string   // The path to the standard library.

	RootDir        string // Full path to the project root.
	RootGopath     string // The GOPATH the project is in.
	RootImportPath string // The import path to the project.

	VendorFile       *vendorfile.File
	VendorFilePath   string // File path to vendor file.
	VendorFolder     string // Store vendor packages in this folder.
	RootToVendorFile string // The relative path from the project root to the vendor file directory.

	VendorDiscoverFolder string // Normally auto-set to "vendor"

	// Package is a map where the import path is the key.
	// Populated with LoadPackage.
	Package map[string]*Package

	// MoveRule provides the translation from original import path to new import path.
	RewriteRule map[string]string // map[from]to

	TreeImport []*pkgspec.Pkg

	Operation []*Operation
	// contains filtered or unexported fields
}

Context represents the current project context.

func NewContext

func NewContext(root, vendorFilePathRel, vendorFolder string, rewriteImports bool) (*Context, error)

NewContext creates new context from a given root folder and vendor file path. The vendorFolder is where vendor packages should be placed.

func NewContextRoot

func NewContextRoot(root string) (*Context, error)

NewContextRoot creates a new context for the given root folder.

func NewContextWD

func NewContextWD(rt RootType) (*Context, error)

NewContextWD creates a new context. It looks for a root folder by finding a vendor file.

func (*Context) Alter

func (ctx *Context) Alter() error

Alter runs any requested package alterations.

func (*Context) Check

func (ctx *Context) Check() []*Conflict

Check returns any conflicts when more than one package can be moved into the same path.

func (*Context) CopyPackage

func (ctx *Context) CopyPackage(destPath, srcPath, lookRoot, pkgPath string, ignoreFiles []string, tree bool, h hash.Hash, beforeCopy func(deps []string) error) error

CopyPackage copies the files from the srcPath to the destPath, destPath folder and parents are are created if they don't already exist.

func (*Context) IgnoreBuildAndPackage

func (ctx *Context) IgnoreBuildAndPackage(ignore string)

IgnoreBuildAndPackage takes a space separated list of tags or package prefixes to ignore. Tags are words, packages are folders, containing or ending with a "/". "a b c" will ignore tags "a" OR "b" OR "c". "p/x q/" will ignore packages "p/x" OR "p/x/y" OR "q" OR "q/z", etc.

func (*Context) ModifyImport

func (ctx *Context) ModifyImport(imp *pkgspec.Pkg, mod Modify, mops ...ModifyOption) error

ModifyImport adds the package to the context.

func (*Context) ModifyStatus

func (ctx *Context) ModifyStatus(sg StatusGroup, mod Modify, mops ...ModifyOption) error

ModifyStatus adds packages to the context by status.

func (*Context) ResloveApply

func (ctx *Context) ResloveApply(cc []*Conflict)

ResolveApply applies the conflict resolution selected. It chooses the Operation listed in the OpIndex field.

func (*Context) ResolveAutoVendorFileOrigin

func (ctx *Context) ResolveAutoVendorFileOrigin(cc []*Conflict) []*Conflict

ResolveAutoVendorFileOrigin resolves conflicts based on the vendor file if possible.

func (*Context) Status

func (ctx *Context) Status() ([]StatusItem, error)

Status obtains the current package status list.

func (*Context) Sync

func (ctx *Context) Sync(dryrun bool) (err error)

Sync checks for outdated packages in the vendor folder and fetches the correct revision from the remote.

func (*Context) VendorFilePackagePath

func (ctx *Context) VendorFilePackagePath(path string) *vendorfile.Package

VendorFilePackagePath finds a given vendor file package give the import path.

func (*Context) VerifyVendor

func (ctx *Context) VerifyVendor() (outOfDate []*vendorfile.Package, err error)

func (*Context) Write

func (ctx *Context) Write(s []byte) (int, error)

Write to the set io.Writer for logging.

func (*Context) WriteVendorFile

func (ctx *Context) WriteVendorFile() (err error)

WriteVendorFile writes the current vendor file to the context location.

type Env

type Env map[string]string

func NewEnv

func NewEnv() (Env, error)

type ErrDirtyPackage

type ErrDirtyPackage struct {
	ImportPath string
}

ErrDirtyPackage returns if package is in dirty version control.

func (ErrDirtyPackage) Error

func (err ErrDirtyPackage) Error() string

type ErrMissingVendorFile

type ErrMissingVendorFile struct {
	Path string
}

ErrMissingVendorFile returns if package already exists.

func (ErrMissingVendorFile) Error

func (err ErrMissingVendorFile) Error() string

type ErrNotInGOPATH

type ErrNotInGOPATH struct {
	Missing string
}

ErrNotInGOPATH returns if not currently in the GOPATH.

func (ErrNotInGOPATH) Error

func (err ErrNotInGOPATH) Error() string

type ErrOldVersion

type ErrOldVersion struct {
	Message string
}

ErrOldVersion returns if vendor file is not in the vendor folder.

func (ErrOldVersion) Error

func (err ErrOldVersion) Error() string

type ErrPackageExists

type ErrPackageExists struct {
	Package string
}

ErrPackageExists returns if package already exists.

func (ErrPackageExists) Error

func (err ErrPackageExists) Error() string

type ErrTreeChildren

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

func (ErrTreeChildren) Error

func (err ErrTreeChildren) Error() string

type ErrTreeParents

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

func (ErrTreeParents) Error

func (err ErrTreeParents) Error() string

type File

type File struct {
	Package *Package
	Path    string
	Imports []string

	ImportComment string
}

File holds a reference to the imports in a file and the file locaiton.

type Label

type Label struct {
	Text   string
	Source LabelSource
}

func FindLabel

func FindLabel(version string, labels []Label) Label

FindLabel matches a single label from a list of labels, given a version. If the returning label.Source is LabelNone, then no labels match.

Labels are first broken into sections separated by "-". Shortest wins. If they have the same number of above sections, then they are compared further. Number sequences are treated as numbers. Numbers do not need a separator. The "." is a break point as well.

func (Label) String

func (l Label) String() string

type LabelSource

type LabelSource byte
const (
	LabelNone LabelSource = iota
	LabelBranch
	LabelTag
)

func (LabelSource) String

func (ls LabelSource) String() string

type License

type License struct {
	Path     string
	Filename string
	Text     string
}

type LicenseSort

type LicenseSort []License

func (LicenseSort) Len

func (list LicenseSort) Len() int

func (LicenseSort) Less

func (list LicenseSort) Less(i, j int) bool

func (LicenseSort) Swap

func (list LicenseSort) Swap(i, j int)

type Modify

type Modify byte

Modify is the type of modifcation to do.

const (
	AddUpdate Modify = iota // Add or update the import.
	Add                     // Only add, error if it already exists.
	Update                  // Only update, error if it doesn't currently exist.
	Remove                  // Remove from vendor path.
	Fetch                   // Get directly from remote repository.
)

type ModifyOption

type ModifyOption byte
const (
	Uncommitted ModifyOption = iota
	MatchTree
	IncludeTree
)

type Operation

type Operation struct {
	Type OperationType

	Pkg *Package

	// Source file path to move packages from.
	// Must not be empty.
	Src string

	// Destination file path to move package to.
	// If Dest if empty the package is removed.
	Dest string

	// Files to ignore for operation.
	IgnoreFile []string

	State OperationState

	// True if the operation should treat the package as uncommitted.
	Uncommitted bool
}

Operation defines how packages should be moved.

TODO (DT): Remove Pkg field and change Src and Dest to *pkgspec.Pkg types.

type OperationState

type OperationState byte

OperationState is the state of the given package move operation.

const (
	OpReady  OperationState = iota // Operation is ready to go.
	OpIgnore                       // Operation should be ignored.
	OpDone                         // Operation has been completed.
)

type OperationType

type OperationType byte
const (
	OpCopy OperationType = iota
	OpRemove
	OpFetch
)

func (OperationType) String

func (t OperationType) String() string

type Package

type Package struct {
	OriginDir string // Origin directory
	Dir       string // Physical directory path of the package.

	Status Status // Status and location of the package.
	*pkgspec.Pkg
	Local  string // Current location of a package relative to $GOPATH/src.
	Gopath string // Includes trailing "src".
	Files  []*File
	// contains filtered or unexported fields
}

Package maintains information pertaining to a package.

func (*Package) String

func (pkg *Package) String() string

type RootType

type RootType byte
const (
	RootVendor RootType = iota
	RootWD
	RootVendorOrWD
	RootVendorOrWDOrFirstGOPATH
)

type Status

type Status struct {
	Type     StatusType     // program, package
	Location StatusLocation // vendor, local, external, stdlib
	Presence StatusPresence // missing, unused, tree, excluded

	Not bool // Not indicates boolean operation "not" on above.
}

Status is the package type, location, and presence indicators.

func (Status) Match

func (pkgSt Status) Match(filterSt Status) bool

func (Status) MatchGroup

func (status Status) MatchGroup(filter StatusGroup) bool

func (Status) String

func (s Status) String() string

type StatusGroup

type StatusGroup struct {
	Status []Status
	Group  []StatusGroup
	And    bool
	Not    bool
}

StatusGroup is the logical filter for status with "and", "not", and grouping.

func (StatusGroup) String

func (sg StatusGroup) String() string

type StatusItem

type StatusItem struct {
	Status       Status
	Pkg          *pkgspec.Pkg
	VersionExact string
	Local        string
	ImportedBy   []*Package
}

ListItem represents a package in the current project.

func (StatusItem) String

func (li StatusItem) String() string

type StatusLocation

type StatusLocation byte // StatusLocation is where the package is.
const (
	LocationUnknown  StatusLocation = iota // LocationUnknown is unset StatusLocation.
	LocationNotFound                       // LocationNotFound package is not to be found (use PresenceMissing).
	LocationStandard                       // LocationStandard package is in the standard library.
	LocationLocal                          // LocationLocal package is in a project, not in a vendor folder.
	LocationExternal                       // LocationExternal package is not in a project, in GOPATH.
	LocationVendor                         // LocationVendor package is in a vendor folder.
)

type StatusPresence

type StatusPresence byte // StatusPresence is if it can be found or referenced.
const (
	PresenceUnknown  StatusPresence = iota // PresenceUnknown is unset StatusPresence.
	PresenceFound                          // PresenceFound package exists.
	PresenceMissing                        // PresenceMissing package is referenced but not found.
	PresenceUnused                         // PresenceUnused package is found locally but not referenced.
	PresenceTree                           // PresenceTree package is in vendor folder, in a tree, but not referenced.
	PresenceExcluded                       // PresenceExcluded package exists, but should not be vendored.
)

type StatusType

type StatusType byte // StatusType is main or not-main.
const (
	TypeUnknown StatusType = iota // TypeUnknown is unset StatusType.
	TypePackage                   // TypePackage package is a non-main package.
	TypeProgram                   // TypeProgram package is a main package.
)

type TagSet

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

func (*TagSet) AddBuildTags

func (ts *TagSet) AddBuildTags(tags string)

func (*TagSet) AddFileTag

func (ts *TagSet) AddFileTag(tag string)

func (*TagSet) IgnoreItem

func (ts *TagSet) IgnoreItem(ignoreList ...string) bool

func (*TagSet) String

func (ts *TagSet) String() string

type VCSCmd

type VCSCmd struct {
	*vcs.Cmd
}

func (*VCSCmd) RevisionSync

func (vcsCmd *VCSCmd) RevisionSync(dir, revision string) error

Jump to

Keyboard shortcuts

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