From 27d5bee878f68624b7317c8ba755ccdafac1ee5f Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Wed, 14 Sep 2011 18:53:30 -0700 Subject: Added support for 2 digits version number. --- api/src/main/java/org/semver/Version.java | 14 ++++++++++---- api/src/test/java/org/semver/VersionTest.java | 7 ++----- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'api') diff --git a/api/src/main/java/org/semver/Version.java b/api/src/main/java/org/semver/Version.java index 417d8b3..1a1b501 100755 --- a/api/src/main/java/org/semver/Version.java +++ b/api/src/main/java/org/semver/Version.java @@ -40,8 +40,9 @@ public final class Version implements Comparable { MAJOR, MINOR, PATCH, SPECIAL; } - private static final String FORMAT = "(\\d)\\.(\\d)\\.(\\d)(?:\\.|-)?([A-Za-z][0-9A-Za-z-]*)?"; + private static final String FORMAT = "(\\d)\\.(\\d)(?:\\.)?(\\d)?(?:\\.|-)?([A-Za-z][0-9A-Za-z-]*)?"; private static final Pattern PATTERN = Pattern.compile(Version.FORMAT); + private static final String SNAPSHOT_VERSION_SUFFIX = "-SNAPSHOT"; private final int major; @@ -85,8 +86,13 @@ public final class Version implements Comparable { final int major = Integer.valueOf(matcher.group(1)); final int minor = Integer.valueOf(matcher.group(2)); - final int patch = Integer.valueOf(matcher.group(3)); - + final int patch; + final String patchMatch = matcher.group(3); + if (patchMatch != null) { + patch = Integer.valueOf(patchMatch); + } else { + patch = 0; + } return new Version(major, minor, patch, matcher.group(4)); } @@ -120,7 +126,7 @@ public final class Version implements Comparable { } public boolean isSnapshot() { - return this.special.endsWith(Version.SNAPSHOT_VERSION_SUFFIX); + return this.special != null && this.special.endsWith(Version.SNAPSHOT_VERSION_SUFFIX); } @Override diff --git a/api/src/test/java/org/semver/VersionTest.java b/api/src/test/java/org/semver/VersionTest.java index 4450b58..8797b22 100755 --- a/api/src/test/java/org/semver/VersionTest.java +++ b/api/src/test/java/org/semver/VersionTest.java @@ -44,12 +44,14 @@ public class VersionTest { @Test public void shouldValidVersionBeParsed() { + Version.parse("1.2"); Version.parse("1.2.3"); Version.parse("1.2.3beta"); Version.parse("1.2.3.DEV"); Version.parse("1.2.3.DEV-SNAPSHOT"); Version.parse("1.2.3-SNAPSHOT"); Version.parse("1.2.3-RC-SNAPSHOT"); + Version.parse("1.2-RC-SNAPSHOT"); } @Test(expected=IllegalArgumentException.class) @@ -64,11 +66,6 @@ public class VersionTest { @Test(expected=IllegalArgumentException.class) public void shouldInvalidVersion3NotBeParsed() { - Version.parse("1.2"); - } - - @Test(expected=IllegalArgumentException.class) - public void shouldInvalidVersion4NotBeParsed() { Version.parse("a.2.3"); } -- cgit v1.2.3