Restoring alpha/beta/rc version semantics (#1112)
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
This commit is contained in:
parent
652cdbd5af
commit
6e199d223b
|
@ -288,4 +288,29 @@ public class LegacyESVersion extends Version {
|
|||
protected int maskId(final int id) {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(major).append('.').append(minor).append('.').append(revision);
|
||||
if (isAlpha()) {
|
||||
sb.append("-alpha");
|
||||
sb.append(build);
|
||||
} else if (isBeta()) {
|
||||
if (major >= 2) {
|
||||
sb.append("-beta");
|
||||
} else {
|
||||
sb.append(".Beta");
|
||||
}
|
||||
sb.append(major < 5 ? build : build-25);
|
||||
} else if (build < 99) {
|
||||
if (major >= 2) {
|
||||
sb.append("-rc");
|
||||
} else {
|
||||
sb.append(".RC");
|
||||
}
|
||||
sb.append(build - 50);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -177,19 +177,35 @@ public class Version implements Comparable<Version>, ToXContentFragment {
|
|||
throw new IllegalArgumentException("illegal version format - snapshot labels are not supported");
|
||||
}
|
||||
String[] parts = version.split("[.-]");
|
||||
// todo: add back optional build number
|
||||
if (parts.length != 3) {
|
||||
throw new IllegalArgumentException("the version needs to contain major, minor, and revision: " + version);
|
||||
if (parts.length < 3 || parts.length > 4) {
|
||||
throw new IllegalArgumentException(
|
||||
"the version needs to contain major, minor, and revision, and optionally the build: " + version);
|
||||
}
|
||||
|
||||
try {
|
||||
final int rawMajor = Integer.parseInt(parts[0]);
|
||||
|
||||
final int betaOffset = 25; // 0 - 24 is taking by alpha builds
|
||||
|
||||
//we reverse the version id calculation based on some assumption as we can't reliably reverse the modulo
|
||||
final int major = rawMajor * 1000000;
|
||||
final int minor = Integer.parseInt(parts[1]) * 10000;
|
||||
final int revision = Integer.parseInt(parts[2]) * 100;
|
||||
int build = 99;
|
||||
if (parts.length == 4) {
|
||||
String buildStr = parts[3];
|
||||
if (buildStr.startsWith("alpha")) {
|
||||
build = Integer.parseInt(buildStr.substring(5));
|
||||
assert build < 25 : "expected a alpha build but " + build + " >= 25";
|
||||
} else if (buildStr.startsWith("Beta") || buildStr.startsWith("beta")) {
|
||||
build = betaOffset + Integer.parseInt(buildStr.substring(4));
|
||||
assert build < 50 : "expected a beta build but " + build + " >= 50";
|
||||
} else if (buildStr.startsWith("RC") || buildStr.startsWith("rc")) {
|
||||
build = Integer.parseInt(buildStr.substring(2)) + 50;
|
||||
} else {
|
||||
throw new IllegalArgumentException("unable to parse version " + version);
|
||||
}
|
||||
}
|
||||
|
||||
return fromId((major + minor + revision + build) ^ MASK);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("unable to parse version " + version, e);
|
||||
|
@ -398,18 +414,10 @@ public class Version implements Comparable<Version>, ToXContentFragment {
|
|||
sb.append("-alpha");
|
||||
sb.append(build);
|
||||
} else if (isBeta()) {
|
||||
if (major >= 2) {
|
||||
sb.append("-beta");
|
||||
} else {
|
||||
sb.append(".Beta");
|
||||
}
|
||||
sb.append(major < 5 ? build : build-25);
|
||||
sb.append("-beta");
|
||||
sb.append(build - 25);
|
||||
} else if (build < 99) {
|
||||
if (major >= 2) {
|
||||
sb.append("-rc");
|
||||
} else {
|
||||
sb.append(".RC");
|
||||
}
|
||||
sb.append("-rc");
|
||||
sb.append(build - 50);
|
||||
}
|
||||
return sb.toString();
|
||||
|
|
|
@ -265,12 +265,36 @@ public class VersionTests extends OpenSearchTestCase {
|
|||
assertEquals("5.0.0-alpha1", LegacyESVersion.fromString("5.0.0-alpha1").toString());
|
||||
}
|
||||
|
||||
public void testIsRc() {
|
||||
assertTrue(LegacyESVersion.fromString("2.0.0-rc1").isRC());
|
||||
assertTrue(LegacyESVersion.fromString("1.0.0.RC1").isRC());
|
||||
assertTrue(Version.fromString("1.0.0-rc1").isRC());
|
||||
assertTrue(Version.fromString("2.0.0.RC1").isRC());
|
||||
|
||||
for (int i = 0 ; i < 25; i++) {
|
||||
assertEquals(LegacyESVersion.fromString("5.0.0-rc" + i).id, LegacyESVersion.fromId(5000000 + i + 50).id);
|
||||
assertEquals("5.0.0-rc" + i, LegacyESVersion.fromId(5000000 + i + 50).toString());
|
||||
|
||||
assertEquals(Version.fromString("1.0.0-rc" + i).id, Version.fromId(135217728 + i + 50).id);
|
||||
assertEquals("1.0.0-rc" + i, Version.fromId(135217728 + i + 50).toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsBeta() {
|
||||
assertTrue(LegacyESVersion.fromString("2.0.0-beta1").isBeta());
|
||||
assertTrue(LegacyESVersion.fromString("1.0.0.Beta1").isBeta());
|
||||
assertTrue(LegacyESVersion.fromString("0.90.0.Beta1").isBeta());
|
||||
}
|
||||
assertTrue(Version.fromString("1.0.0.Beta1").isBeta());
|
||||
assertTrue(Version.fromString("2.0.0.beta1").isBeta());
|
||||
|
||||
for (int i = 0 ; i < 25; i++) {
|
||||
assertEquals(LegacyESVersion.fromString("5.0.0-beta" + i).id, LegacyESVersion.fromId(5000000 + i + 25).id);
|
||||
assertEquals("5.0.0-beta" + i, LegacyESVersion.fromId(5000000 + i + 25).toString());
|
||||
|
||||
assertEquals(Version.fromString("1.0.0-beta" + i).id, Version.fromId(135217728 + i + 25).id);
|
||||
assertEquals("1.0.0-beta" + i, Version.fromId(135217728 + i + 25).toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsAlpha() {
|
||||
assertTrue(new LegacyESVersion(5000001, org.apache.lucene.util.Version.LUCENE_7_0_0).isAlpha());
|
||||
|
@ -279,15 +303,16 @@ public class VersionTests extends OpenSearchTestCase {
|
|||
assertTrue(LegacyESVersion.fromString("5.0.0-alpha14").isAlpha());
|
||||
assertEquals(5000014, LegacyESVersion.fromString("5.0.0-alpha14").id);
|
||||
assertTrue(LegacyESVersion.fromId(5000015).isAlpha());
|
||||
|
||||
assertEquals(135217742, Version.fromString("1.0.0-alpha14").id);
|
||||
assertTrue(Version.fromString("1.0.0-alpha14").isAlpha());
|
||||
|
||||
for (int i = 0 ; i < 25; i++) {
|
||||
assertEquals(LegacyESVersion.fromString("5.0.0-alpha" + i).id, LegacyESVersion.fromId(5000000 + i).id);
|
||||
assertEquals("5.0.0-alpha" + i, LegacyESVersion.fromId(5000000 + i).toString());
|
||||
}
|
||||
|
||||
for (int i = 0 ; i < 25; i++) {
|
||||
assertEquals(LegacyESVersion.fromString("5.0.0-beta" + i).id, LegacyESVersion.fromId(5000000 + i + 25).id);
|
||||
assertEquals("5.0.0-beta" + i, LegacyESVersion.fromId(5000000 + i + 25).toString());
|
||||
|
||||
assertEquals(Version.fromString("1.0.0-alpha" + i).id, Version.fromId(135217728 + i).id);
|
||||
assertEquals("1.0.0-alpha" + i, Version.fromId(135217728 + i).toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue