Explorar o código

Remove reading Lucene version from bwc versions build logic (#94917)

Version.java currently contains mappings to the Lucene version for each
Elasticsearch version. The only use of this in the build logic is for
filtering based on index compatibility. However, that compatibility can
be inferred based on the Elasticsearch major version since there is a
one to one mapping between Elasticsearch major and Lucene major. This
commit removes Lucene version extraction from the build bwc logic.
Ryan Ernst %!s(int64=2) %!d(string=hai) anos
pai
achega
0b32530c11

+ 23 - 42
build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/BwcVersions.java

@@ -65,20 +65,20 @@ import static java.util.Collections.unmodifiableList;
 public class BwcVersions {
 
     private static final Pattern LINE_PATTERN = Pattern.compile(
-        "\\W+public static final Version V_(\\d+)_(\\d+)_(\\d+)(_alpha\\d+|_beta\\d+|_rc\\d+)? .*?LUCENE_(\\d+)_(\\d+)_(\\d+)\\);"
+        "\\W+public static final Version V_(\\d+)_(\\d+)_(\\d+)(_alpha\\d+|_beta\\d+|_rc\\d+)?.*\\);"
     );
     private static final Version MINIMUM_WIRE_COMPATIBLE_VERSION = Version.fromString("7.17.0");
     private static final String GLIBC_VERSION_ENV_VAR = "GLIBC_VERSION";
 
-    private final VersionPair currentVersion;
-    private final List<VersionPair> versions;
+    private final Version currentVersion;
+    private final List<Version> versions;
     private final Map<Version, UnreleasedVersionInfo> unreleased;
 
     public BwcVersions(List<String> versionLines) {
         this(versionLines, Version.fromString(VersionProperties.getElasticsearch()));
     }
 
-    public BwcVersions(Version currentVersionProperty, List<VersionPair> allVersions) {
+    public BwcVersions(Version currentVersionProperty, List<Version> allVersions) {
         if (allVersions.isEmpty()) {
             throw new IllegalArgumentException("Could not parse any versions");
         }
@@ -95,26 +95,21 @@ public class BwcVersions {
         this(currentVersionProperty, parseVersionLines(versionLines));
     }
 
-    private static List<VersionPair> parseVersionLines(List<String> versionLines) {
+    private static List<Version> parseVersionLines(List<String> versionLines) {
         return versionLines.stream()
             .map(LINE_PATTERN::matcher)
             .filter(Matcher::matches)
-            .map(
-                match -> new VersionPair(
-                    new Version(Integer.parseInt(match.group(1)), Integer.parseInt(match.group(2)), Integer.parseInt(match.group(3))),
-                    new Version(Integer.parseInt(match.group(5)), Integer.parseInt(match.group(6)), Integer.parseInt(match.group(7)))
-                )
-            )
+            .map(match -> new Version(Integer.parseInt(match.group(1)), Integer.parseInt(match.group(2)), Integer.parseInt(match.group(3))))
             .sorted()
             .toList();
     }
 
     private void assertCurrentVersionMatchesParsed(Version currentVersionProperty) {
-        if (currentVersionProperty.equals(currentVersion.elasticsearch) == false) {
+        if (currentVersionProperty.equals(currentVersion) == false) {
             throw new IllegalStateException(
                 "Parsed versions latest version does not match the one configured in build properties. "
                     + "Parsed latest version is "
-                    + currentVersion.elasticsearch
+                    + currentVersion
                     + " but the build has "
                     + currentVersionProperty
             );
@@ -130,12 +125,12 @@ public class BwcVersions {
 
     public void forPreviousUnreleased(Consumer<UnreleasedVersionInfo> consumer) {
         filterSupportedVersions(
-            getUnreleased().stream().filter(version -> version.equals(currentVersion.elasticsearch) == false).collect(Collectors.toList())
+            getUnreleased().stream().filter(version -> version.equals(currentVersion) == false).collect(Collectors.toList())
         ).stream().map(unreleased::get).forEach(consumer);
     }
 
     private String getBranchFor(Version version) {
-        if (version.equals(currentVersion.elasticsearch)) {
+        if (version.equals(currentVersion)) {
             // Just assume the current branch is 'main'. It's actually not important, we never check out the current branch.
             return "main";
         } else {
@@ -144,31 +139,31 @@ public class BwcVersions {
     }
 
     private Map<Version, UnreleasedVersionInfo> computeUnreleased() {
-        Set<VersionPair> unreleased = new TreeSet<>();
+        Set<Version> unreleased = new TreeSet<>();
         // The current version is being worked, is always unreleased
         unreleased.add(currentVersion);
         // Recurse for all unreleased versions starting from the current version
         addUnreleased(unreleased, currentVersion, 0);
 
         // Grab the latest version from the previous major if necessary as well, this is going to be a maintenance release
-        VersionPair maintenance = versions.stream()
-            .filter(v -> v.elasticsearch.getMajor() == currentVersion.elasticsearch.getMajor() - 1)
+        Version maintenance = versions.stream()
+            .filter(v -> v.getMajor() == currentVersion.getMajor() - 1)
             .sorted(Comparator.reverseOrder())
             .findFirst()
             .orElseThrow();
         // This is considered the maintenance release only if we haven't yet encountered it
         boolean hasMaintenanceRelease = unreleased.add(maintenance);
 
-        List<VersionPair> unreleasedList = unreleased.stream().sorted(Comparator.reverseOrder()).toList();
+        List<Version> unreleasedList = unreleased.stream().sorted(Comparator.reverseOrder()).toList();
         Map<Version, UnreleasedVersionInfo> result = new TreeMap<>();
         for (int i = 0; i < unreleasedList.size(); i++) {
-            Version esVersion = unreleasedList.get(i).elasticsearch;
+            Version esVersion = unreleasedList.get(i);
             // This is either a new minor or staged release
-            if (currentVersion.elasticsearch.equals(esVersion)) {
+            if (currentVersion.equals(esVersion)) {
                 result.put(esVersion, new UnreleasedVersionInfo(esVersion, getBranchFor(esVersion), ":distribution"));
             } else if (esVersion.getRevision() == 0) {
                 // If there are two upcoming unreleased minors then this one is the new minor
-                if (unreleasedList.get(i + 1).elasticsearch.getRevision() == 0) {
+                if (unreleasedList.get(i + 1).getRevision() == 0) {
                     result.put(esVersion, new UnreleasedVersionInfo(esVersion, getBranchFor(esVersion), ":distribution:bwc:minor"));
                 } else {
                     result.put(esVersion, new UnreleasedVersionInfo(esVersion, getBranchFor(esVersion), ":distribution:bwc:staged"));
@@ -190,10 +185,10 @@ public class BwcVersions {
         return unreleased.keySet().stream().sorted().toList();
     }
 
-    private void addUnreleased(Set<VersionPair> unreleased, VersionPair current, int index) {
-        if (current.elasticsearch.getRevision() == 0) {
+    private void addUnreleased(Set<Version> unreleased, Version current, int index) {
+        if (current.getRevision() == 0) {
             // If the current version is a new minor, the next version is also unreleased
-            VersionPair next = versions.get(versions.size() - (index + 2));
+            Version next = versions.get(versions.size() - (index + 2));
             unreleased.add(next);
 
             // Keep looking through versions until we find the end of unreleased versions
@@ -228,7 +223,7 @@ public class BwcVersions {
     }
 
     private List<Version> getReleased() {
-        return versions.stream().map(v -> v.elasticsearch).filter(v -> unreleased.containsKey(v) == false).toList();
+        return versions.stream().filter(v -> unreleased.containsKey(v) == false).toList();
     }
 
     /**
@@ -242,10 +237,7 @@ public class BwcVersions {
      * Return all versions of Elasticsearch which are index compatible with the current version.
      */
     public List<Version> getAllIndexCompatible() {
-        return versions.stream()
-            .filter(v -> v.lucene.getMajor() >= (currentVersion.lucene.getMajor() - 1))
-            .map(v -> v.elasticsearch)
-            .toList();
+        return versions.stream().filter(v -> v.getMajor() >= (currentVersion.getMajor() - 1)).toList();
     }
 
     public void withIndexCompatible(BiConsumer<Version, String> versionAction) {
@@ -257,9 +249,7 @@ public class BwcVersions {
     }
 
     public List<Version> getWireCompatible() {
-        return filterSupportedVersions(
-            versions.stream().map(v -> v.elasticsearch).filter(v -> v.compareTo(MINIMUM_WIRE_COMPATIBLE_VERSION) >= 0).toList()
-        );
+        return filterSupportedVersions(versions.stream().filter(v -> v.compareTo(MINIMUM_WIRE_COMPATIBLE_VERSION) >= 0).toList());
     }
 
     public void withWireCompatible(BiConsumer<Version, String> versionAction) {
@@ -302,15 +292,6 @@ public class BwcVersions {
 
     public record UnreleasedVersionInfo(Version version, String branch, String gradleProjectPath) {}
 
-    public record VersionPair(Version elasticsearch, Version lucene) implements Comparable<VersionPair> {
-
-        @Override
-        public int compareTo(VersionPair o) {
-            // For ordering purposes, sort by Elasticsearch version
-            return this.elasticsearch.compareTo(o.elasticsearch);
-        }
-    }
-
     /**
      * Determine whether the given version of Elasticsearch is compatible with ML features on the host system.
      *

+ 9 - 10
build-tools-internal/src/test/java/org/elasticsearch/gradle/AbstractDistributionDownloadPluginTests.java

@@ -9,7 +9,6 @@
 package org.elasticsearch.gradle;
 
 import org.elasticsearch.gradle.internal.BwcVersions;
-import org.elasticsearch.gradle.internal.BwcVersions.VersionPair;
 import org.gradle.api.NamedDomainObjectContainer;
 import org.gradle.api.Project;
 import org.gradle.testfixtures.ProjectBuilder;
@@ -23,26 +22,26 @@ public class AbstractDistributionDownloadPluginTests {
     protected static Project packagesProject;
     protected static Project bwcProject;
 
-    protected static final VersionPair BWC_MAJOR_VERSION = new VersionPair(Version.fromString("2.0.0"), Version.fromString("3.0.0"));
-    protected static final VersionPair BWC_MINOR_VERSION = new VersionPair(Version.fromString("1.1.0"), Version.fromString("2.1.0"));
-    protected static final VersionPair BWC_STAGED_VERSION = new VersionPair(Version.fromString("1.0.0"), Version.fromString("2.0.0"));
-    protected static final VersionPair BWC_BUGFIX_VERSION = new VersionPair(Version.fromString("1.0.1"), Version.fromString("2.0.0"));
-    protected static final VersionPair BWC_MAINTENANCE_VERSION = new VersionPair(Version.fromString("0.90.1"), Version.fromString("1.1.3"));
+    protected static final Version BWC_MAJOR_VERSION = Version.fromString("2.0.0");
+    protected static final Version BWC_MINOR_VERSION = Version.fromString("1.1.0");
+    protected static final Version BWC_STAGED_VERSION = Version.fromString("1.0.0");
+    protected static final Version BWC_BUGFIX_VERSION = Version.fromString("1.0.1");
+    protected static final Version BWC_MAINTENANCE_VERSION = Version.fromString("0.90.1");
 
     protected static final BwcVersions BWC_MINOR = new BwcVersions(
-        BWC_MAJOR_VERSION.elasticsearch(),
+        BWC_MAJOR_VERSION,
         Arrays.asList(BWC_BUGFIX_VERSION, BWC_MINOR_VERSION, BWC_MAJOR_VERSION)
     );
     protected static final BwcVersions BWC_STAGED = new BwcVersions(
-        BWC_MAJOR_VERSION.elasticsearch(),
+        BWC_MAJOR_VERSION,
         Arrays.asList(BWC_MAINTENANCE_VERSION, BWC_STAGED_VERSION, BWC_MINOR_VERSION, BWC_MAJOR_VERSION)
     );
     protected static final BwcVersions BWC_BUGFIX = new BwcVersions(
-        BWC_MAJOR_VERSION.elasticsearch(),
+        BWC_MAJOR_VERSION,
         Arrays.asList(BWC_BUGFIX_VERSION, BWC_MINOR_VERSION, BWC_MAJOR_VERSION)
     );
     protected static final BwcVersions BWC_MAINTENANCE = new BwcVersions(
-        BWC_MINOR_VERSION.elasticsearch(),
+        BWC_MINOR_VERSION,
         Arrays.asList(BWC_MAINTENANCE_VERSION, BWC_BUGFIX_VERSION, BWC_MINOR_VERSION)
     );
 

+ 4 - 4
build-tools-internal/src/test/java/org/elasticsearch/gradle/internal/InternalDistributionDownloadPluginTests.java

@@ -41,10 +41,10 @@ public class InternalDistributionDownloadPluginTests extends AbstractDistributio
         for (ElasticsearchDistributionType packageType : types) {
             // note: no non bundled jdk for bwc
             String configName = projectName(packageType.toString(), true);
-            checkBwc("minor", configName, BWC_MINOR_VERSION.elasticsearch(), packageType, null, BWC_MINOR);
-            checkBwc("staged", configName, BWC_STAGED_VERSION.elasticsearch(), packageType, null, BWC_STAGED);
-            checkBwc("bugfix", configName, BWC_BUGFIX_VERSION.elasticsearch(), packageType, null, BWC_BUGFIX);
-            checkBwc("maintenance", configName, BWC_MAINTENANCE_VERSION.elasticsearch(), packageType, null, BWC_MAINTENANCE);
+            checkBwc("minor", configName, BWC_MINOR_VERSION, packageType, null, BWC_MINOR);
+            checkBwc("staged", configName, BWC_STAGED_VERSION, packageType, null, BWC_STAGED);
+            checkBwc("bugfix", configName, BWC_BUGFIX_VERSION, packageType, null, BWC_BUGFIX);
+            checkBwc("maintenance", configName, BWC_MAINTENANCE_VERSION, packageType, null, BWC_MAINTENANCE);
         }
     }
 }

+ 4 - 5
build-tools/src/testFixtures/groovy/org/elasticsearch/gradle/fixtures/AbstractGradleFuncTest.groovy

@@ -152,16 +152,15 @@ abstract class AbstractGradleFuncTest extends Specification {
         import org.elasticsearch.gradle.Architecture
         import org.elasticsearch.gradle.internal.info.BuildParams
 
-        import org.elasticsearch.gradle.internal.BwcVersions.VersionPair
         import org.elasticsearch.gradle.internal.BwcVersions
         import org.elasticsearch.gradle.Version
 
         Version currentVersion = Version.fromString("8.1.0")
         def versionList = [
-          new VersionPair(Version.fromString("$bugfix"), Version.fromString("$bugfixLucene")),
-          new VersionPair(Version.fromString("$staged"), Version.fromString("$stagedLucene")),
-          new VersionPair(Version.fromString("$minor"), Version.fromString("$minorLucene")),
-          new VersionPair(currentVersion, Version.fromString("9.0.0"))
+          Version.fromString("$bugfix"),
+          Version.fromString("$staged"),
+          Version.fromString("$minor"),
+          currentVersion
         ]
 
         BwcVersions versions = new BwcVersions(currentVersion, versionList)