Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ for (String line : versionLines) {
int major = Integer.parseInt(match.group(1))
int minor = Integer.parseInt(match.group(2))
int bugfix = Integer.parseInt(match.group(3))
Version foundVersion = new Version(major, minor, bugfix, false)
String suffix = (match.group(4) ?: '').replace('_', '-')
Version foundVersion = new Version(major, minor, bugfix, suffix, false)
if (currentVersion != foundVersion
&& (major == prevMajor || major == currentVersion.major)
&& (versions.isEmpty() || versions.last() != foundVersion)) {
Expand All @@ -106,10 +107,10 @@ if (currentVersion.bugfix == 0) {
// 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, true)
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, true)
versions[-2].major, versions[-2].minor, versions[-2].bugfix, versions[-2].suffix, true)
}
}

Expand Down
27 changes: 17 additions & 10 deletions buildSrc/src/main/groovy/org/elasticsearch/gradle/Version.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package org.elasticsearch.gradle

import groovy.transform.Sortable
import java.util.regex.Matcher
import org.gradle.api.InvalidUserDataException

/**
* Encapsulates comparison and printing logic for an x.y.z version.
Expand All @@ -32,32 +34,37 @@ public class Version {
final int bugfix
final int id
final boolean snapshot
/**
* 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, boolean snapshot) {
public Version(int major, int minor, int bugfix,
String suffix, boolean snapshot) {
this.major = major
this.minor = minor
this.bugfix = bugfix
this.snapshot = snapshot
this.suffix = suffix
this.id = major * 100000 + minor * 1000 + bugfix * 10 +
(snapshot ? 1 : 0)
}

public static Version fromString(String s) {
String[] parts = s.split('\\.')
String bugfix = parts[2]
boolean snapshot = false
if (bugfix.contains('-')) {
snapshot = bugfix.endsWith('-SNAPSHOT')
bugfix = bugfix.split('-')[0]
Matcher m = s =~ /(\d+)\.(\d+)\.(\d+)(-alpha\d+|-beta\d+|-rc\d+)?(-SNAPSHOT)?/
if (m.matches() == false) {
throw new InvalidUserDataException("Invalid version [${s}]")
}
return new Version(parts[0] as int, parts[1] as int, bugfix as int,
snapshot)
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)
}

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

public boolean before(String compareTo) {
Expand Down
8 changes: 8 additions & 0 deletions distribution/bwc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ if (enabled) {
dependsOn checkoutBwcBranch
dir = checkoutDir
tasks = [':distribution:deb:assemble', ':distribution:rpm:assemble', ':distribution:zip:assemble']
doLast {
List missing = [bwcDeb, bwcRpm, bwcZip].grep { file ->
false == file.exists() }
if (false == missing.empty) {
throw new InvalidUserDataException(
"Building bwc version didn't generate expected files ${missing}")
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,15 @@ public void testGradleVersionsMatchVersionUtils() {
// First check the index compatible versions
VersionsFromProperty indexCompatible = new VersionsFromProperty("tests.gradle_index_compat_versions");
List<Version> released = VersionUtils.allReleasedVersions().stream()
/* We skip alphas, betas, and the like in gradle because they don't have
* backwards compatibility guarantees even though they are technically
* released. */
.filter(v -> v.isRelease() && (v.major == Version.CURRENT.major || v.major == Version.CURRENT.major - 1))
// Java lists some non-index compatible versions but gradle does not include them.
.filter(v -> v.major == Version.CURRENT.major || v.major == Version.CURRENT.major - 1)
/* Gradle will never include *released* alphas or betas because it will prefer
* the unreleased branch head. Gradle is willing to use branch heads that are
* alpha or beta so that we have *something* to test against even though we
* do not offer backwards compatibility for alphas, betas, or rcs. */
.filter(Version::isRelease)
.collect(toList());

List<String> releasedIndexCompatible = released.stream()
.map(Object::toString)
.collect(toList());
Expand All @@ -195,7 +199,12 @@ public void testGradleVersionsMatchVersionUtils() {
/* 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(v -> v.major + "." + v.minor + "." + v.revision)
/* Note that gradle does *not* skip alphas, betas, or rcs here even
* though we don't have backwards compatibility for alphas, betas,
Copy link
Member

@rjernst rjernst Aug 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we agreed to only have the last beta/rc in the wire/index compat versions in gradle in the special case of a new major release like we have now. So we should not have betas/rcs here in most cases. Also, gradle still does not ever have alphas, that would not be matched by the regex for Version.java.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe only the last beta/rc in a branch is unreleased so I think we're good there. I mean, it is technically possible for the release branch and the stable branch to have a beta but I don't think we'll do that so I'm not sure it is worth filtering it out.

I'm not sure why we don't have alphas in the Version.groovy. I mean, I know the regex doesn't match them, I just don't know why we treat them differently then betas. Either way, I can remove the word alpha here and make the filter just allow betas and rcs if you like.

I haven't changed the way gradle scrapes the versions. Did you want me to do that as part of this PR? We talked about wanting that "only the last beta/rc" behavior but I was under the impression we'd already implemented it. When I went to make this change it looks like we haven't and the reason our list lines up now is because we only pick up alphas.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we don't have alphas in the Version.groovy. I mean, I know the regex doesn't match them, I just don't know why we treat them differently then betas

Because alphas are only cut from master, so there is never a case where we need to worry about bwc with an alpha. Only once we branch for a major release will we have betas/rcs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about wanting that "only the last beta/rc" behavior but I was under the impression we'd already implemented it

You are right, I think I already did this. I forgot.

* and rcs. Gradle includes them because they represent the head of
* a branch that will one day be released for which we will offer
* backwards compatibility. */
.map(Object::toString)
.collect(toCollection(LinkedHashSet::new)));
assertEquals(unreleasedIndexCompatible, indexCompatible.unreleased);

Expand Down