version

package module
v0.0.0-...-d3157d6 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: Apache-2.0 Imports: 6 Imported by: 14

README

go-mvn-version

A Go library for parsing maven(java) package versions

go-mvn-version is a library for parsing and comparing versions

The implementation is based on this specification

other reference: maven implementation

Installation and Usage

Installation can be done with a normal go get:

$ go get github.com/masahiro331/go-mvn-version

Version Parsing and Comparison

import "github.com/masahiro331/go-mvn-version"

v1, err := version.NewVersion("10-snapshot")
v2, err := version.NewVersion("10-b1")

if v1.GreaterThan(*v2) {
    fmt.Printf("%s is greater than %s", v1, v2)
}

WARNING

This implementation based on the maven specification, but not the maven implementation.

See issues: ComparableVersion incorrectly parses certain version strings

$ go test .
--- FAIL: TestVersionsNumber (0.00s)
    version_test.go:415: expected: 2.0.a < 2.0.0.a
    version_test.go:418: expected: 2.0.0.a > 2.0.a
FAIL
FAIL    github.com/masahiro331/go-mvn-version/pkg/version       0.005s
FAIL

License

Apache License 2.0

Author

Masahiro Fujimura

Documentation

Index

Constants

View Source
const (
	MINVersion = "-----1"
	MAXVersion = "99999999999999999999"
)

Variables

View Source
var (
	Qualifiers          = []string{"alpha", "beta", "milestone", "rc", "snapshot", "", "sp"}
	Aliases             = map[string]string{"ga": "", "final": "", "release": "", "cr": "rc"}
	ReleaseVersionIndex = fmt.Sprint(indexOf("", Qualifiers))
)

Functions

This section is empty.

Types

type Comparer

type Comparer interface {
	Check(v Version) bool
}

func NewComparer

func NewComparer(v string) (Comparer, error)

type Constraints

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

Constraints is one or more constraint that a version can be checked against.

func NewConstraints

func NewConstraints(v string) (Constraints, error)

func (Constraints) Check

func (cs Constraints) Check(v Version) bool

func (Constraints) String

func (cs Constraints) String() string

String returns the string format of the constraints

type IntItem

type IntItem int

func (IntItem) Compare

func (item1 IntItem) Compare(item2 Item) int

type Item

type Item interface {
	Compare(v2 Item) int
	// contains filtered or unexported methods
}

type ListItem

type ListItem []Item

func (ListItem) Compare

func (items1 ListItem) Compare(item2 Item) int

type ListItemStack

type ListItemStack []ListItem

func (*ListItemStack) IsEmpty

func (s *ListItemStack) IsEmpty() bool

IsEmpty checks if stack is empty

func (*ListItemStack) Pop

func (s *ListItemStack) Pop() ListItem

Pop removes and returns top element of stack. Return false if stack is empty.

func (*ListItemStack) Push

func (s *ListItemStack) Push(item ListItem)

Push pushes a new value onto the stack

type Requirements

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

func NewRequirements

func NewRequirements(v string) (Requirements, error)

NewRequirements is return Requirement [1.0.0], [1.0.1] => []requirement{"[1.0.0]","[1.0.1]"} [1.0.0] => []requirement{"[1.0.0]"}

func (Requirements) Check

func (rs Requirements) Check(v Version) bool

type StringItem

type StringItem string

func (StringItem) Compare

func (item1 StringItem) Compare(item2 Item) int

type Version

type Version struct {
	Value string
	Items ListItem
}

func NewVersion

func NewVersion(v string) (Version, error)

func (Version) Compare

func (v1 Version) Compare(v2 Version) int

func (Version) Equal

func (v1 Version) Equal(v2 Version) bool

func (Version) GreaterThan

func (v1 Version) GreaterThan(v2 Version) bool

func (Version) GreaterThanOrEqual

func (v1 Version) GreaterThanOrEqual(v2 Version) bool

func (Version) LessThan

func (v1 Version) LessThan(v2 Version) bool

func (Version) LessThanOrEqual

func (v1 Version) LessThanOrEqual(v2 Version) bool

func (Version) String

func (v1 Version) String() string

Jump to

Keyboard shortcuts

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