Remove SNAPSHOT from versions in plugin descriptors

We removed leniencey from version parsing which caught problems with
-SNAPSHOT suffixes on plugin properies. This commit removes the -SNAPSHOT
from both es and the extension version and adds tests to ensure we can
parse older versions that allowed -SNAPSHOT in BWC way.
This commit is contained in:
Simon Willnauer 2016-03-07 17:41:38 +01:00
parent 887b69b58b
commit 9cbc602487
3 changed files with 22 additions and 2 deletions

View File

@ -68,11 +68,17 @@ class PluginPropertiesTask extends Copy {
}
Map generateSubstitutions() {
def stringSnap = { version ->
if (version.endsWith("-SNAPSHOT")) {
return version.substring(0, version.length() - 9)
}
return version
}
return [
'name': extension.name,
'description': extension.description,
'version': extension.version,
'elasticsearchVersion': VersionProperties.elasticsearch,
'version': stringSnap(extension.version),
'elasticsearchVersion': stringSnap(VersionProperties.elasticsearch),
'javaVersion': project.targetCompatibility as String,
'isolated': extension.isolated as String,
'classname': extension.classname

View File

@ -137,6 +137,10 @@ public class Version {
if (!Strings.hasLength(version)) {
return Version.CURRENT;
}
final boolean snapshot; // this is some BWC for 2.x and before indices
if (snapshot = version.endsWith("-SNAPSHOT")) {
version = version.substring(0, version.length() - 9);
}
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: " + version);
@ -144,6 +148,9 @@ public class Version {
try {
final int rawMajor = Integer.parseInt(parts[0]);
if (rawMajor >= 5 && snapshot) { // we don't support snapshot as part of the version here anymore
throw new IllegalArgumentException("illegal version format - snapshots are only supported until version 2.x");
}
final int betaOffset = rawMajor < 5 ? 0 : 25;
//we reverse the version id calculation based on some assumption as we can't reliably reverse the modulo
final int major = rawMajor * 1000000;

View File

@ -198,6 +198,13 @@ public class VersionTests extends ESTestCase {
expectThrows(IllegalArgumentException.class, () -> {
Version.fromString("5.0.0-alph2");
});
assertSame(Version.CURRENT, Version.fromString(Version.CURRENT.toString()));
assertSame(Version.fromString("2.0.0-SNAPSHOT"), Version.fromString("2.0.0"));
expectThrows(IllegalArgumentException.class, () -> {
Version.fromString("5.0.0-SNAPSHOT");
});
}
public void testParseLenient() {