Drop current from the list of released versions (#25187)

It hasn't been released....
This commit is contained in:
Nik Everett 2017-07-07 15:59:57 -04:00 committed by GitHub
parent 93311ab717
commit 794257c421
2 changed files with 40 additions and 34 deletions

View File

@ -31,7 +31,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Random;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.Collections.unmodifiableList;
@ -58,10 +57,10 @@ public class VersionUtils {
if (field.getType() != Version.class) {
continue;
}
assert field.getName().matches("(V(_\\d+)+(_(alpha|beta|rc)\\d+)?|CURRENT)") : field.getName();
if ("CURRENT".equals(field.getName())) {
continue;
}
assert field.getName().matches("V(_\\d+)+(_(alpha|beta|rc)\\d+)?") : field.getName();
try {
versions.add(((Version) field.get(null)));
} catch (final IllegalAccessException e) {
@ -69,29 +68,28 @@ public class VersionUtils {
}
}
Collections.sort(versions);
assert versions.get(versions.size() - 1).equals(current) : "The highest version must be the current one "
Version last = versions.remove(versions.size() - 1);
assert last.equals(current) : "The highest version must be the current one "
+ "but was [" + versions.get(versions.size() - 1) + "] and current was [" + current + "]";
if (current.revision != 0) {
/* If we are in a stable branch there should be no unreleased version constants
* because we don't expect to release any new versions in older branches. If there
* are extra constants then gradle will yell about it. */
return new Tuple<>(unmodifiableList(versions), emptyList());
return new Tuple<>(unmodifiableList(versions), singletonList(current));
}
/* If we are on a patch release then we know that at least the version before the
* current one is unreleased. If it is released then gradle would be complaining. */
int unreleasedIndex = versions.size() - 2;
int unreleasedIndex = versions.size() - 1;
while (true) {
if (unreleasedIndex < 0) {
throw new IllegalArgumentException("Couldn't find first non-alpha release");
}
/* Technically we don't support backwards compatiblity for alphas, betas,
* and rcs. But the testing infrastructure requires that we act as though we
* do. This is a difference between the gradle and Java logic but should be
* fairly safe as it is errs on us being more compatible rather than less....
* Anyway, the upshot is that we never declare alphas as unreleased, no
* matter where they are in the list. */
/* We don't support backwards compatibility for alphas, betas, and rcs. But
* they were released so we add them to the released list. Usually this doesn't
* matter to consumers, but consumers that do care should filter non-release
* versions. */
if (versions.get(unreleasedIndex).isRelease()) {
break;
}
@ -104,9 +102,9 @@ public class VersionUtils {
* that there is yet another unreleased version before that. */
unreleasedIndex--;
Version earlierUnreleased = versions.remove(unreleasedIndex);
return new Tuple<>(unmodifiableList(versions), unmodifiableList(Arrays.asList(earlierUnreleased, unreleased)));
return new Tuple<>(unmodifiableList(versions), unmodifiableList(Arrays.asList(earlierUnreleased, unreleased, current)));
}
return new Tuple<>(unmodifiableList(versions), singletonList(unreleased));
return new Tuple<>(unmodifiableList(versions), unmodifiableList(Arrays.asList(unreleased, current)));
}
private static final List<Version> RELEASED_VERSIONS;
@ -149,9 +147,13 @@ public class VersionUtils {
* Get the released version before {@code version}.
*/
public static Version getPreviousVersion(Version version) {
int index = RELEASED_VERSIONS.indexOf(version);
assert index > 0;
return RELEASED_VERSIONS.get(index - 1);
for (int i = RELEASED_VERSIONS.size() - 1; i >= 0; i--) {
Version v = RELEASED_VERSIONS.get(i);
if (v.before(version)) {
return v;
}
}
throw new IllegalArgumentException("couldn't find any released versions before [" + version + "]");
}
/**
@ -168,12 +170,13 @@ public class VersionUtils {
* where the minor version is less than the currents minor version.
*/
public static Version getPreviousMinorVersion() {
Version version = Version.CURRENT;
do {
version = getPreviousVersion(version);
assert version.before(Version.CURRENT);
} while (version.minor == Version.CURRENT.minor);
return version;
for (int i = RELEASED_VERSIONS.size() - 1; i >= 0; i--) {
Version v = RELEASED_VERSIONS.get(i);
if (v.minor < Version.CURRENT.minor || v.major < Version.CURRENT.major) {
return v;
}
}
throw new IllegalArgumentException("couldn't find any released versions of the minor before [" + Version.CURRENT + "]");
}
/** Returns the oldest released {@link Version} */

View File

@ -25,7 +25,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@ -109,8 +108,8 @@ public class VersionUtilsTests extends ESTestCase {
List<Version> released = t.v1();
List<Version> unreleased = t.v2();
assertEquals(Arrays.asList(TestReleaseBranch.V_5_3_0, TestReleaseBranch.V_5_3_1, TestReleaseBranch.V_5_3_2,
TestReleaseBranch.V_5_4_0, TestReleaseBranch.V_5_4_1), released);
assertEquals(emptyList(), unreleased);
TestReleaseBranch.V_5_4_0), released);
assertEquals(singletonList(TestReleaseBranch.V_5_4_1), unreleased);
}
static class TestStableBranch {
@ -125,10 +124,8 @@ public class VersionUtilsTests extends ESTestCase {
TestStableBranch.class);
List<Version> released = t.v1();
List<Version> unreleased = t.v2();
assertEquals(
Arrays.asList(TestStableBranch.V_5_3_0, TestStableBranch.V_5_3_1, TestStableBranch.V_5_4_0),
released);
assertEquals(singletonList(TestStableBranch.V_5_3_2), unreleased);
assertEquals(Arrays.asList(TestStableBranch.V_5_3_0, TestStableBranch.V_5_3_1), released);
assertEquals(Arrays.asList(TestStableBranch.V_5_3_2, TestStableBranch.V_5_4_0), unreleased);
}
static class TestStableBranchBehindStableBranch {
@ -144,9 +141,9 @@ public class VersionUtilsTests extends ESTestCase {
TestStableBranchBehindStableBranch.class);
List<Version> released = t.v1();
List<Version> unreleased = t.v2();
assertEquals(Arrays.asList(TestStableBranchBehindStableBranch.V_5_3_0, TestStableBranchBehindStableBranch.V_5_3_1,
TestStableBranchBehindStableBranch.V_5_5_0), released);
assertEquals(Arrays.asList(TestStableBranchBehindStableBranch.V_5_3_2, Version.V_5_4_0), unreleased);
assertEquals(Arrays.asList(TestStableBranchBehindStableBranch.V_5_3_0, TestStableBranchBehindStableBranch.V_5_3_1), released);
assertEquals(Arrays.asList(TestStableBranchBehindStableBranch.V_5_3_2, TestStableBranchBehindStableBranch.V_5_4_0,
TestStableBranchBehindStableBranch.V_5_5_0), unreleased);
}
static class TestUnstableBranch {
@ -166,8 +163,8 @@ public class VersionUtilsTests extends ESTestCase {
List<Version> released = t.v1();
List<Version> unreleased = t.v2();
assertEquals(Arrays.asList(TestUnstableBranch.V_5_3_0, TestUnstableBranch.V_5_3_1,
TestUnstableBranch.V_6_0_0_alpha1, TestUnstableBranch.V_6_0_0_alpha2, TestUnstableBranch.V_6_0_0_alpha3), released);
assertEquals(Arrays.asList(TestUnstableBranch.V_5_3_2, TestUnstableBranch.V_5_4_0), unreleased);
TestUnstableBranch.V_6_0_0_alpha1, TestUnstableBranch.V_6_0_0_alpha2), released);
assertEquals(Arrays.asList(TestUnstableBranch.V_5_3_2, TestUnstableBranch.V_5_4_0, TestUnstableBranch.V_6_0_0_alpha3), unreleased);
}
/**
@ -190,6 +187,9 @@ public class VersionUtilsTests extends ESTestCase {
assertEquals(releasedIndexCompatible, indexCompatible.released);
List<String> unreleasedIndexCompatible = VersionUtils.allUnreleasedVersions().stream()
/* Gradle skips the current version because being backwards compatible
* with yourself is implied. Java lists the version because it is useful. */
.filter(v -> v != Version.CURRENT)
.map(Object::toString)
.collect(toList());
assertEquals(unreleasedIndexCompatible, indexCompatible.unreleased);
@ -212,6 +212,9 @@ public class VersionUtilsTests extends ESTestCase {
assertEquals(releasedWireCompatible, wireCompatible.released);
List<String> unreleasedWireCompatible = VersionUtils.allUnreleasedVersions().stream()
/* Gradle skips the current version because being backwards compatible
* with yourself is implied. Java lists the version because it is useful. */
.filter(v -> v != Version.CURRENT)
.filter(v -> v.onOrAfter(minimumCompatibleVersion))
.map(Object::toString)
.collect(toList());