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

View File

@ -25,7 +25,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList; import static java.util.Collections.singletonList;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo;
@ -109,8 +108,8 @@ public class VersionUtilsTests extends ESTestCase {
List<Version> released = t.v1(); List<Version> released = t.v1();
List<Version> unreleased = t.v2(); List<Version> unreleased = t.v2();
assertEquals(Arrays.asList(TestReleaseBranch.V_5_3_0, TestReleaseBranch.V_5_3_1, TestReleaseBranch.V_5_3_2, 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); TestReleaseBranch.V_5_4_0), released);
assertEquals(emptyList(), unreleased); assertEquals(singletonList(TestReleaseBranch.V_5_4_1), unreleased);
} }
static class TestStableBranch { static class TestStableBranch {
@ -125,10 +124,8 @@ public class VersionUtilsTests extends ESTestCase {
TestStableBranch.class); TestStableBranch.class);
List<Version> released = t.v1(); List<Version> released = t.v1();
List<Version> unreleased = t.v2(); List<Version> unreleased = t.v2();
assertEquals( assertEquals(Arrays.asList(TestStableBranch.V_5_3_0, TestStableBranch.V_5_3_1), released);
Arrays.asList(TestStableBranch.V_5_3_0, TestStableBranch.V_5_3_1, TestStableBranch.V_5_4_0), assertEquals(Arrays.asList(TestStableBranch.V_5_3_2, TestStableBranch.V_5_4_0), unreleased);
released);
assertEquals(singletonList(TestStableBranch.V_5_3_2), unreleased);
} }
static class TestStableBranchBehindStableBranch { static class TestStableBranchBehindStableBranch {
@ -144,9 +141,9 @@ public class VersionUtilsTests extends ESTestCase {
TestStableBranchBehindStableBranch.class); TestStableBranchBehindStableBranch.class);
List<Version> released = t.v1(); List<Version> released = t.v1();
List<Version> unreleased = t.v2(); List<Version> unreleased = t.v2();
assertEquals(Arrays.asList(TestStableBranchBehindStableBranch.V_5_3_0, TestStableBranchBehindStableBranch.V_5_3_1, assertEquals(Arrays.asList(TestStableBranchBehindStableBranch.V_5_3_0, TestStableBranchBehindStableBranch.V_5_3_1), released);
TestStableBranchBehindStableBranch.V_5_5_0), released); assertEquals(Arrays.asList(TestStableBranchBehindStableBranch.V_5_3_2, TestStableBranchBehindStableBranch.V_5_4_0,
assertEquals(Arrays.asList(TestStableBranchBehindStableBranch.V_5_3_2, Version.V_5_4_0), unreleased); TestStableBranchBehindStableBranch.V_5_5_0), unreleased);
} }
static class TestUnstableBranch { static class TestUnstableBranch {
@ -166,8 +163,8 @@ public class VersionUtilsTests extends ESTestCase {
List<Version> released = t.v1(); List<Version> released = t.v1();
List<Version> unreleased = t.v2(); List<Version> unreleased = t.v2();
assertEquals(Arrays.asList(TestUnstableBranch.V_5_3_0, TestUnstableBranch.V_5_3_1, 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); 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), unreleased); 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); assertEquals(releasedIndexCompatible, indexCompatible.released);
List<String> unreleasedIndexCompatible = VersionUtils.allUnreleasedVersions().stream() 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) .map(Object::toString)
.collect(toList()); .collect(toList());
assertEquals(unreleasedIndexCompatible, indexCompatible.unreleased); assertEquals(unreleasedIndexCompatible, indexCompatible.unreleased);
@ -212,6 +212,9 @@ public class VersionUtilsTests extends ESTestCase {
assertEquals(releasedWireCompatible, wireCompatible.released); assertEquals(releasedWireCompatible, wireCompatible.released);
List<String> unreleasedWireCompatible = VersionUtils.allUnreleasedVersions().stream() 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)) .filter(v -> v.onOrAfter(minimumCompatibleVersion))
.map(Object::toString) .map(Object::toString)
.collect(toList()); .collect(toList());