aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorJulien Eluard <[email protected]>2011-09-14 18:53:30 -0700
committerJulien Eluard <[email protected]>2011-09-14 18:53:30 -0700
commit27d5bee878f68624b7317c8ba755ccdafac1ee5f (patch)
tree2946ea4054a83a3370bea267666b1a01b3535483 /api
parent1ce9a15183a3072f408a43225436ba973c74e71c (diff)
Added support for 2 digits version number.
Diffstat (limited to 'api')
-rwxr-xr-xapi/src/main/java/org/semver/Version.java14
-rwxr-xr-xapi/src/test/java/org/semver/VersionTest.java7
2 files changed, 12 insertions, 9 deletions
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<Version> {
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<Version> {
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<Version> {
}
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");
}