Fixed version scheme

- Lowercase `beta` and `rc`
- use `-beta` and `-rc` suffixes instead of `.beta`and `.rc`

Original commit: elastic/x-pack-elasticsearch@74860d8252
This commit is contained in:
uboness 2015-06-22 13:05:44 +02:00
parent a79557c0bc
commit 5daddf3fc1
2 changed files with 59 additions and 5 deletions

View File

@ -62,7 +62,7 @@ public class LicenseVersion implements Serializable {
return LicenseVersion.CURRENT;
}
String[] parts = version.split("\\.");
String[] parts = version.split("\\.|\\-");
if (parts.length < 3 || parts.length > 4) {
throw new IllegalArgumentException("the version needs to contain major, minor and revision, and optionally the build");
}
@ -76,10 +76,10 @@ public class LicenseVersion implements Serializable {
int build = 99;
if (parts.length == 4) {
String buildStr = parts[3];
if (buildStr.startsWith("Beta")) {
if (buildStr.startsWith("beta")) {
build = Integer.parseInt(buildStr.substring(4));
}
if (buildStr.startsWith("RC")) {
if (buildStr.startsWith("rc")) {
build = Integer.parseInt(buildStr.substring(2)) + 50;
}
}
@ -155,9 +155,9 @@ public class LicenseVersion implements Serializable {
StringBuilder sb = new StringBuilder();
sb.append(major).append('.').append(minor).append('.').append(revision);
if (build < 50) {
sb.append(".Beta").append(build);
sb.append("-beta").append(build);
} else if (build < 99) {
sb.append(".RC").append(build - 50);
sb.append("-rc").append(build - 50);
}
return sb.toString();
}

View File

@ -0,0 +1,54 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.license.plugin;
import org.elasticsearch.test.ElasticsearchTestCase;
import org.junit.Test;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
/**
*
*/
public class LicenseVersionTests extends ElasticsearchTestCase {
@Test
public void testStrings() throws Exception {
boolean beta = randomBoolean();
int buildNumber = beta ? randomIntBetween(0, 49) : randomIntBetween(0, 48);
int major = randomIntBetween(0, 20);
int minor = randomIntBetween(0, 20);
int revision = randomIntBetween(0, 20);
String build = buildNumber == 0 ? "" :
beta ? "-beta" + buildNumber : "-rc" + buildNumber;
String versionName = new StringBuilder()
.append(major)
.append(".").append(minor)
.append(".").append(revision)
.append(build).toString();
LicenseVersion version = LicenseVersion.fromString(versionName);
logger.info("version: {}", versionName);
assertThat(version.major, is((byte) major));
assertThat(version.minor, is((byte) minor));
assertThat(version.revision, is((byte) revision));
if (buildNumber == 0) {
assertThat(version.build, is((byte) 99));
} else if (beta) {
assertThat(version.build, is((byte) buildNumber));
} else {
assertThat(version.build, is((byte) (buildNumber + 50)));
}
assertThat(version.number(), equalTo(versionName));
}
}