search

package
v0.0.0-...-12d6510 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2019 License: MIT Imports: 2 Imported by: 3

Documentation

Overview

Package search provides a mini-DSL for nexus.Client.Artifacts().

Index

Examples

Constants

View Source
const All = noCriteria(true)

All is the zero value for Criteria. Its Parameters() returns an empty map.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByChecksum

type ByChecksum string

ByChecksum searches by SHA1 checksum.

func (ByChecksum) Parameters

func (sha1 ByChecksum) Parameters() map[string]string

Parameters implements the search.Criteria interface.

func (ByChecksum) String

func (sha1 ByChecksum) String() string

String implements the fmt.Stringer interface.

type ByClassname

type ByClassname string

ByClassname searches by class name.

func (ByClassname) Parameters

func (cn ByClassname) Parameters() map[string]string

Parameters implements the search.Criteria interface.

func (ByClassname) String

func (cn ByClassname) String() string

String implements the fmt.Stringer interface.

type ByCoordinates

type ByCoordinates struct {
	GroupID    string // e.g. com.atlassian.maven.plugins
	ArtifactID string // e.g. maven-jgitflow-plugin
	Version    string // e.g. 1.0-alpha27, 2.0.0-SNAPSHOT...
	Classifier string // e.g. sources, javadoc, jdk15...
	Packaging  string // e.g. maven-plugin, ear, war, jar, pom...
}

ByCoordinates searches by Maven project coordinates (http://maven.apache.org/pom.html#Maven_Coordinates). Nexus' search by coordinates has certain issues and peculiarities, some shown in the examples below.

Example
package main

import (
	"sbrubbles.org/go/nexus"
	"sbrubbles.org/go/nexus/credentials"
	"sbrubbles.org/go/nexus/search"
)

func main() {
	n := nexus.New("https://maven.java.net", credentials.None)

	// Returns all artifacts with a groupID starting with com.sun. Due to Go's
	// struct syntax, we don't need to specify all the coordinates; they
	// default to string's zero value (""), which Nexus ignores.
	n.Artifacts(search.ByCoordinates{GroupID: "com.sun*"})

	// A coordinate search requires specifying at least either a groupID, an
	// artifactID or a version. This search will (after some time), return
	// nothing. This doesn't mean there are no projects with packaging "pom";
	// this is a limitation of Nexus' search.
	n.Artifacts(search.ByCoordinates{Packaging: "pom"})

	// This search may or may not return an error, depending on the version of
	// the Nexus being accessed. On newer Nexuses (sp?) "*" searches are
	// invalid.
	n.Artifacts(search.ByCoordinates{GroupID: "*", Packaging: "pom"})

	// ByCoordinates searches in Maven *projects*, not artifacts. So this
	// search will return all com.sun* artifacts in projects with packaging
	// "pom", not all POM artifacts with groupID com.sun*! Packaging is not
	// the same as extension.
	n.Artifacts(search.ByCoordinates{GroupID: "com*", Packaging: "pom"})
}
Output:

func (ByCoordinates) Parameters

func (gav ByCoordinates) Parameters() map[string]string

Parameters implements the search.Criteria interface.

func (ByCoordinates) String

func (gav ByCoordinates) String() string

String implements the fmt.Stringer interface.

type ByKeyword

type ByKeyword string

ByKeyword searches by keywords.

Example
package main

import (
	"sbrubbles.org/go/nexus"
	"sbrubbles.org/go/nexus/credentials"
	"sbrubbles.org/go/nexus/search"
)

func main() {
	n := nexus.New("https://maven.java.net", credentials.None)

	// Return all artifacts with javax.enterprise somewhere.
	n.Artifacts(search.ByKeyword("javax.enterprise*"))

	// This search may or may not return an error, depending on the version of
	// the Nexus being accessed. On newer Nexuses (sp?) "*" searches are
	// invalid.
	n.Artifacts(search.ByKeyword("*"))
}
Output:

func (ByKeyword) Parameters

func (q ByKeyword) Parameters() map[string]string

Parameters implements the search.Criteria interface.

func (ByKeyword) String

func (q ByKeyword) String() string

String implements the fmt.Stringer interface.

type ByRepository

type ByRepository string

ByRepository searches for all artifacts in the given repository ID.

func (ByRepository) Parameters

func (byRepo ByRepository) Parameters() map[string]string

Parameters implements the search.Criteria interface.

func (ByRepository) String

func (byRepo ByRepository) String() string

String implements the fmt.Stringer interface.

type Criteria

type Criteria interface {
	Parameters() map[string]string
}

Criteria represents a search request. It compiles to a single map with the parameters Nexus expects. Nexus' API supports 4 different types of searches, but in the end, all we need is a map holding the parameters to pass along.

func OrZero

func OrZero(c Criteria) Criteria

OrZero returns the given criteria untouched if it's not nil, and search.All otherwise. Useful for when one must ensure a non-nil criteria.

type InRepository

type InRepository struct {
	RepositoryID string // e.g. releases

	Criteria Criteria // e.g. search.ByKeyword("javax.enterprise")
}

InRepository searches for all artifacts in the given repository ID following the given criteria.

Example
package main

import (
	"sbrubbles.org/go/nexus"
	"sbrubbles.org/go/nexus/credentials"
	"sbrubbles.org/go/nexus/search"
)

func main() {
	n := nexus.New("https://maven.java.net", credentials.None)

	// Returns all artifacts in the repository releases with groupID starting
	// with com.sun and whose project has packaging "pom".
	n.Artifacts(
		search.InRepository{
			"releases",
			search.ByCoordinates{GroupID: "com.sun*", Packaging: "pom"},
		})

	// Nexus doesn't support * in the repository ID parameter, so this search
	// will return an error.
	n.Artifacts(
		search.InRepository{
			"releases*",
			search.ByCoordinates{GroupID: "com.sun*", Packaging: "pom"},
		})
}
Output:

func (InRepository) Parameters

func (inRepo InRepository) Parameters() map[string]string

Parameters implements the search.Criteria interface.

func (InRepository) String

func (inRepo InRepository) String() string

String implements the fmt.Stringer interface.

Jump to

Keyboard shortcuts

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