maven

package
v13.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2019 License: Apache-2.0 Imports: 18 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllDependencies

func AllDependencies(f *Fetch, artifacts []Artifact, concurrency int, indent, buildRules bool, graph *Graph) []string

AllDependencies returns all the dependencies of these artifacts in a short format that we consume later. The format is vaguely akin to a Maven id, although we consider it an internal detail - it must agree between this and the maven_jars build rule that consumes it, but we don't hold it stable between different Please versions. The format is: group_id:artifact_id:version:{src|no_src}[:licence|licence|...]

Alternatively if buildRules is true, it will return a series of maven_jar rules that could be pasted into a BUILD file.

Types

type Artifact

type Artifact struct {

	// Raw version as found in XML
	Version string `xml:"version"`
	// A full-blown Maven version spec. If the version is not parseable (which is allowed
	// to happen :( ) then we just use Version to interpret it as a string.
	ParsedVersion Version
	// Trailing specifier e.g. "@aar"
	Specifier string

	// A "soft version", for dependencies that don't have one specified and we want to
	// provide a hint about what to do in that case.
	SoftVersion string
	// somewhat awkward, we use this to pass through excluded artifacts from above.
	Exclusions []Artifact `xml:"exclusions>exclusion"`
	// contains filtered or unexported fields
}

An Artifact is a model of a Maven artifact.

func (*Artifact) FromID

func (a *Artifact) FromID(id string) error

FromID loads this artifact from a Maven id.

func (*Artifact) GroupPath

func (a *Artifact) GroupPath() string

GroupPath returns the group ID as a path.

func (*Artifact) IsExcluded

func (a *Artifact) IsExcluded(a2 *Artifact) bool

IsExcluded returns true if the given artifact is in this one's list of exclusions.

func (*Artifact) MetadataPath

func (a *Artifact) MetadataPath() string

MetadataPath returns the path to the metadata XML file for this artifact.

func (*Artifact) Path

func (a *Artifact) Path(suffix string) string

Path returns the path to an artifact that we'd download.

func (*Artifact) PomPath

func (a *Artifact) PomPath() string

PomPath returns the path to the pom.xml for this artifact.

func (*Artifact) SetVersion

func (a *Artifact) SetVersion(ver string)

SetVersion updates the version on this artifact.

func (*Artifact) SourcePath

func (a *Artifact) SourcePath() string

SourcePath returns the path to the sources jar for this artifact.

func (Artifact) String

func (a Artifact) String() string

String prints this artifact as a Maven identifier (i.e. GroupID:ArtifactID:Version)

func (*Artifact) UnmarshalFlag

func (a *Artifact) UnmarshalFlag(value string) error

UnmarshalFlag implements the flags.Unmarshaler interface. This lets us use Artifact instances directly as flags.

type Fetch

type Fetch struct {

	// Version resolver.
	Resolver *Resolver
	// contains filtered or unexported fields
}

A Fetch fetches files for us from Maven. It memoises requests internally so we don't re-request the same file.

func NewFetch

func NewFetch(repos, exclude, optional []string) *Fetch

NewFetch constructs & returns a new Fetch instance.

func (*Fetch) HasSources

func (f *Fetch) HasSources(a *Artifact) bool

HasSources returns true if the given artifact has any sources available. Unfortunately there's no way of determining this other than making a request, and lots of servers don't seem to support HEAD requests to just find out if the artifact is there.

func (*Fetch) IsExcluded

func (f *Fetch) IsExcluded(artifact string) bool

IsExcluded returns true if this artifact should be excluded from the download.

func (*Fetch) Metadata

func (f *Fetch) Metadata(a *Artifact) *MetadataXML

Metadata returns the metadata XML for a package. This contains some information, typically the main useful thing is the latest available version of the package.

func (*Fetch) Pom

func (f *Fetch) Pom(a *Artifact) *PomXML

Pom fetches the POM XML for a package. Note that this may invoke itself recursively to fetch parent artifacts and dependencies.

func (*Fetch) ShouldInclude

func (f *Fetch) ShouldInclude(artifact string) bool

ShouldInclude returns true if we should include an optional dependency.

type Graph

type Graph struct {
	Packages map[string]pkg `json:"packages"`
	// contains filtered or unexported fields
}

A Graph is a minimal representation of the parts of `plz query graph`'s output that we care about.

func (*Graph) BuildMapping

func (g *Graph) BuildMapping()

BuildMapping sets up the internal reverse mapping of maven id -> target. It must be called once before anything else is.

func (*Graph) Dep

func (g *Graph) Dep(groupID, artifactID string) string

Dep returns the dependency for a given groupID / artifact ID. If it's not in the graph already it returns the label for a newly added target.

func (*Graph) Needed

func (g *Graph) Needed(groupID, artifactID string) bool

Needed returns true if we need a build rule for the given group ID / artifact ID. It's false if one already exists in the current build files.

type MetadataXML

type MetadataXML struct {
	Version    string `xml:"version"`
	Versioning struct {
		Latest   string `xml:"latest"`
		Release  string `xml:"release"`
		Versions struct {
			Version []string `xml:"version"`
		} `xml:"versions"`
	} `xml:"versioning"`
	Group, Artifact string
}

A MetadataXML models a Maven metadata.xml file and its contents.

func (*MetadataXML) HasVersion

func (metadata *MetadataXML) HasVersion(version string) bool

HasVersion returns true if the given package has the specified version.

func (*MetadataXML) LatestVersion

func (metadata *MetadataXML) LatestVersion() string

LatestVersion returns the latest available version of a package

func (*MetadataXML) Unmarshal

func (metadata *MetadataXML) Unmarshal(content []byte)

Unmarshal reads a metadata object from raw XML. It dies on any error.

type PomXML

type PomXML struct {
	Artifact
	sync.Mutex
	OriginalArtifact     Artifact
	Dependencies         pomDependencies `xml:"dependencies"`
	DependencyManagement struct {
		Dependencies pomDependencies `xml:"dependencies"`
	} `xml:"dependencyManagement"`
	Properties struct {
		Property []pomProperty `xml:",any"`
	} `xml:"properties"`
	Licences struct {
		Licence []struct {
			Name string `xml:"name"`
		} `xml:"license"`
	} `xml:"licenses"`
	Parent        Artifact `xml:"parent"`
	PropertiesMap map[string]string
	Dependors     []*PomXML
	HasSources    bool
}

A PomXML models a Maven pom.xml and its contents.

func (*PomXML) AddProperty

func (pom *PomXML) AddProperty(property pomProperty)

AddProperty adds a property (typically from a parent or wherever), without overwriting.

func (*PomXML) AllDependencies

func (pom *PomXML) AllDependencies() []*PomXML

AllDependencies returns all the dependencies for this package.

func (*PomXML) AllLicences

func (pom *PomXML) AllLicences() []string

AllLicences returns all the licences for this package.

func (*PomXML) Unmarshal

func (pom *PomXML) Unmarshal(f *Fetch, response []byte)

Unmarshal parses a downloaded pom.xml. This is of course less trivial than you would hope.

type Resolver

type Resolver struct {
	sync.Mutex
	// contains filtered or unexported fields
}

A Resolver resolves Maven artifacts into specific versions. Ultimately we should really be using a proper SAT solver here but we're not rushing it in favour of forcing manual disambiguation (and the majority of things going wrong are due to Maven madness anyway).

func NewResolver

func NewResolver(f *Fetch) *Resolver

NewResolver constructs and returns a new Resolver instance.

func (*Resolver) CreatePom

func (r *Resolver) CreatePom(a *Artifact) (*PomXML, bool)

CreatePom returns a pom for an artifact. If a suitable match doesn't exist, a new one will be created. The second return value is true if a new one was created.

func (*Resolver) Mediate

func (r *Resolver) Mediate()

Mediate performs recursive dependency version mediation for all artifacts. Note that this is only done within each artifact, i.e. technically solving this properly is a fairly hard problem, and we avoid that by just attempting to solve within each individual artifact.

func (*Resolver) Pom

func (r *Resolver) Pom(a *Artifact) *PomXML

Pom returns a pom for an artifact. The version doesn't have to be specified exactly. If one doesn't currently exist it will return nil.

func (*Resolver) Run

func (r *Resolver) Run(artifacts []Artifact, concurrency int)

Run runs the given number of worker threads until everything is resolved.

func (*Resolver) Submit

func (r *Resolver) Submit(dep *pomDependency)

Submit adds this dependency to the queue for future resolution.

type Version

type Version struct {
	Min, Max  VersionPart
	Raw, Path string
	Parsed    bool
}

A Version is a Maven version spec (see https://docs.oracle.com/middleware/1212/core/MAVEN/maven_version.htm), including range reference info (https://docs.oracle.com/middleware/1212/core/MAVEN/maven_version.htm) The above is pretty light on detail unfortunately (like how do you know the difference between a BuildNumber and a Qualifier) so we really are taking a bit of a guess here. If only semver had existed back then...

Note that we don't (yet?) support broken ranges like (,1.0],[1.2,).

func (*Version) Intersect

func (v *Version) Intersect(v2 *Version) bool

Intersect reduces v to the intersection of itself and v2. It returns true if the resulting version is still conceptually satisfiable.

func (*Version) LessThan

func (v *Version) LessThan(ver *Version) bool

LessThan returns true if this version is less than the given version.

func (*Version) Matches

func (v *Version) Matches(ver *Version) bool

Matches returns true if this version matches the spec given by ver. Note that this is not symmetric; if this version is 1.0 and ver is <= 2.0, this is true; conversely it is false if this is 2.0 and ver is <= 1.0. It further treats this version as exact using its Min attribute, since that's roughly how Maven does it.

func (*Version) Unmarshal

func (v *Version) Unmarshal(in string)

Unmarshal parses a Version from a raw string. Errors are not reported since literally anything can appear in a Maven version specifier; an input like "thirty-five ham and cheese sandwiches" is simply treated as a string.

type VersionPart

type VersionPart struct {
	Qualifier                 string
	Major, Minor, Incremental int
	Inclusive                 bool
	Set                       bool
}

A VersionPart forms part of a Version; it can be either an upper or lower bound.

func (VersionPart) Equals

func (v1 VersionPart) Equals(v2 VersionPart) bool

Equals returns true if the two versions are equal.

func (VersionPart) GreaterThan

func (v1 VersionPart) GreaterThan(v2 VersionPart) bool

GreaterThan returns true if v1 > v2 (or >= if v2.Inclusive)

func (VersionPart) LessThan

func (v1 VersionPart) LessThan(v2 VersionPart) bool

LessThan returns true if v1 < v2 (or <= if v2.Inclusive)

Jump to

Keyboard shortcuts

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