Commit b5553734 authored by GregDThomas's avatar GregDThomas Committed by daryl herzmann

Add support for SNAPSHOT style versioning now Maven is a first class build tool. (#958)

parent 7e2f1fc5
......@@ -28,6 +28,7 @@ import java.util.regex.Pattern;
public final class Version implements Comparable<Version> {
private static final Pattern PATTERN = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)(?:\\s+(\\w+))?(?:\\s+(\\d+))?");
private static final Pattern SNAPSHOT_PATTERN = Pattern.compile("(?i)(\\d+)\\.(\\d+)\\.(\\d+)(?:\\.(\\d+))?-SNAPSHOT");
/**
* The major number (ie 1.x.x).
......@@ -111,17 +112,23 @@ public final class Version implements Comparable<Version> {
} else {
this.statusVersion = -1;
}
} else {
this.major = this.minor = this.micro = 0;
this.statusVersion = -1;
this.status = ReleaseStatus.Release;
return;
}
final Matcher snapshotMatcher = SNAPSHOT_PATTERN.matcher(source);
if (snapshotMatcher.matches()) {
major = Integer.parseInt(snapshotMatcher.group(1));
minor = Integer.parseInt(snapshotMatcher.group(2));
micro = Integer.parseInt(snapshotMatcher.group(3));
status = ReleaseStatus.Snapshot;
final String statusVersionString = snapshotMatcher.group(4);
statusVersion = statusVersionString == null ? -1 : Integer.parseInt(statusVersionString);
return;
}
}
} else {
this.major = this.minor = this.micro = 0;
this.statusVersion = -1;
this.status = ReleaseStatus.Release;
}
}
/**
* Returns the version number of this instance of Openfire as a
......@@ -133,7 +140,12 @@ public final class Version implements Comparable<Version> {
if (versionString == null) {
StringBuilder sb = new StringBuilder();
sb.append(major).append('.').append(minor).append('.').append(micro);
if (status != ReleaseStatus.Release || statusVersion != -1) {
if(status == ReleaseStatus.Snapshot) {
if (statusVersion >= 0) {
sb.append('.').append(statusVersion);
}
sb.append("-SNAPSHOT");
} else if (status != ReleaseStatus.Release || statusVersion != -1) {
sb.append(' ').append(status);
if (statusVersion >= 0) {
sb.append(' ').append(statusVersion);
......@@ -196,7 +208,7 @@ public final class Version implements Comparable<Version> {
* are indicated by type safe enum constants.
*/
public enum ReleaseStatus {
Release("Release"), Release_Candidate("RC"), Beta("Beta"), Alpha("Alpha");
Release("Release"), Release_Candidate("RC"), Beta("Beta"), Alpha("Alpha"), Snapshot("Snapshot");
private String status;
......
package org.jivesoftware.util;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import org.jivesoftware.util.Version.ReleaseStatus;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
public class VersionTest {
@Test
......@@ -100,4 +102,32 @@ public class VersionTest {
assertEquals(version1, version2);
assertTrue((version1.compareTo(version2) == 0) == version1.equals(version2));
}
@Test
public void willVersionAThreeDigitSnapshot() throws Exception {
final String versionString = "1.2.3-SNAPSHOT";
Version test = new Version(versionString);
assertThat(test.getMajor(), is(1));
assertThat(test.getMinor(), is(2));
assertThat(test.getMicro(), is(3));
assertThat(test.getStatusVersion(), is(-1));
assertThat(test.getStatus(), is(ReleaseStatus.Snapshot));
assertThat(test.getVersionString(),is(versionString));
}
@Test
public void willVersionAFourDigitSnapshot() throws Exception {
final String versionString = "1.2.3.4-snapshot";
Version test = new Version(versionString);
assertThat(test.getMajor(), is(1));
assertThat(test.getMinor(), is(2));
assertThat(test.getMicro(), is(3));
assertThat(test.getStatusVersion(), is(4));
assertThat(test.getStatus(), is(ReleaseStatus.Snapshot));
assertThat(test.getVersionString(),is(versionString.toUpperCase()));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment