2017-12-07 13:04:40 -05:00
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
2017-11-21 03:45:10 -05:00
|
|
|
import org.elasticsearch.gradle.Version
|
|
|
|
|
2017-05-30 09:04:27 -04:00
|
|
|
import java.util.regex.Matcher
|
|
|
|
import org.elasticsearch.gradle.LoggedExec
|
2017-12-07 13:04:40 -05:00
|
|
|
import org.elasticsearch.gradle.test.NodeInfo
|
2017-05-30 09:04:27 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 {
|
2017-11-21 03:45:10 -05:00
|
|
|
final Matcher match = project.name =~ /bwc-snapshot-(\d+\.(\d+|x))/
|
|
|
|
if (!match.matches()) {
|
2017-05-30 09:04:27 -04:00
|
|
|
throw new InvalidUserDataException("Unsupport project name ${project.name}")
|
|
|
|
}
|
2017-11-21 03:45:10 -05:00
|
|
|
String bwcBranch = match.group(1)
|
|
|
|
|
|
|
|
if (project.hasProperty('bwcVersion')) {
|
|
|
|
Version bwcVersion = project.ext.bwcVersion
|
|
|
|
|
2017-05-30 09:04:27 -04:00
|
|
|
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
|
|
|
|
|
|
|
File esCheckoutDir = file("${buildDir}/bwc/checkout-es-${bwcBranch}")
|
2017-12-07 13:04:40 -05:00
|
|
|
/* Delay building the path as the path will not exist during configuration which will
|
|
|
|
* fail on Windows due to getting the short name requiring the path to already exist.
|
|
|
|
*/
|
|
|
|
Object esCheckoutPath = """${->
|
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
2017-12-18 12:13:54 -05:00
|
|
|
esCheckoutDir.mkdirs()
|
2017-12-07 13:04:40 -05:00
|
|
|
NodeInfo.getShortPathName(esCheckoutDir.toString())
|
|
|
|
} else {
|
|
|
|
esCheckoutDir.toString()
|
|
|
|
}
|
|
|
|
}"""
|
2017-05-30 09:04:27 -04:00
|
|
|
File xpackCheckoutDir = file("${esCheckoutDir}-extra/x-pack-elasticsearch")
|
2017-12-07 13:04:40 -05:00
|
|
|
Object xpackCheckoutPath = """${->
|
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
2017-12-18 12:13:54 -05:00
|
|
|
xpackCheckoutDir.mkdirs()
|
2017-12-07 13:04:40 -05:00
|
|
|
NodeInfo.getShortPathName(xpackCheckoutDir.toString())
|
|
|
|
} else {
|
|
|
|
xpackCheckoutDir.toString()
|
|
|
|
}
|
|
|
|
}"""
|
2017-05-30 09:04:27 -04:00
|
|
|
|
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 }
|
2017-12-07 13:04:40 -05:00
|
|
|
commandLine = ['git', 'clone', rootDir, esCheckoutPath]
|
2017-05-30 09:04:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
task createXPackClone(type: LoggedExec) {
|
|
|
|
onlyIf { xpackCheckoutDir.exists() == false }
|
2018-01-27 00:48:30 -05:00
|
|
|
commandLine = ['git', 'clone', xpackRootProject.projectDir, xpackCheckoutPath]
|
2017-05-30 09:04:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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")
|
2018-01-08 21:47:41 -05:00
|
|
|
task buildBwcVersion(type: Exec) {
|
2017-08-28 17:03:02 -04:00
|
|
|
dependsOn checkoutXPackBwcBranch, checkoutElasticsearchBwcBranch, writeElasticsearchBuildMetadata, writeXPackBuildMetadata
|
2018-01-08 21:47:41 -05:00
|
|
|
workingDir = xpackCheckoutDir
|
2018-01-16 13:45:42 -05:00
|
|
|
if (project.rootProject.ext.runtimeJavaVersion == JavaVersion.VERSION_1_8 && ["5.6", "6.0", "6.1"].contains(bwcBranch)) {
|
|
|
|
/*
|
|
|
|
* If runtime Java home is set to JDK 8 and we are building branches that are officially built with JDK 8, push this to JAVA_HOME for
|
|
|
|
* these builds.
|
|
|
|
*/
|
|
|
|
environment('JAVA_HOME', System.getenv('RUNTIME_JAVA_HOME'))
|
|
|
|
}
|
2018-01-09 05:58:41 -05:00
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
|
executable 'cmd'
|
|
|
|
args '/C', 'call', new File(xpackCheckoutDir, 'gradlew').toString()
|
|
|
|
} else {
|
2018-01-16 13:45:42 -05:00
|
|
|
executable new File(xpackCheckoutDir, 'gradlew').toString()
|
2018-01-09 05:58:41 -05:00
|
|
|
}
|
2018-01-16 13:45:42 -05:00
|
|
|
args ":x-pack-elasticsearch:plugin:assemble", "-Dbuild.snapshot=${System.getProperty('build.snapshot') ?: 'true'}"
|
2018-01-08 21:47:41 -05:00
|
|
|
final LogLevel logLevel = gradle.startParameter.logLevel
|
|
|
|
if ([LogLevel.QUIET, LogLevel.WARN, LogLevel.INFO, LogLevel.DEBUG].contains(logLevel)) {
|
2018-01-16 13:45:42 -05:00
|
|
|
args "--${logLevel.name().toLowerCase(Locale.ENGLISH)}"
|
2018-01-08 21:47:41 -05:00
|
|
|
}
|
|
|
|
final String showStacktraceName = gradle.startParameter.showStacktrace.name()
|
|
|
|
assert ["INTERNAL_EXCEPTIONS", "ALWAYS", "ALWAYS_FULL"].contains(showStacktraceName)
|
|
|
|
if (showStacktraceName.equals("ALWAYS")) {
|
2018-01-16 13:45:42 -05:00
|
|
|
args "--stacktrace"
|
2018-01-08 21:47:41 -05:00
|
|
|
} else if (showStacktraceName.equals("ALWAYS_FULL")) {
|
2018-01-16 13:45:42 -05:00
|
|
|
args "--full-stacktrace"
|
2018-01-08 21:47:41 -05:00
|
|
|
}
|
2017-05-30 09:04:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
artifacts {
|
|
|
|
'default' file: bwcZip, name: 'x-pack', type: 'zip', builtBy: buildBwcVersion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|