Build: Find bwc version during build (#23801)

We currently have the last minor version of the previous major hardcoded
in tests like rolling upgrade. This change programatically finds this
during gradle initialization by parsing versions from Version.java.
This commit is contained in:
Ryan Ernst 2017-03-29 12:11:38 -07:00 committed by GitHub
parent c8081bde91
commit cc1addeac2
4 changed files with 22 additions and 9 deletions

View File

@ -18,15 +18,17 @@
*/ */
import java.nio.file.Path import java.nio.file.Path
import java.util.regex.Matcher
import org.eclipse.jgit.lib.Repository import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.lib.RepositoryBuilder import org.eclipse.jgit.lib.RepositoryBuilder
import org.gradle.plugins.ide.eclipse.model.SourceFolder import org.gradle.plugins.ide.eclipse.model.SourceFolder
import org.apache.tools.ant.taskdefs.condition.Os import org.apache.tools.ant.taskdefs.condition.Os
import org.elasticsearch.gradle.VersionProperties
// common maven publishing configuration // common maven publishing configuration
subprojects { subprojects {
group = 'org.elasticsearch' group = 'org.elasticsearch'
version = org.elasticsearch.gradle.VersionProperties.elasticsearch version = VersionProperties.elasticsearch
description = "Elasticsearch subproject ${project.path}" description = "Elasticsearch subproject ${project.path}"
} }
@ -59,12 +61,26 @@ configure(subprojects.findAll { it.projectDir.toPath().startsWith(rootPath) }) {
} }
} }
int prevMajor = Integer.parseInt(VersionProperties.elasticsearch.split('\\.')[0]) - 1
String prevSnapshot = VersionProperties.elasticsearch.contains('alpha') ? '-SNAPSHOT' : ''
File versionFile = file('core/src/main/java/org/elasticsearch/Version.java')
List<String> versionLines = versionFile.readLines('UTF-8')
int prevMinor = 0
for (String line : versionLines) {
Matcher match = line =~ /\W+public static final Version V_${prevMajor}_(\d+)_.*/
if (match.matches()) {
prevMinor = Math.max(Integer.parseInt(match.group(1)), prevMinor)
}
}
// injecting groovy property variables into all projects
allprojects { allprojects {
// injecting groovy property variables into all projects
project.ext { project.ext {
// for ide hacks... // for ide hacks...
isEclipse = System.getProperty("eclipse.launcher") != null || gradle.startParameter.taskNames.contains('eclipse') || gradle.startParameter.taskNames.contains('cleanEclipse') 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') isIdea = System.getProperty("idea.active") != null || gradle.startParameter.taskNames.contains('idea') || gradle.startParameter.taskNames.contains('cleanIdea')
// for backcompat testing
bwcVersion = "${prevMajor}.${prevMinor}.0${prevSnapshot}"
} }
} }
@ -113,7 +129,7 @@ subprojects {
"org.elasticsearch.test:framework:${version}": ':test:framework', "org.elasticsearch.test:framework:${version}": ':test:framework',
"org.elasticsearch.distribution.integ-test-zip:elasticsearch:${version}": ':distribution:integ-test-zip', "org.elasticsearch.distribution.integ-test-zip:elasticsearch:${version}": ':distribution:integ-test-zip',
// TODO: don't use a hardcoded version here, introspect it from Version.java // TODO: don't use a hardcoded version here, introspect it from Version.java
"org.elasticsearch.distribution.zip:elasticsearch:5.4.0-SNAPSHOT": ':distribution:bwc-zip', "org.elasticsearch.distribution.zip:elasticsearch:${bwcVersion}": ':distribution:bwc-zip',
"org.elasticsearch.distribution.zip:elasticsearch:${version}": ':distribution:zip', "org.elasticsearch.distribution.zip:elasticsearch:${version}": ':distribution:zip',
"org.elasticsearch.distribution.tar:elasticsearch:${version}": ':distribution:tar', "org.elasticsearch.distribution.tar:elasticsearch:${version}": ':distribution:tar',
"org.elasticsearch.distribution.rpm:elasticsearch:${version}": ':distribution:rpm', "org.elasticsearch.distribution.rpm:elasticsearch:${version}": ':distribution:rpm',

View File

@ -29,9 +29,6 @@ import org.elasticsearch.gradle.LoggedExec
apply plugin: 'distribution' apply plugin: 'distribution'
// TODO: generate this, by introspecting Version.java for last previous minor
String BWC_VERSION = "5.4.0-SNAPSHOT"
String checkoutDir = "${buildDir}/bwc/checkout-5.x" String checkoutDir = "${buildDir}/bwc/checkout-5.x"
task createClone(type: LoggedExec) { task createClone(type: LoggedExec) {
onlyIf { new File(checkoutDir).exists() == false } onlyIf { new File(checkoutDir).exists() == false }
@ -71,7 +68,7 @@ task checkoutBwcBranch(type: LoggedExec) {
commandLine = ['git', 'checkout', 'upstream/5.x'] commandLine = ['git', 'checkout', 'upstream/5.x']
} }
File bwcZip = file("${checkoutDir}/distribution/zip/build/distributions/elasticsearch-${BWC_VERSION}.zip") File bwcZip = file("${checkoutDir}/distribution/zip/build/distributions/elasticsearch-${bwcVersion}.zip")
task buildBwcVersion(type: GradleBuild) { task buildBwcVersion(type: GradleBuild) {
dependsOn checkoutBwcBranch dependsOn checkoutBwcBranch
dir = checkoutDir dir = checkoutDir

View File

@ -28,7 +28,7 @@ integTest {
integTestCluster { integTestCluster {
numNodes = 4 numNodes = 4
numBwcNodes = 2 numBwcNodes = 2
bwcVersion = "5.4.0-SNAPSHOT" bwcVersion = project.bwcVersion
setting 'logger.org.elasticsearch', 'DEBUG' setting 'logger.org.elasticsearch', 'DEBUG'
} }

View File

@ -27,7 +27,7 @@ task oldClusterTest(type: RestIntegTestTask) {
oldClusterTestCluster { oldClusterTestCluster {
distribution = 'zip' distribution = 'zip'
bwcVersion = '5.4.0-SNAPSHOT' // TODO: either randomize, or make this settable with sysprop bwcVersion = project.bwcVersion // TODO: either randomize, or make this settable with sysprop
numBwcNodes = 2 numBwcNodes = 2
numNodes = 2 numNodes = 2
clusterName = 'rolling-upgrade' clusterName = 'rolling-upgrade'