Adapt to SemVer 2.0.0-rc.2
This commit is contained in:
parent
8c6b05f245
commit
5c39ab15d8
|
@ -57,6 +57,14 @@ public class Version implements Comparable<Version> {
|
||||||
SEMVER_PATTERN = Pattern.compile(sb.toString());
|
SEMVER_PATTERN = Pattern.compile(sb.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Version(NormalVersion normal) {
|
||||||
|
this(normal, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
Version(NormalVersion normal, MetadataVersion preRelease) {
|
||||||
|
this(normal, preRelease, null);
|
||||||
|
}
|
||||||
|
|
||||||
Version(
|
Version(
|
||||||
NormalVersion normal,
|
NormalVersion normal,
|
||||||
MetadataVersion preRelease,
|
MetadataVersion preRelease,
|
||||||
|
@ -93,15 +101,36 @@ public class Version implements Comparable<Version> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Version incrementMajorVersion() {
|
public Version incrementMajorVersion() {
|
||||||
return new Version(normal.incrementMajor(), preRelease, build);
|
return new Version(normal.incrementMajor());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Version incrementMajorVersion(String preRelease) {
|
||||||
|
return new Version(
|
||||||
|
normal.incrementMajor(),
|
||||||
|
new MetadataVersion(preRelease)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Version incrementMinorVersion() {
|
public Version incrementMinorVersion() {
|
||||||
return new Version(normal.incrementMinor(), preRelease, build);
|
return new Version(normal.incrementMinor());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Version incrementMinorVersion(String preRelease) {
|
||||||
|
return new Version(
|
||||||
|
normal.incrementMinor(),
|
||||||
|
new MetadataVersion(preRelease)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Version incrementPatchVersion() {
|
public Version incrementPatchVersion() {
|
||||||
return new Version(normal.incrementPatch(), preRelease, build);
|
return new Version(normal.incrementPatch());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Version incrementPatchVersion(String preRelease) {
|
||||||
|
return new Version(
|
||||||
|
normal.incrementPatch(),
|
||||||
|
new MetadataVersion(preRelease)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMajorVersion() {
|
public int getMajorVersion() {
|
||||||
|
@ -124,7 +153,7 @@ public class Version implements Comparable<Version> {
|
||||||
return (preRelease != null) ? preRelease.toString() : "";
|
return (preRelease != null) ? preRelease.toString() : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBuildVersion() {
|
public String getBuildMetadata() {
|
||||||
return (build != null) ? build.toString() : "";
|
return (build != null) ? build.toString() : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +200,7 @@ public class Version implements Comparable<Version> {
|
||||||
sb.append(PRE_RELEASE_PREFIX).append(getPreReleaseVersion());
|
sb.append(PRE_RELEASE_PREFIX).append(getPreReleaseVersion());
|
||||||
}
|
}
|
||||||
if (build != null) {
|
if (build != null) {
|
||||||
sb.append(BUILD_PREFIX).append(getBuildVersion());
|
sb.append(BUILD_PREFIX).append(getBuildMetadata());
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
@ -181,9 +210,6 @@ public class Version implements Comparable<Version> {
|
||||||
int result = normal.compareTo(other.normal);
|
int result = normal.compareTo(other.normal);
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
result = comparePreReleases(other);
|
result = comparePreReleases(other);
|
||||||
if (result == 0) {
|
|
||||||
result = compareBuilds(other);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -201,18 +227,4 @@ public class Version implements Comparable<Version> {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int compareBuilds(Version other) {
|
|
||||||
int result = 0;
|
|
||||||
if (build != null && other.build != null) {
|
|
||||||
result = build.compareTo(other.build);
|
|
||||||
} else if (build == null ^ other.build == null) {
|
|
||||||
/**
|
|
||||||
* Build versions satisfy and have a higher precedence
|
|
||||||
* than the associated normal version. (SemVer p.10)
|
|
||||||
*/
|
|
||||||
result = (build == null) ? -1 : 1;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,22 +54,17 @@ public class VersionTest {
|
||||||
@Test
|
@Test
|
||||||
public void mayHaveBuildFollowingPatchOrPreReleaseAppendedWithPlus() {
|
public void mayHaveBuildFollowingPatchOrPreReleaseAppendedWithPlus() {
|
||||||
Version v = Version.valueOf("1.2.3+build");
|
Version v = Version.valueOf("1.2.3+build");
|
||||||
assertEquals("build", v.getBuildVersion());
|
assertEquals("build", v.getBuildMetadata());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldCompareBuildIfNormalAndPreReleaseAreEqual() {
|
public void shouldIgnoreBuildMetadataWhenDeterminingVersionPrecedence() {
|
||||||
Version v1 = Version.valueOf("1.3.7-beta+build.1");
|
Version v1 = Version.valueOf("1.3.7-beta");
|
||||||
Version v2 = Version.valueOf("1.3.7-beta+build.2");
|
Version v2 = Version.valueOf("1.3.7-beta+build.1");
|
||||||
assertTrue(0 > v1.compareTo(v2));
|
Version v3 = Version.valueOf("1.3.7-beta+build.2");
|
||||||
}
|
assertTrue(0 == v1.compareTo(v2));
|
||||||
|
assertTrue(0 == v1.compareTo(v3));
|
||||||
@Test
|
assertTrue(0 == v2.compareTo(v3));
|
||||||
public void buildShouldHaveHigherPrecedenceThanAssociatedNormal() {
|
|
||||||
Version v1 = Version.valueOf("1.3.7");
|
|
||||||
Version v2 = Version.valueOf("1.3.7+build");
|
|
||||||
assertTrue(0 > v1.compareTo(v2));
|
|
||||||
assertTrue(0 < v2.compareTo(v1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -126,12 +121,7 @@ public class VersionTest {
|
||||||
"1.0.0-beta.2",
|
"1.0.0-beta.2",
|
||||||
"1.0.0-beta.11",
|
"1.0.0-beta.11",
|
||||||
"1.0.0-rc.1",
|
"1.0.0-rc.1",
|
||||||
"1.0.0-rc.1+build.1",
|
|
||||||
"1.0.0",
|
"1.0.0",
|
||||||
"1.0.0+0.3.7",
|
|
||||||
"1.3.7+build",
|
|
||||||
"1.3.7+build.2.b8f12d7",
|
|
||||||
"1.3.7+build.11.e0f985a"
|
|
||||||
};
|
};
|
||||||
for (int i = 1; i < versions.length; i++) {
|
for (int i = 1; i < versions.length; i++) {
|
||||||
Version v1 = Version.valueOf(versions[i-1]);
|
Version v1 = Version.valueOf(versions[i-1]);
|
||||||
|
@ -148,7 +138,7 @@ public class VersionTest {
|
||||||
assertEquals(0, v.getPatchVersion());
|
assertEquals(0, v.getPatchVersion());
|
||||||
assertEquals("1.0.0", v.getNormalVersion());
|
assertEquals("1.0.0", v.getNormalVersion());
|
||||||
assertEquals("rc.1", v.getPreReleaseVersion());
|
assertEquals("rc.1", v.getPreReleaseVersion());
|
||||||
assertEquals("build.1", v.getBuildVersion());
|
assertEquals("build.1", v.getBuildMetadata());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -158,6 +148,13 @@ public class VersionTest {
|
||||||
assertEquals("2.0.0", incrementedMajor.toString());
|
assertEquals("2.0.0", incrementedMajor.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldIncrementMajorVersionWithPreReleaseIfProvided() {
|
||||||
|
Version v = Version.valueOf("1.2.3");
|
||||||
|
Version incrementedMajor = v.incrementMajorVersion("beta");
|
||||||
|
assertEquals("2.0.0-beta", incrementedMajor.toString());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldProvideIncrementMinorVersionMethod() {
|
public void shouldProvideIncrementMinorVersionMethod() {
|
||||||
Version v = Version.valueOf("1.2.3");
|
Version v = Version.valueOf("1.2.3");
|
||||||
|
@ -165,6 +162,13 @@ public class VersionTest {
|
||||||
assertEquals("1.3.0", incrementedMinor.toString());
|
assertEquals("1.3.0", incrementedMinor.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldIncrementMinorVersionWithPreReleaseIfProvided() {
|
||||||
|
Version v = Version.valueOf("1.2.3");
|
||||||
|
Version incrementedMinor = v.incrementMinorVersion("alpha");
|
||||||
|
assertEquals("1.3.0-alpha", incrementedMinor.toString());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldProvideIncrementPatchVersionMethod() {
|
public void shouldProvideIncrementPatchVersionMethod() {
|
||||||
Version v = Version.valueOf("1.2.3");
|
Version v = Version.valueOf("1.2.3");
|
||||||
|
@ -172,6 +176,33 @@ public class VersionTest {
|
||||||
assertEquals("1.2.4", incrementedPatch.toString());
|
assertEquals("1.2.4", incrementedPatch.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldIncrementPatchVersionWithPreReleaseIfProvided() {
|
||||||
|
Version v = Version.valueOf("1.2.3");
|
||||||
|
Version incrementedPatch = v.incrementPatchVersion("rc");
|
||||||
|
assertEquals("1.2.4-rc", incrementedPatch.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldDropBuildMetadataWhenIncrementing() {
|
||||||
|
Version v = Version.valueOf("1.2.3-alpha+build");
|
||||||
|
|
||||||
|
Version major1 = v.incrementMajorVersion();
|
||||||
|
assertEquals("2.0.0", major1.toString());
|
||||||
|
Version major2 = v.incrementMajorVersion("beta");
|
||||||
|
assertEquals("2.0.0-beta", major2.toString());
|
||||||
|
|
||||||
|
Version minor1 = v.incrementMinorVersion();
|
||||||
|
assertEquals("1.3.0", minor1.toString());
|
||||||
|
Version minor2 = v.incrementMinorVersion("beta");
|
||||||
|
assertEquals("1.3.0-beta", minor2.toString());
|
||||||
|
|
||||||
|
Version patch1 = v.incrementPatchVersion();
|
||||||
|
assertEquals("1.2.4", patch1.toString());
|
||||||
|
Version patch2 = v.incrementPatchVersion("beta");
|
||||||
|
assertEquals("1.2.4-beta", patch2.toString());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldBeImmutable() {
|
public void shouldBeImmutable() {
|
||||||
Version version = Version.valueOf("1.2.3");
|
Version version = Version.valueOf("1.2.3");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user