unit

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2016 License: BSD-3-Clause, MIT Imports: 11 Imported by: 84

Documentation

Overview

Package unit provides a source unit abstraction over distribution packages in various languages.

Package unit is a generated protocol buffer package.

It is generated from these files:
	unit.proto

It has these top-level messages:
	RepoSourceUnit

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthUnit = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowUnit   = fmt.Errorf("proto: integer overflow")
)

Functions

func ExpandPaths

func ExpandPaths(base string, paths []string) ([]string, error)

ExpandPaths interprets paths, which contains paths (optionally with filepath.Glob-compatible globs) that are relative to base. A list of actual files that are referenced is returned.

func ParseID

func ParseID(unitID string) (name, typ string, err error)

ParseID parses the name and type from a source unit ID (from (*SourceUnit).ID()).

Types

type ID

type ID string

ID is a source unit ID. It is only unique within a repository.

type ID2 added in v0.0.33

type ID2 struct {
	Type string
	Name string
}

ID2 is a source unit ID. It is only unique within a repository.

func (ID2) String added in v0.0.33

func (v ID2) String() string

type Info

type Info struct {
	// NameInRepository is the name to use when displaying the source unit in
	// the context of the repository in which it is defined. This name
	// typically needs less qualification than GlobalName.
	//
	// For example, a Go package's GlobalName is its repository URI basename
	// plus its directory path within the repository (e.g.,
	// "github.com/user/repo/x/y"'s NameInRepository is "repo/x/y"). Because npm
	// and pip packages are named globally, their name is probably appropriate
	// to use as both the unit's NameInRepository and GlobalName.
	NameInRepository string

	// GlobalName is the name to use when displaying the source unit *OUTSIDE OF*
	// the context of the repository in which it is defined.
	//
	// For example, a Go package's GlobalName is its full import path. Because
	// npm and pip packages are named globally, their name is probably
	// appropriate to use as both the unit's NameInRepository and GlobalName.
	GlobalName string

	// Description is a short (~1-sentence) description of the source unit.
	Description string

	// TypeName is the human-readable name of the type of source unit; e.g., "Go
	// package".
	TypeName string
}

func GetInfo

func GetInfo(u SourceUnit) Info

GetInfo returns a source unit's Info field if non-nil, or otherwise an Info struct filled with values derived from the source unit's name and type.

type Key added in v0.0.33

type Key struct {
	// Repo is the URI of the repository containing this source unit.
	Repo string

	// CommitID is the VCS commit that the source unit exists at.
	CommitID string

	// UnitType is the source unit's Type.
	UnitType string

	// Unit is the source unit's Name.
	Unit string
}

Key is the unique key for a source unit.

func (Key) ID2 added in v0.0.33

func (u Key) ID2() ID2

type RepoSourceUnit

type RepoSourceUnit struct {
	Repo     string `protobuf:"bytes,1,opt,name=Repo,proto3" json:"Repo,omitempty"`
	CommitID string `protobuf:"bytes,2,opt,name=CommitID,proto3" json:"CommitID,omitempty"`
	UnitType string `protobuf:"bytes,3,opt,name=UnitType,proto3" json:"UnitType,omitempty"`
	Unit     string `protobuf:"bytes,4,opt,name=Unit,proto3" json:"Unit,omitempty"`
	// Data is the JSON of the underlying SourceUnit.
	Data []byte `protobuf:"bytes,5,opt,name=Data,proto3" json:"Data,omitempty"`
}

A RepoSourceUnit is the "concrete" form of SourceUnit that includes information about which repository (and commit) the source unit exists in. In general, type SourceUnit is used during analysis of a single source unit and type RepoSourceUnit is used afterwards (either in cross-source-unit analysis, such as cross-reference resolution, or in after-the-fact DB/API queries).

func NewRepoSourceUnit added in v0.0.29

func NewRepoSourceUnit(u *SourceUnit) (*RepoSourceUnit, error)

NewRepoSourceUnit creates an equivalent RepoSourceUnit from a SourceUnit.

It does not set the returned source unit's Private field (because it can't tell if it is private from the underlying source unit alone).

It also doesn't set CommitID (for the same reason).

func (*RepoSourceUnit) Marshal added in v0.2.0

func (m *RepoSourceUnit) Marshal() (data []byte, err error)

func (*RepoSourceUnit) MarshalTo added in v0.2.0

func (m *RepoSourceUnit) MarshalTo(data []byte) (int, error)

func (*RepoSourceUnit) ProtoMessage added in v0.1.0

func (*RepoSourceUnit) ProtoMessage()

func (*RepoSourceUnit) Reset added in v0.1.0

func (m *RepoSourceUnit) Reset()

func (*RepoSourceUnit) Size added in v0.2.0

func (m *RepoSourceUnit) Size() (n int)

func (*RepoSourceUnit) SourceUnit

func (u *RepoSourceUnit) SourceUnit() (*SourceUnit, error)

SourceUnit decodes u's Data JSON field to the SourceUnit it represents.

func (*RepoSourceUnit) String added in v0.1.0

func (m *RepoSourceUnit) String() string

func (*RepoSourceUnit) Unmarshal added in v0.2.0

func (m *RepoSourceUnit) Unmarshal(data []byte) error

type SourceUnit

type SourceUnit struct {
	// Name is an opaque identifier for this source unit that MUST be unique
	// among all other source units of the same type in the same repository.
	//
	// Two source units of different types in a repository may have the same name.
	// To obtain an identifier for a source unit that is guaranteed to be unique
	// repository-wide, use the ID method.
	Name string

	// Type is the type of source unit this represents, such as "GoPackage".
	Type string

	// Repo is the URI of the repository containing this source unit, if any.
	// The scanner tool does not need to set this field - it can be left blank,
	// to be filled in by the `srclib` tool
	Repo string `json:",omitempty"`

	// CommitID is the commit ID of the repository containing this
	// source unit, if any. The scanner tool need not fill this in; it
	// should be left blank, to be filled in by the `srclib` tool.
	CommitID string `json:",omitempty"`

	// Globs is a list of patterns that match files that make up this source
	// unit. It is used to detect when the source unit definition is out of date
	// (e.g., when a file matches the glob but is not in the Files list).
	//
	// TODO(sqs): implement this in the Makefiles
	Globs []string `json:",omitempty"`

	// Files is all of the files that make up this source unit. Filepaths should
	// be relative to the repository root.
	Files []string

	// Dir is the root directory of this source unit. It is optional and maybe
	// empty.
	Dir string `json:",omitempty"`

	// Dependencies is a list of dependencies that this source unit has. The
	// schema for these dependencies is internal to the scanner that produced
	// this source unit. The dependency resolver is expected to know how to
	// interpret this schema.
	//
	// The dependency information stored in this field should be able to be very
	// quickly determined by the scanner. The scanner should not perform any
	// dependency resolution on these entries. This is because the scanner is
	// run frequently and should execute very quickly, and dependency resolution
	// is often slow (requiring network access, etc.).
	Dependencies []interface{} `json:",omitempty"`

	// Info is an optional field that contains additional information used to
	// display the source unit
	Info *Info `json:",omitempty"`

	// Data is additional data dumped by the scanner about this source unit. It
	// typically holds information that the scanner wants to make available to
	// other components in the toolchain (grapher, dep resolver, etc.).
	Data interface{} `json:",omitempty"`

	// Config is an arbitrary key-value property map. The Config map from the
	// tree config is copied verbatim to each source unit. It can be used to
	// pass options from the Srcfile to tools.
	Config map[string]interface{} `json:",omitempty"`

	// Ops enumerates the operations that should be performed on this source
	// unit. Each key is the name of an operation, and the value is the tool to
	// use to perform that operation. If the value is nil, the tool is chosen
	// automatically according to the user's configuration.
	Ops map[string]*srclib.ToolRef `json:",omitempty"`
}

START SourceUnit OMIT

func (SourceUnit) ContainsAny added in v0.0.32

func (u SourceUnit) ContainsAny(filenames []string) bool

ContainsAny returns true if u contains any files in filesnames. Currently doesn't process globs.

func (SourceUnit) ID

func (u SourceUnit) ID() ID

ID returns an opaque identifier for this source unit that is guaranteed to be unique among all other source units in the same repository.

func (*SourceUnit) ID2 added in v0.0.33

func (u *SourceUnit) ID2() ID2

func (*SourceUnit) Key added in v0.0.33

func (u *SourceUnit) Key() Key

func (*SourceUnit) OpsSorted

func (u *SourceUnit) OpsSorted() []string

OpsSorted returns the keys of the Ops map in sorted order.

func (SourceUnit) String added in v0.0.33

func (u SourceUnit) String() string

type SourceUnits added in v0.0.33

type SourceUnits []*SourceUnit

func (SourceUnits) Len added in v0.0.33

func (v SourceUnits) Len() int

func (SourceUnits) Less added in v0.0.33

func (v SourceUnits) Less(i, j int) bool

func (SourceUnits) Swap added in v0.0.33

func (v SourceUnits) Swap(i, j int)

Jump to

Keyboard shortcuts

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