Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d50a7e4
Unused imports
DaveCTurner Nov 21, 2017
d232d2f
Typo
DaveCTurner Nov 21, 2017
d858eb4
Rename version number component 'bugfix' to 'revision'
DaveCTurner Nov 21, 2017
dd5eb22
Extract logic for reading `Version.java` out of `build.gradle`
DaveCTurner Nov 21, 2017
d9a1564
Add calculations of snapshots for BWC testing
DaveCTurner Nov 21, 2017
53b0e57
Convert VersionUtils into VersionCollection, encapsulating the list o…
DaveCTurner Nov 21, 2017
1e60605
Get rid of indexCompatVersions and wireCompatVersions and simply use …
DaveCTurner Nov 21, 2017
403debd
Add hack for testing vs different Version.java files
DaveCTurner Nov 21, 2017
1c66e9a
Fail if versionCollection.BWCSnapshotForPreviousMinorOfCurrentMajor w…
DaveCTurner Nov 21, 2017
ef0fa0e
Add tests of VersionCollection
DaveCTurner Nov 22, 2017
9e1dc82
Expand import *
DaveCTurner Nov 22, 2017
e591919
Get rid of tests for VersionCollection
DaveCTurner Nov 22, 2017
f53ae09
Merge branch 'master' into 2017-11-20-version-numbering
DaveCTurner Nov 22, 2017
f93e7bc
Resolve TODO: only check out the known snapshots
DaveCTurner Nov 22, 2017
05c6956
Add comments
DaveCTurner Nov 22, 2017
ee1ce49
Explicit types
DaveCTurner Nov 22, 2017
3fac5d7
Stop failing on versionCollection.BWCSnapshotForPreviousMinorOfCurren…
DaveCTurner Nov 22, 2017
0f7f8aa
Merge branch 'master' into 2017-11-20-version-numbering
DaveCTurner Nov 22, 2017
5643e08
Merge branch 'master' into 2017-11-20-version-numbering
DaveCTurner Nov 22, 2017
ee9812f
Merge remote-tracking branch 'upstream/master' into 2017-11-20-versio…
DaveCTurner Nov 23, 2017
353465b
Added one project for each historical branch for BWC testing
DaveCTurner Nov 23, 2017
e9e5915
Create bwc-snapshot projects for all branches
DaveCTurner Nov 23, 2017
ee7de8f
Also need to set up the project substitutions, oops
DaveCTurner Nov 23, 2017
807592b
Apparently you need to omit the "ext." qualifier here
DaveCTurner Nov 23, 2017
d439370
Create dummy projects for each branch within each plugin too
DaveCTurner Nov 23, 2017
c75b874
Choose a name that's less likely to clash
DaveCTurner Nov 23, 2017
3242036
Merge branch 'master' into 2017-11-20-version-numbering
DaveCTurner Nov 23, 2017
27810c3
Just check out into the dummy project directory, no need for an extra…
DaveCTurner Nov 23, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 26 additions & 94 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
* under the License.
*/

import java.nio.file.Path
import java.util.regex.Matcher
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.lib.RepositoryBuilder
import org.gradle.plugins.ide.eclipse.model.SourceFolder

import org.apache.tools.ant.taskdefs.condition.Os
import org.elasticsearch.gradle.BuildPlugin
import org.elasticsearch.gradle.VersionProperties
import org.elasticsearch.gradle.Version
import org.elasticsearch.gradle.VersionCollection
import org.elasticsearch.gradle.VersionProperties
import org.gradle.plugins.ide.eclipse.model.SourceFolder

import java.nio.file.Path

// common maven publishing configuration
subprojects {
Expand Down Expand Up @@ -67,72 +67,16 @@ configure(subprojects.findAll { it.projectDir.toPath().startsWith(rootPath) }) {
}
}

/* Introspect all versions of ES that may be tested agains for backwards
/* Introspect all versions of ES that may be tested against for backwards
* compatibility. It is *super* important that this logic is the same as the
* logic in VersionUtils.java, throwing out alphas because they don't have any
* backwards compatibility guarantees and only keeping the latest beta or rc
* in a branch if there are only betas and rcs in the branch so we have
* *something* to test against. */
Version currentVersion = Version.fromString(VersionProperties.elasticsearch.minus('-SNAPSHOT'))
int prevMajor = currentVersion.major - 1
File versionFile = file('core/src/main/java/org/elasticsearch/Version.java')
List<String> versionLines = versionFile.readLines('UTF-8')
List<Version> versions = []
// keep track of the previous major version's last minor, so we know where wire compat begins
int prevMinorIndex = -1 // index in the versions list of the last minor from the prev major
int lastPrevMinor = -1 // the minor version number from the prev major we most recently seen
int prevBugfixIndex = -1 // index in the versions list of the last bugfix release from the prev major
for (String line : versionLines) {
/* Note that this skips alphas and betas which is fine because they aren't
* compatible with anything. */
Matcher match = line =~ /\W+public static final Version V_(\d+)_(\d+)_(\d+)(_beta\d+|_rc\d+)? .*/
if (match.matches()) {
int major = Integer.parseInt(match.group(1))
int minor = Integer.parseInt(match.group(2))
int bugfix = Integer.parseInt(match.group(3))
String suffix = (match.group(4) ?: '').replace('_', '-')
Version foundVersion = new Version(major, minor, bugfix, suffix, false)
if (currentVersion != foundVersion
&& (major == prevMajor || major == currentVersion.major)) {
if (versions.isEmpty() || versions.last() != foundVersion) {
versions.add(foundVersion)
} else {
// Replace the earlier betas with later ones
Version last = versions.set(versions.size() - 1, foundVersion)
if (last.suffix == '') {
throw new InvalidUserDataException("Found two equal versions but"
+ " the first one [$last] wasn't a beta.")
}
}
if (major == prevMajor && minor > lastPrevMinor) {
prevMinorIndex = versions.size() - 1
lastPrevMinor = minor
}
}
if (major == prevMajor) {
prevBugfixIndex = versions.size() - 1
}
}
}
if (versions.toSorted { it.id } != versions) {
println "Versions: ${versions}"
throw new GradleException("Versions.java contains out of order version constants")
}
if (prevBugfixIndex != -1) {
versions[prevBugfixIndex] = new Version(versions[prevBugfixIndex].major, versions[prevBugfixIndex].minor,
versions[prevBugfixIndex].bugfix, versions[prevBugfixIndex].suffix, true)
}
if (currentVersion.bugfix == 0) {
// If on a release branch, after the initial release of that branch, the bugfix version will
// be bumped, and will be != 0. On master and N.x branches, we want to test against the
// unreleased version of closest branch. So for those cases, the version includes -SNAPSHOT,
// and the bwc distribution will checkout and build that version.
Version last = versions[-1]
versions[-1] = new Version(last.major, last.minor, last.bugfix, last.suffix, true)
if (last.bugfix == 0) {
versions[-2] = new Version(
versions[-2].major, versions[-2].minor, versions[-2].bugfix, versions[-2].suffix, true)
}
VersionCollection versions = new VersionCollection(file('core/src/main/java/org/elasticsearch/Version.java').readLines('UTF-8'))
if (versions.currentVersion.toString() != VersionProperties.elasticsearch) {
throw new GradleException("The last version in Versions.java [${versions.currentVersion}] does not match " +
"VersionProperties.elasticsearch [${VersionProperties.elasticsearch}]")
}

// build metadata from previous build, contains eg hashes for bwc builds
Expand All @@ -151,9 +95,10 @@ allprojects {
// for ide hacks...
isEclipse = System.getProperty("eclipse.launcher") != null || gradle.startParameter.taskNames.contains('eclipse') || gradle.startParameter.taskNames.contains('cleanEclipse')
isIdea = System.getProperty("idea.active") != null || gradle.startParameter.taskNames.contains('idea') || gradle.startParameter.taskNames.contains('cleanIdea')
// for backcompat testing
indexCompatVersions = versions
wireCompatVersions = versions.subList(prevMinorIndex, versions.size())

// for BWC testing
versionCollection = versions

buildMetadata = buildMetadataMap
}
}
Expand All @@ -171,13 +116,13 @@ task verifyVersions {
Set<Version> knownVersions = new TreeSet<>(xml.versioning.versions.version.collect { it.text() }.findAll { it ==~ /\d\.\d\.\d/ }.collect { Version.fromString(it) })

// Limit the known versions to those that should be index compatible, and are not future versions
knownVersions = knownVersions.findAll { it.major >= prevMajor && it.before(VersionProperties.elasticsearch) }
knownVersions = knownVersions.findAll { it.major >= versions.currentVersion.major - 1 && it.before(VersionProperties.elasticsearch) }

/* Limit the listed versions to those that have been marked as released.
* Versions not marked as released don't get the same testing and we want
* to make sure that we flip all unreleased versions to released as soon
* as possible after release. */
Set<Version> actualVersions = new TreeSet<>(indexCompatVersions.findAll { false == it.snapshot })
Set<Version> actualVersions = new TreeSet<>(versions.versionsIndexCompatibleWithCurrent.findAll { false == it.snapshot })

// Finally, compare!
if (knownVersions.equals(actualVersions) == false) {
Expand Down Expand Up @@ -252,30 +197,17 @@ subprojects {
"org.elasticsearch.plugin:aggs-matrix-stats-client:${version}": ':modules:aggs-matrix-stats',
"org.elasticsearch.plugin:percolator-client:${version}": ':modules:percolator',
]
if (indexCompatVersions[-1].snapshot) {
/* The last and second to last versions can be snapshots. Rather than use
* snapshots built by CI we connect these versions to projects that build
* those those versions from the HEAD of the appropriate branch. */
if (indexCompatVersions[-1].bugfix == 0) {
ext.projectSubstitutions["org.elasticsearch.distribution.deb:elasticsearch:${indexCompatVersions[-1]}"] = ':distribution:bwc-stable-snapshot'
ext.projectSubstitutions["org.elasticsearch.distribution.rpm:elasticsearch:${indexCompatVersions[-1]}"] = ':distribution:bwc-stable-snapshot'
ext.projectSubstitutions["org.elasticsearch.distribution.zip:elasticsearch:${indexCompatVersions[-1]}"] = ':distribution:bwc-stable-snapshot'
if (indexCompatVersions.size() > 1) {
ext.projectSubstitutions["org.elasticsearch.distribution.deb:elasticsearch:${indexCompatVersions[-2]}"] = ':distribution:bwc-release-snapshot'
ext.projectSubstitutions["org.elasticsearch.distribution.rpm:elasticsearch:${indexCompatVersions[-2]}"] = ':distribution:bwc-release-snapshot'
ext.projectSubstitutions["org.elasticsearch.distribution.zip:elasticsearch:${indexCompatVersions[-2]}"] = ':distribution:bwc-release-snapshot'
}
} else {
ext.projectSubstitutions["org.elasticsearch.distribution.deb:elasticsearch:${indexCompatVersions[-1]}"] = ':distribution:bwc-release-snapshot'
ext.projectSubstitutions["org.elasticsearch.distribution.rpm:elasticsearch:${indexCompatVersions[-1]}"] = ':distribution:bwc-release-snapshot'
ext.projectSubstitutions["org.elasticsearch.distribution.zip:elasticsearch:${indexCompatVersions[-1]}"] = ':distribution:bwc-release-snapshot'

for (final Version version : versionCollection.versionsIndexCompatibleWithCurrent) {
if (version.branch != null) {
final String snapshotProject = ":distribution:bwc-snapshot-${version.branch}"
project(snapshotProject).ext.bwcVersion = version
ext.projectSubstitutions["org.elasticsearch.distribution.deb:elasticsearch:${version}"] = snapshotProject
ext.projectSubstitutions["org.elasticsearch.distribution.rpm:elasticsearch:${version}"] = snapshotProject
ext.projectSubstitutions["org.elasticsearch.distribution.zip:elasticsearch:${version}"] = snapshotProject
}
} else if (indexCompatVersions[-2].snapshot) {
/* This is a terrible hack for the bump to 6.0.1 which will be fixed by #27397 */
ext.projectSubstitutions["org.elasticsearch.distribution.deb:elasticsearch:${indexCompatVersions[-2]}"] = ':distribution:bwc-release-snapshot'
ext.projectSubstitutions["org.elasticsearch.distribution.rpm:elasticsearch:${indexCompatVersions[-2]}"] = ':distribution:bwc-release-snapshot'
ext.projectSubstitutions["org.elasticsearch.distribution.zip:elasticsearch:${indexCompatVersions[-2]}"] = ':distribution:bwc-release-snapshot'
}

project.afterEvaluate {
configurations.all {
resolutionStrategy.dependencySubstitution { DependencySubstitutions subs ->
Expand Down
55 changes: 48 additions & 7 deletions buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,26 @@ public class Version {

final int major
final int minor
final int bugfix
final int revision
final int id
final boolean snapshot
final String branch
/**
* Suffix on the version name. Unlike Version.java the build does not
* consider alphas and betas different versions, it just preserves the
* suffix that the version was declared with in Version.java.
*/
final String suffix

public Version(int major, int minor, int bugfix,
String suffix, boolean snapshot) {
public Version(int major, int minor, int revision,
String suffix, boolean snapshot, String branch) {
this.major = major
this.minor = minor
this.bugfix = bugfix
this.revision = revision
this.snapshot = snapshot
this.suffix = suffix
this.id = major * 100000 + minor * 1000 + bugfix * 10 +
this.branch = branch
this.id = major * 100000 + minor * 1000 + revision * 10 +
(snapshot ? 1 : 0)
}

Expand All @@ -58,13 +60,13 @@ public class Version {
throw new InvalidUserDataException("Invalid version [${s}]")
}
return new Version(m.group(1) as int, m.group(2) as int,
m.group(3) as int, m.group(4) ?: '', m.group(5) != null)
m.group(3) as int, m.group(4) ?: '', m.group(5) != null, null)
}

@Override
public String toString() {
String snapshotStr = snapshot ? '-SNAPSHOT' : ''
return "${major}.${minor}.${bugfix}${suffix}${snapshotStr}"
return "${major}.${minor}.${revision}${suffix}${snapshotStr}"
}

public boolean before(String compareTo) {
Expand All @@ -82,4 +84,43 @@ public class Version {
public boolean after(String compareTo) {
return id > fromString(compareTo).id
}

public boolean onOrBeforeIncludingSuffix(Version otherVersion) {
if (id != otherVersion.id) {
return id < otherVersion.id
}

if (suffix == '') {
return otherVersion.suffix == ''
}

return otherVersion.suffix == '' || suffix < otherVersion.suffix
}

boolean equals(o) {
if (this.is(o)) return true
if (getClass() != o.class) return false

Version version = (Version) o

if (id != version.id) return false
if (major != version.major) return false
if (minor != version.minor) return false
if (revision != version.revision) return false
if (snapshot != version.snapshot) return false
if (suffix != version.suffix) return false

return true
}

int hashCode() {
int result
result = major
result = 31 * result + minor
result = 31 * result + revision
result = 31 * result + id
result = 31 * result + (snapshot ? 1 : 0)
result = 31 * result + (suffix != null ? suffix.hashCode() : 0)
return result
}
}
Loading