1717 * under the License.
1818 */
1919
20- import java.nio.file.Path
21- import java.util.regex.Matcher
22- import org.eclipse.jgit.lib.Repository
23- import org.eclipse.jgit.lib.RepositoryBuilder
24- import org.gradle.plugins.ide.eclipse.model.SourceFolder
20+
2521import org.apache.tools.ant.taskdefs.condition.Os
2622import org.elasticsearch.gradle.BuildPlugin
27- import org.elasticsearch.gradle.VersionProperties
2823import org.elasticsearch.gradle.Version
24+ import org.elasticsearch.gradle.VersionCollection
25+ import org.elasticsearch.gradle.VersionProperties
26+ import org.gradle.plugins.ide.eclipse.model.SourceFolder
27+
28+ import java.nio.file.Path
2929
3030// common maven publishing configuration
3131subprojects {
@@ -67,72 +67,16 @@ configure(subprojects.findAll { it.projectDir.toPath().startsWith(rootPath) }) {
6767 }
6868}
6969
70- /* Introspect all versions of ES that may be tested agains for backwards
70+ /* Introspect all versions of ES that may be tested against for backwards
7171 * compatibility. It is *super* important that this logic is the same as the
7272 * logic in VersionUtils.java, throwing out alphas because they don't have any
7373 * backwards compatibility guarantees and only keeping the latest beta or rc
7474 * in a branch if there are only betas and rcs in the branch so we have
7575 * *something* to test against. */
76- Version currentVersion = Version . fromString(VersionProperties . elasticsearch. minus(' -SNAPSHOT' ))
77- int prevMajor = currentVersion. major - 1
78- File versionFile = file(' core/src/main/java/org/elasticsearch/Version.java' )
79- List<String > versionLines = versionFile. readLines(' UTF-8' )
80- List<Version > versions = []
81- // keep track of the previous major version's last minor, so we know where wire compat begins
82- int prevMinorIndex = -1 // index in the versions list of the last minor from the prev major
83- int lastPrevMinor = -1 // the minor version number from the prev major we most recently seen
84- int prevBugfixIndex = -1 // index in the versions list of the last bugfix release from the prev major
85- for (String line : versionLines) {
86- /* Note that this skips alphas and betas which is fine because they aren't
87- * compatible with anything. */
88- Matcher match = line =~ / \W +public static final Version V_(\d +)_(\d +)_(\d +)(_beta\d +|_rc\d +)? .*/
89- if (match. matches()) {
90- int major = Integer . parseInt(match. group(1 ))
91- int minor = Integer . parseInt(match. group(2 ))
92- int bugfix = Integer . parseInt(match. group(3 ))
93- String suffix = (match. group(4 ) ?: ' ' ). replace(' _' , ' -' )
94- Version foundVersion = new Version (major, minor, bugfix, suffix, false )
95- if (currentVersion != foundVersion
96- && (major == prevMajor || major == currentVersion. major)) {
97- if (versions. isEmpty() || versions. last() != foundVersion) {
98- versions. add(foundVersion)
99- } else {
100- // Replace the earlier betas with later ones
101- Version last = versions. set(versions. size() - 1 , foundVersion)
102- if (last. suffix == ' ' ) {
103- throw new InvalidUserDataException (" Found two equal versions but"
104- + " the first one [$last ] wasn't a beta." )
105- }
106- }
107- if (major == prevMajor && minor > lastPrevMinor) {
108- prevMinorIndex = versions. size() - 1
109- lastPrevMinor = minor
110- }
111- }
112- if (major == prevMajor) {
113- prevBugfixIndex = versions. size() - 1
114- }
115- }
116- }
117- if (versions. toSorted { it. id } != versions) {
118- println " Versions: ${ versions} "
119- throw new GradleException (" Versions.java contains out of order version constants" )
120- }
121- if (prevBugfixIndex != -1 ) {
122- versions[prevBugfixIndex] = new Version (versions[prevBugfixIndex]. major, versions[prevBugfixIndex]. minor,
123- versions[prevBugfixIndex]. bugfix, versions[prevBugfixIndex]. suffix, true )
124- }
125- if (currentVersion. bugfix == 0 ) {
126- // If on a release branch, after the initial release of that branch, the bugfix version will
127- // be bumped, and will be != 0. On master and N.x branches, we want to test against the
128- // unreleased version of closest branch. So for those cases, the version includes -SNAPSHOT,
129- // and the bwc distribution will checkout and build that version.
130- Version last = versions[-1 ]
131- versions[-1 ] = new Version (last. major, last. minor, last. bugfix, last. suffix, true )
132- if (last. bugfix == 0 ) {
133- versions[-2 ] = new Version (
134- versions[-2 ]. major, versions[-2 ]. minor, versions[-2 ]. bugfix, versions[-2 ]. suffix, true )
135- }
76+ VersionCollection versions = new VersionCollection (file(' core/src/main/java/org/elasticsearch/Version.java' ). readLines(' UTF-8' ))
77+ if (versions. currentVersion. toString() != VersionProperties . elasticsearch) {
78+ throw new GradleException (" The last version in Versions.java [${ versions.currentVersion} ] does not match " +
79+ " VersionProperties.elasticsearch [${ VersionProperties.elasticsearch} ]" )
13680}
13781
13882// build metadata from previous build, contains eg hashes for bwc builds
@@ -151,9 +95,10 @@ allprojects {
15195 // for ide hacks...
15296 isEclipse = System . getProperty(" eclipse.launcher" ) != null || gradle. startParameter. taskNames. contains(' eclipse' ) || gradle. startParameter. taskNames. contains(' cleanEclipse' )
15397 isIdea = System . getProperty(" idea.active" ) != null || gradle. startParameter. taskNames. contains(' idea' ) || gradle. startParameter. taskNames. contains(' cleanIdea' )
154- // for backcompat testing
155- indexCompatVersions = versions
156- wireCompatVersions = versions. subList(prevMinorIndex, versions. size())
98+
99+ // for BWC testing
100+ versionCollection = versions
101+
157102 buildMetadata = buildMetadataMap
158103 }
159104}
@@ -171,13 +116,13 @@ task verifyVersions {
171116 Set<Version > knownVersions = new TreeSet<> (xml. versioning. versions. version. collect { it. text() }. findAll { it ==~ / \d\.\d\.\d / }. collect { Version . fromString(it) })
172117
173118 // Limit the known versions to those that should be index compatible, and are not future versions
174- knownVersions = knownVersions. findAll { it. major >= prevMajor && it. before(VersionProperties . elasticsearch) }
119+ knownVersions = knownVersions. findAll { it. major >= versions . currentVersion . major - 1 && it. before(VersionProperties . elasticsearch) }
175120
176121 /* Limit the listed versions to those that have been marked as released.
177122 * Versions not marked as released don't get the same testing and we want
178123 * to make sure that we flip all unreleased versions to released as soon
179124 * as possible after release. */
180- Set<Version > actualVersions = new TreeSet<> (indexCompatVersions . findAll { false == it. snapshot })
125+ Set<Version > actualVersions = new TreeSet<> (versions . versionsIndexCompatibleWithCurrent . findAll { false == it. snapshot })
181126
182127 // Finally, compare!
183128 if (knownVersions. equals(actualVersions) == false ) {
@@ -252,30 +197,17 @@ subprojects {
252197 " org.elasticsearch.plugin:aggs-matrix-stats-client:${ version} " : ' :modules:aggs-matrix-stats' ,
253198 " org.elasticsearch.plugin:percolator-client:${ version} " : ' :modules:percolator' ,
254199 ]
255- if (indexCompatVersions[-1 ]. snapshot) {
256- /* The last and second to last versions can be snapshots. Rather than use
257- * snapshots built by CI we connect these versions to projects that build
258- * those those versions from the HEAD of the appropriate branch. */
259- if (indexCompatVersions[-1 ]. bugfix == 0 ) {
260- ext. projectSubstitutions[" org.elasticsearch.distribution.deb:elasticsearch:${ indexCompatVersions[-1]} " ] = ' :distribution:bwc-stable-snapshot'
261- ext. projectSubstitutions[" org.elasticsearch.distribution.rpm:elasticsearch:${ indexCompatVersions[-1]} " ] = ' :distribution:bwc-stable-snapshot'
262- ext. projectSubstitutions[" org.elasticsearch.distribution.zip:elasticsearch:${ indexCompatVersions[-1]} " ] = ' :distribution:bwc-stable-snapshot'
263- if (indexCompatVersions. size() > 1 ) {
264- ext. projectSubstitutions[" org.elasticsearch.distribution.deb:elasticsearch:${ indexCompatVersions[-2]} " ] = ' :distribution:bwc-release-snapshot'
265- ext. projectSubstitutions[" org.elasticsearch.distribution.rpm:elasticsearch:${ indexCompatVersions[-2]} " ] = ' :distribution:bwc-release-snapshot'
266- ext. projectSubstitutions[" org.elasticsearch.distribution.zip:elasticsearch:${ indexCompatVersions[-2]} " ] = ' :distribution:bwc-release-snapshot'
267- }
268- } else {
269- ext. projectSubstitutions[" org.elasticsearch.distribution.deb:elasticsearch:${ indexCompatVersions[-1]} " ] = ' :distribution:bwc-release-snapshot'
270- ext. projectSubstitutions[" org.elasticsearch.distribution.rpm:elasticsearch:${ indexCompatVersions[-1]} " ] = ' :distribution:bwc-release-snapshot'
271- ext. projectSubstitutions[" org.elasticsearch.distribution.zip:elasticsearch:${ indexCompatVersions[-1]} " ] = ' :distribution:bwc-release-snapshot'
200+
201+ for (final Version version : versionCollection. versionsIndexCompatibleWithCurrent) {
202+ if (version. branch != null ) {
203+ final String snapshotProject = " :distribution:bwc-snapshot-${ version.branch} "
204+ project(snapshotProject). ext. bwcVersion = version
205+ ext. projectSubstitutions[" org.elasticsearch.distribution.deb:elasticsearch:${ version} " ] = snapshotProject
206+ ext. projectSubstitutions[" org.elasticsearch.distribution.rpm:elasticsearch:${ version} " ] = snapshotProject
207+ ext. projectSubstitutions[" org.elasticsearch.distribution.zip:elasticsearch:${ version} " ] = snapshotProject
272208 }
273- } else if (indexCompatVersions[-2 ]. snapshot) {
274- /* This is a terrible hack for the bump to 6.0.1 which will be fixed by #27397 */
275- ext. projectSubstitutions[" org.elasticsearch.distribution.deb:elasticsearch:${ indexCompatVersions[-2]} " ] = ' :distribution:bwc-release-snapshot'
276- ext. projectSubstitutions[" org.elasticsearch.distribution.rpm:elasticsearch:${ indexCompatVersions[-2]} " ] = ' :distribution:bwc-release-snapshot'
277- ext. projectSubstitutions[" org.elasticsearch.distribution.zip:elasticsearch:${ indexCompatVersions[-2]} " ] = ' :distribution:bwc-release-snapshot'
278209 }
210+
279211 project. afterEvaluate {
280212 configurations. all {
281213 resolutionStrategy. dependencySubstitution { DependencySubstitutions subs ->
0 commit comments