Giter Site home page Giter Site logo

java-npm-semver's Introduction

Java npm SemVer

This is a direct port node-semver, great to have npm like semantics in a Java application.

Releases

Available in the Maven Central repository.

Maven configuration

<dependency>
  <groupId>com.github.yuchi</groupId>
  <artifactId>npm-semver</artifactId>
  <version>1.0.0</version>
</dependency>

Gradle configuration

compile group: "com.github.yuchi", name: "npm-semver", version: "1.0.0"
// or
compile "com.github.yuchi:npm-semver:1.0.0"

Quick usage

Version version = Version.from("1.2.3");
Range range = Range.from("^1.2.0");

range.test(version) // true

Full Usage

Version comparison

boolean loose = false;

Version v1 = Version.from("1.2.3", loose);
String v2 = Version.from("1.3.0", loose);

v1.compareTo(v2); // -1
v2.compareTo(v1); // +1
v1.compareTo(v1); //  0

In Range tests

boolean loose = false;

Version v = Version.from("1.2.3", loose);
Range r = Range.from("^1.0.0", loose);

r.test(v); // true

Range boundaries test

boolean loose = false;

SemVer.isGreaterThenRange("1.3.0", ">1.0.0 <1.4.0", loose); // false
SemVer.isGreaterThenRange("1.5.0", ">1.0.0 <1.4.0", loose); // true
SemVer.isGreaterThenRange("0.9.0", ">1.0.0 <1.4.0", loose); // false

SemVer.isLessThenRange("1.3.0", ">1.0.0 <1.4.0", loose); // false
SemVer.isLessThenRange("1.5.0", ">1.0.0 <1.4.0", loose); // false
SemVer.isLessThenRange("0.9.0", ">1.0.0 <1.4.0", loose); // true

Sorting

List<Version> versions = new ArrayList<Version>();

versions.add(Version.from("4.2.0", false));
versions.add(Version.from("1.8.0", false));
versions.add(Version.from("1.2.0", false));

versions.sort(new VersionComparator()); // { "4.2.0", "1.8.0", "1.2.0" }

Versions Stream filtering

List<Version> versions = new ArrayList<Version>();

versions.add(Version.from("4.2.0", false));
versions.add(Version.from("1.8.0", false));
versions.add(Version.from("1.2.0", false));

Range range = Range.from(">3.0.0", false);

version.stream().filter(range::test); // { "4.2.0" }

Publishing

$ trash build
$ trash tmp
$ mkdir tmp
$ gradle clean preparePublish publish
$ gradle clean preparePublish publish # yes you need to launch it twice

License

This library, java-npm-semver, is free software ("Licensed Software"); you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; including but not limited to, the implied warranty of MERCHANTABILITY, NONINFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

java-npm-semver's People

Contributors

yuchi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

java-npm-semver's Issues

Maven artifact

Hi,

congrats, after trying various java implementations of semver (and even considering to implement it myself) I found your work. Its the best and most solid implementation by a margin !

I'd like to include this as a dependency with one of my OS work (kontraktor-http). This includes a NPM clone written in java (i'm doing bundling + minification + react-jsx transpilation completely in java, so I don't want force users to install node just to be able to have a ´npm i install react react-dom´).

However LGPL disallows bundling inside a single artifact, so I'd need a artifact on maven.org. I could do this however it would be listed as "de.ruedigermoeller" ..

Assumption on numeric parts being 32-bit integers is insufficient

It is not uncommon to attach timestamps to the "prerelease" part of package version strings. Here is an example -- https://registry.npmjs.org/puppeteer/1.3.0-next.1524774887046

The timestamp is in the unit of microsecond, and hence exceeds the boundary of Integer.MAX_VALUE. Feeding the above example into Version.from() results in this exception:

Caused by: java.lang.NumberFormatException: For input string: "1524774887046"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
	at java.lang.Integer.parseInt(Integer.java:583)
	at java.lang.Integer.parseInt(Integer.java:615)
	at com.github.yuchi.semver.Version.<init>(Version.java:81)
	at com.github.yuchi.semver.Version.<init>(Version.java:32)

Using Long may solve the issue. Or all numeric parts in a version string should stay in string data type.

Was functionality to increment a semantic version planned?

Hello! I stumbled upon this great project today, and was wondering if functionality to increment the semantic version was planned? I understand this isn't a new project, but was just curious.

From npm-semver (commandline utility usage section):

https://docs.npmjs.com/misc/semver#usage

-i --increment [<level>]
        Increment a version by the specified level.  Level can
        be one of: major, minor, patch, premajor, preminor,
        prepatch, or prerelease.  Default level is 'patch'.
        Only one version may be specified.

--preid <identifier>
        Identifier to be used to prefix premajor, preminor,
        prepatch or prerelease version increments.

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.