zafarkhaja / jsemver

Java implementation of the SemVer Specification
MIT License
429 stars 82 forks source link

Support for System.getProperty("java.version") #37

Closed tresf closed 7 years ago

tresf commented 7 years ago

Java's own internal version scheme is: 1.8.0_121

Version v = Version.valueOf(System.getProperty("java.version"));

However when attempting to parse Java's own version information the following exception is raised.

Caused by: Unexpected character 'ILLEGAL(_)' at position '5', expecting '[HYPHEN, PLUS, EOI]'
    at com.github.zafarkhaja.semver.VersionParser.consumeNextCharacter(VersionParser.java:516)
    at com.github.zafarkhaja.semver.VersionParser.parseValidSemVer(VersionParser.java:259)
    at com.github.zafarkhaja.semver.VersionParser.parseValidSemVer(VersionParser.java:195)
    at com.github.zafarkhaja.semver.Version.valueOf(Version.java:265)

I've tried replacing the underscore with a period and it raises a similar error: Unexpected character 'DOT(.)' at position '5', expecting '[HYPHEN, PLUS, EOI]'

This seems like the most basic use-case inspired by a very simple Oracle version parsing. Am I using the library wrong, or is Oracle's own format not supported by this library?

The use-case is to test for a specific update level inside Java (e.g. u121 vs u141).

tresf commented 7 years ago

Closing this out since turning Java's version string into a valid SemVer will fix it.

The following snippet will fix Java version parsing...

This will turn 1.8.0_42 to 1.8.0-42 and fix the parsing error...

- Version v = Version.valueOf(System.getProperty("java.version"));
+ Version v = Version.valueOf(System.getProperty("java.version").replaceFirst("_", "-"));