2017-03-24 01:32:13 -04:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2018-04-14 15:44:43 -04:00
|
|
|
|
2018-07-04 23:24:01 -04:00
|
|
|
|
2018-01-09 05:58:16 -05:00
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os
|
2017-03-24 01:32:13 -04:00
|
|
|
import org.elasticsearch.gradle.LoggedExec
|
2017-11-21 03:26:45 -05:00
|
|
|
import org.elasticsearch.gradle.Version
|
2018-01-16 13:45:13 -05:00
|
|
|
|
2018-07-04 23:24:01 -04:00
|
|
|
import java.nio.charset.StandardCharsets
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2018-07-04 23:24:01 -04:00
|
|
|
import static org.elasticsearch.gradle.BuildPlugin.getJavaHome
|
2017-03-24 01:32:13 -04:00
|
|
|
/**
|
2017-05-17 15:58:37 -04:00
|
|
|
* 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.
|
2017-03-24 01:32:13 -04:00
|
|
|
*/
|
2018-02-09 15:55:10 -05:00
|
|
|
subprojects {
|
2017-11-21 03:26:45 -05:00
|
|
|
|
2018-02-09 15:55:10 -05:00
|
|
|
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}"
|
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2017-05-17 15:58:37 -04:00
|
|
|
apply plugin: 'distribution'
|
2017-06-16 17:16:03 -04:00
|
|
|
// Not published so no need to assemble
|
2018-09-04 00:32:14 -04:00
|
|
|
assemble.enabled = false
|
2018-09-05 01:24:44 -04:00
|
|
|
assemble.dependsOn.remove('buildBwcVersion')
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2017-05-17 15:58:37 -04:00
|
|
|
File checkoutDir = file("${buildDir}/bwc/checkout-${bwcBranch}")
|
2017-05-29 10:22:32 -04:00
|
|
|
|
2017-10-07 13:40:18 -04:00
|
|
|
final String remote = System.getProperty("tests.bwc.remote", "elastic")
|
|
|
|
|
2018-04-13 09:31:06 -04:00
|
|
|
final boolean gitFetchLatest
|
|
|
|
final String gitFetchLatestProperty = System.getProperty("tests.bwc.git_fetch_latest", "true")
|
|
|
|
if ("true".equals(gitFetchLatestProperty)) {
|
|
|
|
gitFetchLatest = true
|
|
|
|
} else if ("false".equals(gitFetchLatestProperty)) {
|
|
|
|
gitFetchLatest = false
|
|
|
|
} else {
|
|
|
|
throw new GradleException("tests.bwc.git_fetch_latest must be [true] or [false] but was [" + gitFetchLatestProperty + "]")
|
|
|
|
}
|
|
|
|
|
2017-05-17 15:58:37 -04:00
|
|
|
task createClone(type: LoggedExec) {
|
|
|
|
onlyIf { checkoutDir.exists() == false }
|
|
|
|
commandLine = ['git', 'clone', rootDir, checkoutDir]
|
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2017-10-07 13:40:18 -04:00
|
|
|
task findRemote(type: LoggedExec) {
|
2017-05-17 15:58:37 -04:00
|
|
|
dependsOn createClone
|
|
|
|
workingDir = checkoutDir
|
|
|
|
commandLine = ['git', 'remote', '-v']
|
2017-11-08 15:27:15 -05:00
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream()
|
|
|
|
standardOutput = output
|
2017-05-17 15:58:37 -04:00
|
|
|
doLast {
|
2017-10-07 13:40:18 -04:00
|
|
|
project.ext.remoteExists = false
|
2017-05-17 15:58:37 -04:00
|
|
|
output.toString('UTF-8').eachLine {
|
2018-02-13 15:54:11 -05:00
|
|
|
if (it.contains("${remote}\t")) {
|
2017-10-07 13:40:18 -04:00
|
|
|
project.ext.remoteExists = true
|
2017-05-17 15:58:37 -04:00
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-07 13:40:18 -04:00
|
|
|
task addRemote(type: LoggedExec) {
|
|
|
|
dependsOn findRemote
|
|
|
|
onlyIf { project.ext.remoteExists == false }
|
2017-05-17 15:58:37 -04:00
|
|
|
workingDir = checkoutDir
|
2017-10-07 13:40:18 -04:00
|
|
|
commandLine = ['git', 'remote', 'add', "${remote}", "https://github.com/${remote}/elasticsearch.git"]
|
2017-05-17 15:58:37 -04:00
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2017-05-17 15:58:37 -04:00
|
|
|
task fetchLatest(type: LoggedExec) {
|
2018-04-13 09:31:06 -04:00
|
|
|
onlyIf { project.gradle.startParameter.isOffline() == false && gitFetchLatest }
|
2017-10-07 13:40:18 -04:00
|
|
|
dependsOn addRemote
|
2017-05-17 15:58:37 -04:00
|
|
|
workingDir = checkoutDir
|
2017-07-07 07:39:24 -04:00
|
|
|
commandLine = ['git', 'fetch', '--all']
|
2017-05-17 15:58:37 -04:00
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2017-08-28 17:10:06 -04:00
|
|
|
String buildMetadataKey = "bwc_refspec_${project.path.substring(1)}"
|
2017-08-30 14:01:17 -04:00
|
|
|
task checkoutBwcBranch(type: LoggedExec) {
|
2018-03-29 14:59:52 -04:00
|
|
|
String refspec = System.getProperty("tests.bwc.refspec.${bwcBranch}", buildMetadata.get(buildMetadataKey, "${remote}/${bwcBranch}"))
|
2017-05-17 15:58:37 -04:00
|
|
|
dependsOn fetchLatest
|
|
|
|
workingDir = checkoutDir
|
2017-07-07 05:18:03 -04:00
|
|
|
commandLine = ['git', 'checkout', refspec]
|
2017-08-30 14:01:17 -04:00
|
|
|
doFirst {
|
|
|
|
println "Checking out elasticsearch ${refspec} for branch ${bwcBranch}"
|
|
|
|
}
|
2017-05-17 15:58:37 -04:00
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2017-08-28 17:10:06 -04:00
|
|
|
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)
|
2017-08-30 14:01:17 -04:00
|
|
|
String commit = output.toString('UTF-8')
|
|
|
|
buildMetadataFile.setText("${buildMetadataKey}=${commit}", 'UTF-8')
|
|
|
|
println "Checked out elasticsearch commit ${commit}"
|
2017-08-28 17:10:06 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-23 11:03:17 -05:00
|
|
|
List<File> artifactFiles = []
|
|
|
|
List<String> projectDirs = []
|
|
|
|
for (String project : ['zip', 'deb', 'rpm']) {
|
|
|
|
String baseDir = "distribution"
|
|
|
|
if (bwcVersion.onOrAfter('6.3.0')) {
|
|
|
|
baseDir += project == 'zip' ? '/archives' : '/packages'
|
|
|
|
// add oss variant first
|
|
|
|
projectDirs.add("${baseDir}/oss-${project}")
|
|
|
|
artifactFiles.add(file("${checkoutDir}/${baseDir}/oss-${project}/build/distributions/elasticsearch-oss-${bwcVersion}.${project}"))
|
|
|
|
}
|
|
|
|
projectDirs.add("${baseDir}/${project}")
|
|
|
|
artifactFiles.add(file("${checkoutDir}/${baseDir}/${project}/build/distributions/elasticsearch-${bwcVersion}.${project}"))
|
2018-02-14 01:49:53 -05:00
|
|
|
}
|
2018-02-23 11:03:17 -05:00
|
|
|
|
2018-01-08 21:47:22 -05:00
|
|
|
task buildBwcVersion(type: Exec) {
|
2017-08-28 17:10:06 -04:00
|
|
|
dependsOn checkoutBwcBranch, writeBuildMetadata
|
2018-01-08 21:47:22 -05:00
|
|
|
workingDir = checkoutDir
|
2018-10-05 03:46:00 -04:00
|
|
|
doFirst {
|
|
|
|
// Execution time so that the checkouts are available
|
|
|
|
List<String> lines = file("$checkoutDir/.ci/java-versions.properties").readLines()
|
|
|
|
environment(
|
|
|
|
'JAVA_HOME',
|
|
|
|
getJavaHome(it, Integer.parseInt(
|
|
|
|
lines
|
|
|
|
.findAll({ it.startsWith("ES_BUILD_JAVA=java") })
|
|
|
|
.collect({ it.replace("ES_BUILD_JAVA=java", "").trim() })
|
|
|
|
.join("!!")
|
|
|
|
))
|
|
|
|
)
|
|
|
|
environment(
|
|
|
|
'RUNTIME_JAVA_HOME',
|
|
|
|
getJavaHome(it, Integer.parseInt(
|
|
|
|
lines
|
|
|
|
.findAll({ it.startsWith("ES_RUNTIME_JAVA=java") })
|
|
|
|
.collect({ it.replace("ES_RUNTIME_JAVA=java", "").trim() })
|
|
|
|
.join("!!")
|
|
|
|
))
|
|
|
|
)
|
2018-01-16 13:45:13 -05:00
|
|
|
}
|
2018-10-05 03:46:00 -04:00
|
|
|
|
2018-01-09 05:58:16 -05:00
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
|
executable 'cmd'
|
|
|
|
args '/C', 'call', new File(checkoutDir, 'gradlew').toString()
|
|
|
|
} else {
|
2018-01-16 13:45:13 -05:00
|
|
|
executable new File(checkoutDir, 'gradlew').toString()
|
2018-01-09 05:58:16 -05:00
|
|
|
}
|
2018-10-09 17:07:51 -04:00
|
|
|
if (gradle.startParameter.isOffline()) {
|
|
|
|
args "--offline"
|
|
|
|
}
|
2018-02-23 11:03:17 -05:00
|
|
|
for (String dir : projectDirs) {
|
|
|
|
args ":${dir.replace('/', ':')}:assemble"
|
|
|
|
}
|
|
|
|
args "-Dbuild.snapshot=true"
|
2018-01-08 21:47:22 -05:00
|
|
|
final LogLevel logLevel = gradle.startParameter.logLevel
|
|
|
|
if ([LogLevel.QUIET, LogLevel.WARN, LogLevel.INFO, LogLevel.DEBUG].contains(logLevel)) {
|
2018-01-16 13:45:13 -05:00
|
|
|
args "--${logLevel.name().toLowerCase(Locale.ENGLISH)}"
|
2018-01-08 21:47:22 -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:13 -05:00
|
|
|
args "--stacktrace"
|
2018-01-08 21:47:22 -05:00
|
|
|
} else if (showStacktraceName.equals("ALWAYS_FULL")) {
|
2018-01-16 13:45:13 -05:00
|
|
|
args "--full-stacktrace"
|
2018-01-08 21:47:22 -05:00
|
|
|
}
|
2018-07-04 23:24:01 -04:00
|
|
|
standardOutput = new IndentingOutputStream(System.out)
|
|
|
|
errorOutput = new IndentingOutputStream(System.err)
|
2017-08-10 14:30:00 -04:00
|
|
|
doLast {
|
2018-02-23 11:03:17 -05:00
|
|
|
List missing = artifactFiles.grep { file ->
|
2018-01-08 21:47:22 -05:00
|
|
|
false == file.exists()
|
|
|
|
}
|
2017-08-10 14:30:00 -04:00
|
|
|
if (false == missing.empty) {
|
|
|
|
throw new InvalidUserDataException(
|
2018-01-08 21:47:22 -05:00
|
|
|
"Building bwc version didn't generate expected files ${missing}")
|
2017-08-10 14:30:00 -04:00
|
|
|
}
|
|
|
|
}
|
2017-05-17 15:58:37 -04:00
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
|
2018-09-05 01:24:44 -04:00
|
|
|
if (gradle.startParameter.taskNames == ["assemble"]) {
|
|
|
|
// Gradle needs the `artifacts` declaration, including `builtBy` bellow to make projects dependencies on this
|
|
|
|
// project work, but it will also trigger the build of these for the `assemble` task.
|
|
|
|
// Since these are only used for testing, we don't want to assemble them if `assemble` is the single command being
|
|
|
|
// ran.
|
|
|
|
logger.info("Skipping BWC builds since `assemble` is the only task name provided on the command line")
|
|
|
|
} else {
|
|
|
|
artifacts {
|
|
|
|
for (File artifactFile : artifactFiles) {
|
|
|
|
String artifactName = artifactFile.name.contains('oss') ? 'elasticsearch-oss' : 'elasticsearch'
|
|
|
|
String suffix = artifactFile.toString()[-3..-1]
|
|
|
|
'default' file: artifactFile, name: artifactName, type: suffix, builtBy: buildBwcVersion
|
|
|
|
}
|
2018-02-23 11:03:17 -05:00
|
|
|
}
|
2017-05-17 15:58:37 -04:00
|
|
|
}
|
2017-03-24 01:32:13 -04:00
|
|
|
}
|
2018-07-04 23:24:01 -04:00
|
|
|
|
|
|
|
class IndentingOutputStream extends OutputStream {
|
|
|
|
|
|
|
|
public static final byte[] INDENT = " [bwc] ".getBytes(StandardCharsets.UTF_8)
|
|
|
|
private final OutputStream delegate
|
|
|
|
|
|
|
|
public IndentingOutputStream(OutputStream delegate) {
|
|
|
|
this.delegate = delegate
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void write(int b) {
|
|
|
|
write([b] as int[], 0, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
public void write(int[] bytes, int offset, int length) {
|
|
|
|
for (int i = 0; i < bytes.length; i++) {
|
|
|
|
delegate.write(bytes[i])
|
|
|
|
if (bytes[i] == '\n') {
|
|
|
|
delegate.write(INDENT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-05 03:46:00 -04:00
|
|
|
}
|