2017-05-30 09:04:27 -04:00
|
|
|
import java.util.regex.Matcher
|
|
|
|
import org.elasticsearch.gradle.LoggedExec
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subdirectories of this project are dummy projects which does a local
|
|
|
|
* checkout of the appropriate version's branch, and builds a snapshot. This
|
|
|
|
* allows backcompat tests to test against the next unreleased versions
|
|
|
|
* without relying on snapshots.
|
|
|
|
*/
|
|
|
|
|
|
|
|
subprojects {
|
|
|
|
String bwcVersion
|
|
|
|
boolean enabled = true
|
|
|
|
if (project.name == 'stable-snapshot') {
|
|
|
|
/* bwc-stable is only used if the last version is on a stable branch instead
|
|
|
|
* of a release branch */
|
|
|
|
enabled = indexCompatVersions[-1].bugfix == 0
|
|
|
|
bwcVersion = indexCompatVersions[-1]
|
|
|
|
} else if (project.name == 'release-snapshot') {
|
|
|
|
if (indexCompatVersions[-1].bugfix == 0) {
|
|
|
|
/* The last version is on a stable branch so it is handled by the bwc-stable
|
|
|
|
* project. This project will instead handle the version before that which
|
|
|
|
* *should* be on a release branch. */
|
|
|
|
bwcVersion = indexCompatVersions[-2]
|
|
|
|
} else {
|
|
|
|
// The last version is on a release branch so it is handled by this project
|
|
|
|
bwcVersion = indexCompatVersions[-1]
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw new InvalidUserDataException("Unsupport project name ${project.name}")
|
|
|
|
}
|
|
|
|
if (enabled) {
|
|
|
|
apply plugin: 'distribution'
|
2017-06-16 17:19:24 -04:00
|
|
|
// Not published so no need to assemble
|
2017-06-14 19:57:26 -04:00
|
|
|
tasks.remove(assemble)
|
2017-06-16 17:19:24 -04:00
|
|
|
build.dependsOn.remove('assemble')
|
2017-05-30 09:04:27 -04:00
|
|
|
|
|
|
|
def (String major, String minor, String bugfix) = bwcVersion.split('\\.')
|
2017-06-08 13:40:45 -04:00
|
|
|
def (String currentMajor, String currentMinor, String currentBugfix) = version.split('\\.')
|
|
|
|
String bwcBranch
|
2017-11-09 15:03:40 -05:00
|
|
|
if (project.name == 'stable-snapshot' && major != currentMajor) {
|
2017-06-08 13:40:45 -04:00
|
|
|
bwcBranch = "${major}.x"
|
|
|
|
} else {
|
|
|
|
bwcBranch = "${major}.${minor}"
|
|
|
|
}
|
2017-05-30 09:04:27 -04:00
|
|
|
|
|
|
|
File esCheckoutDir = file("${buildDir}/bwc/checkout-es-${bwcBranch}")
|
|
|
|
File xpackCheckoutDir = file("${esCheckoutDir}-extra/x-pack-elasticsearch")
|
|
|
|
|
2017-10-25 22:39:58 -04:00
|
|
|
final String remote = System.getProperty("tests.bwc.remote", "elastic")
|
|
|
|
|
2017-05-30 09:04:27 -04:00
|
|
|
task createElasticsearchClone(type: LoggedExec) {
|
|
|
|
onlyIf { esCheckoutDir.exists() == false }
|
|
|
|
commandLine = ['git', 'clone', rootDir, esCheckoutDir]
|
|
|
|
}
|
|
|
|
|
|
|
|
task createXPackClone(type: LoggedExec) {
|
|
|
|
onlyIf { xpackCheckoutDir.exists() == false }
|
|
|
|
commandLine = ['git', 'clone', project(':x-pack-elasticsearch').projectDir, xpackCheckoutDir]
|
|
|
|
}
|
|
|
|
|
|
|
|
// we use regular Exec here to ensure we always get output, regardless of logging level
|
2017-10-25 22:39:58 -04:00
|
|
|
task findElasticsearchRemote(type: Exec) {
|
2017-05-30 09:04:27 -04:00
|
|
|
dependsOn createElasticsearchClone
|
|
|
|
workingDir = esCheckoutDir
|
|
|
|
commandLine = ['git', 'remote', '-v']
|
|
|
|
ignoreExitValue = true
|
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream()
|
|
|
|
standardOutput = output
|
|
|
|
doLast {
|
|
|
|
if (execResult.exitValue != 0) {
|
|
|
|
output.toString('UTF-8').eachLine { line -> logger.error(line) }
|
|
|
|
execResult.assertNormalExitValue()
|
|
|
|
}
|
2017-10-25 22:39:58 -04:00
|
|
|
project.ext.esRemoteExists = false
|
2017-05-30 09:04:27 -04:00
|
|
|
output.toString('UTF-8').eachLine {
|
2017-10-25 22:39:58 -04:00
|
|
|
if (it.contains("${remote}\tgit@github.com:${remote}/elasticsearch.git")) {
|
|
|
|
project.ext.esRemoteExists = true
|
2017-05-30 09:04:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-25 22:39:58 -04:00
|
|
|
task findXPackRemote(type: Exec) {
|
2017-05-30 09:04:27 -04:00
|
|
|
dependsOn createXPackClone
|
|
|
|
workingDir = xpackCheckoutDir
|
|
|
|
commandLine = ['git', 'remote', '-v']
|
|
|
|
ignoreExitValue = true
|
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream()
|
|
|
|
standardOutput = output
|
|
|
|
doLast {
|
|
|
|
if (execResult.exitValue != 0) {
|
|
|
|
output.toString('UTF-8').eachLine { line -> logger.error(line) }
|
|
|
|
execResult.assertNormalExitValue()
|
|
|
|
}
|
2017-10-25 22:39:58 -04:00
|
|
|
project.ext.xpackRemoteExists = false
|
2017-05-30 09:04:27 -04:00
|
|
|
output.toString('UTF-8').eachLine {
|
2017-10-25 22:39:58 -04:00
|
|
|
if (it.contains("${remote}\tgit@github.com:${remote}/x-pack-elasticsearch.git")) {
|
|
|
|
project.ext.xpackRemoteExists = true
|
2017-05-30 09:04:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-25 22:39:58 -04:00
|
|
|
task addElasticsearchRemote(type: LoggedExec) {
|
|
|
|
dependsOn findElasticsearchRemote
|
|
|
|
onlyIf { project.ext.esRemoteExists == false }
|
2017-05-30 09:04:27 -04:00
|
|
|
workingDir = esCheckoutDir
|
2017-10-25 22:39:58 -04:00
|
|
|
commandLine = ['git', 'remote', 'add', "${remote}", "git@github.com:${remote}/elasticsearch.git"]
|
2017-05-30 09:04:27 -04:00
|
|
|
}
|
|
|
|
|
2017-10-25 22:39:58 -04:00
|
|
|
task addXPackRemote(type: LoggedExec) {
|
|
|
|
dependsOn findXPackRemote
|
|
|
|
onlyIf { project.ext.xpackRemoteExists == false }
|
2017-05-30 09:04:27 -04:00
|
|
|
workingDir = xpackCheckoutDir
|
2017-10-25 22:39:58 -04:00
|
|
|
commandLine = ['git', 'remote', 'add', "${remote}", "git@github.com:${remote}/x-pack-elasticsearch.git"]
|
2017-05-30 09:04:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
task fetchElasticsearchLatest(type: LoggedExec) {
|
2017-10-25 22:39:58 -04:00
|
|
|
dependsOn addElasticsearchRemote
|
2017-05-30 09:04:27 -04:00
|
|
|
workingDir = esCheckoutDir
|
2017-08-21 03:59:45 -04:00
|
|
|
commandLine = ['git', 'fetch', '--all']
|
2017-05-30 09:04:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
task fetchXPackLatest(type: LoggedExec) {
|
2017-10-25 22:39:58 -04:00
|
|
|
dependsOn addXPackRemote
|
2017-05-30 09:04:27 -04:00
|
|
|
workingDir = xpackCheckoutDir
|
2017-08-21 03:59:45 -04:00
|
|
|
commandLine = ['git', 'fetch', '--all']
|
2017-05-30 09:04:27 -04:00
|
|
|
}
|
|
|
|
|
2017-08-28 17:03:02 -04:00
|
|
|
String esBuildMetadataKey = "bwc_refspec_${project.path.substring(1)}_elasticsearch"
|
2017-05-30 09:04:27 -04:00
|
|
|
task checkoutElasticsearchBwcBranch(type: LoggedExec) {
|
|
|
|
dependsOn fetchElasticsearchLatest
|
2017-10-25 22:39:58 -04:00
|
|
|
def String refspec = System.getProperty("tests.bwc.refspec", buildMetadata.get(esBuildMetadataKey, "${remote}/${bwcBranch}"))
|
2017-05-30 09:04:27 -04:00
|
|
|
workingDir = esCheckoutDir
|
2017-08-21 03:59:45 -04:00
|
|
|
commandLine = ['git', 'checkout', refspec]
|
2017-05-30 09:04:27 -04:00
|
|
|
}
|
|
|
|
|
2017-08-28 17:03:02 -04:00
|
|
|
String xpackBuildMetadataKey = "bwc_refspec_${project.path.substring(1)}_xpack"
|
2017-05-30 09:04:27 -04:00
|
|
|
task checkoutXPackBwcBranch(type: LoggedExec) {
|
|
|
|
dependsOn fetchXPackLatest
|
2017-10-25 22:39:58 -04:00
|
|
|
def String refspec = System.getProperty("tests.bwc.refspec", buildMetadata.get(xpackBuildMetadataKey, "${remote}/${bwcBranch}"))
|
2017-05-30 09:04:27 -04:00
|
|
|
workingDir = xpackCheckoutDir
|
2017-08-21 03:59:45 -04:00
|
|
|
commandLine = ['git', 'checkout', refspec]
|
2017-05-30 09:04:27 -04:00
|
|
|
}
|
|
|
|
|
2017-08-28 17:03:02 -04:00
|
|
|
File esBuildMetadataFile = project.file("build/${project.name}_elasticsearch/build_metadata")
|
|
|
|
task writeElasticsearchBuildMetadata(type: LoggedExec) {
|
|
|
|
dependsOn checkoutElasticsearchBwcBranch
|
|
|
|
workingDir = esCheckoutDir
|
|
|
|
commandLine = ['git', 'rev-parse', 'HEAD']
|
|
|
|
ignoreExitValue = true
|
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream()
|
|
|
|
standardOutput = output
|
|
|
|
doLast {
|
|
|
|
if (execResult.exitValue != 0) {
|
|
|
|
output.toString('UTF-8').eachLine { line -> logger.error(line) }
|
|
|
|
execResult.assertNormalExitValue()
|
|
|
|
}
|
|
|
|
project.mkdir(esBuildMetadataFile.parent)
|
|
|
|
esBuildMetadataFile.setText("${esBuildMetadataKey}=${output.toString('UTF-8')}", 'UTF-8')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
File xpackBuildMetadataFile = project.file("build/${project.name}_xpack/build_metadata")
|
|
|
|
task writeXPackBuildMetadata(type: LoggedExec) {
|
|
|
|
dependsOn checkoutXPackBwcBranch
|
|
|
|
workingDir = xpackCheckoutDir
|
|
|
|
commandLine = ['git', 'rev-parse', 'HEAD']
|
|
|
|
ignoreExitValue = true
|
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream()
|
|
|
|
standardOutput = output
|
|
|
|
doLast {
|
|
|
|
if (execResult.exitValue != 0) {
|
|
|
|
output.toString('UTF-8').eachLine { line -> logger.error(line) }
|
|
|
|
execResult.assertNormalExitValue()
|
|
|
|
}
|
|
|
|
project.mkdir(xpackBuildMetadataFile.parent)
|
|
|
|
xpackBuildMetadataFile.setText("${xpackBuildMetadataKey}=${output.toString('UTF-8')}", 'UTF-8')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 09:04:27 -04:00
|
|
|
File bwcZip = file("${xpackCheckoutDir}/plugin/build/distributions/x-pack-${bwcVersion}.zip")
|
|
|
|
task buildBwcVersion(type: GradleBuild) {
|
2017-08-28 17:03:02 -04:00
|
|
|
dependsOn checkoutXPackBwcBranch, checkoutElasticsearchBwcBranch, writeElasticsearchBuildMetadata, writeXPackBuildMetadata
|
2017-05-30 09:04:27 -04:00
|
|
|
dir = xpackCheckoutDir
|
|
|
|
tasks = [':x-pack-elasticsearch:plugin:assemble']
|
|
|
|
}
|
|
|
|
|
|
|
|
artifacts {
|
|
|
|
'default' file: bwcZip, name: 'x-pack', type: 'zip', builtBy: buildBwcVersion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|