179 lines
6.6 KiB
Groovy
179 lines
6.6 KiB
Groovy
/*
|
|
* Licensed to Elasticsearch under one or more contributor
|
|
* license agreements. See the NOTICE file distributed with
|
|
* this work for additional information regarding copyright
|
|
* ownership. Elasticsearch licenses this file to you under
|
|
* the Apache License, Version 2.0 (the "License"); you may
|
|
* not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing,
|
|
* software distributed under the License is distributed on an
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
* KIND, either express or implied. See the License for the
|
|
* specific language governing permissions and limitations
|
|
* under the License.
|
|
*/
|
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
|
import org.elasticsearch.gradle.LoggedExec
|
|
import org.elasticsearch.gradle.Version
|
|
|
|
import java.util.regex.Matcher
|
|
|
|
/**
|
|
* This is a dummy project which does a local checkout of the previous
|
|
* wire compat version's branch, and builds a snapshot. This allows backcompat
|
|
* tests to test against the next unreleased version, closest to this version,
|
|
* without relying on snapshots.
|
|
*/
|
|
subprojects {
|
|
|
|
Version bwcVersion = bwcVersions.getSnapshotForProject(project.name)
|
|
if (bwcVersion == null) {
|
|
// this project wont do anything
|
|
return
|
|
}
|
|
|
|
String bwcBranch
|
|
if (project.name == 'next-minor-snapshot') {
|
|
// this is always a .x series
|
|
bwcBranch = "${bwcVersion.major}.x"
|
|
} else {
|
|
bwcBranch = "${bwcVersion.major}.${bwcVersion.minor}"
|
|
}
|
|
|
|
apply plugin: 'distribution'
|
|
// Not published so no need to assemble
|
|
tasks.remove(assemble)
|
|
build.dependsOn.remove('assemble')
|
|
|
|
File checkoutDir = file("${buildDir}/bwc/checkout-${bwcBranch}")
|
|
|
|
final String remote = System.getProperty("tests.bwc.remote", "elastic")
|
|
|
|
task createClone(type: LoggedExec) {
|
|
onlyIf { checkoutDir.exists() == false }
|
|
commandLine = ['git', 'clone', rootDir, checkoutDir]
|
|
}
|
|
|
|
task findRemote(type: LoggedExec) {
|
|
dependsOn createClone
|
|
workingDir = checkoutDir
|
|
commandLine = ['git', 'remote', '-v']
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream()
|
|
standardOutput = output
|
|
doLast {
|
|
project.ext.remoteExists = false
|
|
output.toString('UTF-8').eachLine {
|
|
if (it.contains("${remote}\t")) {
|
|
project.ext.remoteExists = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
task addRemote(type: LoggedExec) {
|
|
dependsOn findRemote
|
|
onlyIf { project.ext.remoteExists == false }
|
|
workingDir = checkoutDir
|
|
commandLine = ['git', 'remote', 'add', "${remote}", "https://github.com/${remote}/elasticsearch.git"]
|
|
}
|
|
|
|
task fetchLatest(type: LoggedExec) {
|
|
onlyIf { project.gradle.startParameter.isOffline() == false }
|
|
dependsOn addRemote
|
|
workingDir = checkoutDir
|
|
commandLine = ['git', 'fetch', '--all']
|
|
}
|
|
|
|
String buildMetadataKey = "bwc_refspec_${project.path.substring(1)}"
|
|
task checkoutBwcBranch(type: LoggedExec) {
|
|
String refspec = System.getProperty("tests.bwc.refspec.${bwcBranch}", buildMetadata.get(buildMetadataKey, "${remote}/${bwcBranch}"))
|
|
dependsOn fetchLatest
|
|
workingDir = checkoutDir
|
|
commandLine = ['git', 'checkout', refspec]
|
|
doFirst {
|
|
println "Checking out elasticsearch ${refspec} for branch ${bwcBranch}"
|
|
}
|
|
}
|
|
|
|
File buildMetadataFile = project.file("build/${project.name}/build_metadata")
|
|
task writeBuildMetadata(type: LoggedExec) {
|
|
dependsOn checkoutBwcBranch
|
|
workingDir = checkoutDir
|
|
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(buildMetadataFile.parent)
|
|
String commit = output.toString('UTF-8')
|
|
buildMetadataFile.setText("${buildMetadataKey}=${commit}", 'UTF-8')
|
|
println "Checked out elasticsearch commit ${commit}"
|
|
}
|
|
}
|
|
|
|
String debDir = 'distribution/packages/deb'
|
|
String rpmDir = 'distribution/packages/rpm'
|
|
String zipDir = 'distribution/archives/zip'
|
|
if (bwcVersion.before('6.3.0')) {
|
|
debDir = 'distribution/deb'
|
|
rpmDir = 'distribution/rpm'
|
|
zipDir = 'distribution/zip'
|
|
}
|
|
File bwcDeb = file("${checkoutDir}/${debDir}/build/distributions/elasticsearch-${bwcVersion}.deb")
|
|
File bwcRpm = file("${checkoutDir}/${rpmDir}/build/distributions/elasticsearch-${bwcVersion}.rpm")
|
|
File bwcZip = file("${checkoutDir}/${zipDir}/build/distributions/elasticsearch-${bwcVersion}.zip")
|
|
task buildBwcVersion(type: Exec) {
|
|
dependsOn checkoutBwcBranch, writeBuildMetadata
|
|
workingDir = checkoutDir
|
|
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'))
|
|
}
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
executable 'cmd'
|
|
args '/C', 'call', new File(checkoutDir, 'gradlew').toString()
|
|
} else {
|
|
executable new File(checkoutDir, 'gradlew').toString()
|
|
}
|
|
args ":${debDir.replace('/', ':')}:assemble", ":${rpmDir.replace('/', ':')}:assemble", ":${zipDir.replace('/', ':')}:assemble", "-Dbuild.snapshot=true"
|
|
final LogLevel logLevel = gradle.startParameter.logLevel
|
|
if ([LogLevel.QUIET, LogLevel.WARN, LogLevel.INFO, LogLevel.DEBUG].contains(logLevel)) {
|
|
args "--${logLevel.name().toLowerCase(Locale.ENGLISH)}"
|
|
}
|
|
final String showStacktraceName = gradle.startParameter.showStacktrace.name()
|
|
assert ["INTERNAL_EXCEPTIONS", "ALWAYS", "ALWAYS_FULL"].contains(showStacktraceName)
|
|
if (showStacktraceName.equals("ALWAYS")) {
|
|
args "--stacktrace"
|
|
} else if (showStacktraceName.equals("ALWAYS_FULL")) {
|
|
args "--full-stacktrace"
|
|
}
|
|
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}")
|
|
}
|
|
}
|
|
}
|
|
|
|
artifacts {
|
|
'default' file: bwcDeb, name: 'elasticsearch', type: 'deb', builtBy: buildBwcVersion
|
|
'default' file: bwcRpm, name: 'elasticsearch', type: 'rpm', builtBy: buildBwcVersion
|
|
'default' file: bwcZip, name: 'elasticsearch', type: 'zip', builtBy: buildBwcVersion
|
|
}
|
|
}
|