Code Monkey home page Code Monkey logo

version-utils's Introduction

VersionUtils

Easily parse and compare version strings!

<!-- Available on Maven Central -->
<dependency>
    <groupId>io.github.adamhamlin</groupId>
    <artifactId>version-utils</artifactId>
    <version>0.0.1</version>
</dependency>

Usage

// Instantiate Version objects from strings
var v = Version("2020.2.8-SNAPSHOT")
v.major // 2020
v.minor // 2
v.patch // 8
v.suffix // "SNAPSHOT"
v.versionStr // "2020.2.8"

v = Version("2.14_test_beta_debug")
v.major // 2
v.minor // 14
v.patch // 0
v.suffix // "test_debug_beta"
v.versionStr // "2.14.0"

The Version class also implements Ordered, so you can compare/sort Version objects:

// Compare
Version("2.3.7") < Version("2.4") // true
Version("1.0") >= Version("0.9.1") // true
Version("6.4") == Version("6.4.0") // true
// Sort
val first = Version("1.0.5")
val second = Version("1.9")
val third = Version("1.12_SNAPSHOT")
Seq(second, third, first).sorted // Seq(first, second, third)

You can also pattern match on strings to deconstruct Version objects:

"2020.4_TEST" match {
  case Version(major, minor, patch, suffix) => // 2020, 4, 0, "TEST"
}

You can work with version strings that have 1-3 version parts

Any missing/non-numeric version parts are defaulted to 0

The suffix is considered to be everything after the first hyphen or underscore

Development

Deploying to Sonatype

In order to publish, you'll need the following:

  • A Sonatype account with privileged access for this groupId
  • A maven settings file configured with the ossrh server and your Sonatype credentials
  • A GPG key pair for signing the artifacts

To do a dry-run, execute the following:

mvn clean install -Prelease --settings /path/to/sonatypeSettings.xml
gpg --verify target/*.pom.asc
# Verify the above command outputted a "Good signature..."

Once you're confident, you can actually publish to the nexus using

mvn clean deploy -Prelease --settings /path/to/sonatypeSettings.xml

You can immediately view the artifacts in the staging repository.

The artifacts should be available on Maven Central within 30 minutes and searchable within 4 hours.

Future Work

  • Option to limit or extend the number of version parts to be used.
  • Option to specify a different delimiter for the suffix, or the version parts.
  • Add suffix comparison as tiebreaker for Version comparison with same major, minor, patch.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.