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-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-11-01 11:43:57 -04:00
|
|
|
import org.elasticsearch.gradle.VersionCollection
|
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
|
2018-11-01 11:43:57 -04:00
|
|
|
|
2017-03-24 01:32:13 -04:00
|
|
|
/**
|
2018-11-01 11:43:57 -04:00
|
|
|
* We want to be able to do BWC tests for unreleased versions without relying on and waiting for snapshots.
|
|
|
|
* For this we need to check out and build the unreleased versions.
|
|
|
|
* Since These depend on the current version, we can't name the Gradle projects statically, and don't know what the
|
|
|
|
* unreleased versions are when Gradle projects are set up, so we use "build-unreleased-version-*" as placeholders
|
|
|
|
* and configure them to build various versions here.
|
2017-03-24 01:32:13 -04:00
|
|
|
*/
|
2018-11-01 11:43:57 -04:00
|
|
|
bwcVersions.forPreviousUnreleased { VersionCollection.UnreleasedVersionInfo unreleasedVersion -> project("${project.path}:${unreleasedVersion.gradleProjectName}") {
|
|
|
|
Version bwcVersion = unreleasedVersion.version
|
|
|
|
String bwcBranch = unreleasedVersion.branch
|
|
|
|
apply plugin: 'distribution'
|
|
|
|
// Not published so no need to assemble
|
|
|
|
assemble.enabled = false
|
|
|
|
|
|
|
|
File checkoutDir = file("${buildDir}/bwc/checkout-${bwcBranch}")
|
|
|
|
|
|
|
|
final String remote = System.getProperty("tests.bwc.remote", "elastic")
|
|
|
|
|
2018-12-05 07:06:11 -05:00
|
|
|
boolean gitFetchLatest
|
2018-11-01 11:43:57 -04:00
|
|
|
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-08-28 17:10:06 -04:00
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
|
|
|
|
task createClone(type: LoggedExec) {
|
|
|
|
onlyIf { checkoutDir.exists() == false }
|
|
|
|
commandLine = ['git', 'clone', rootDir, checkoutDir]
|
2018-02-23 11:03:17 -05:00
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-16 13:45:13 -05:00
|
|
|
}
|
2018-10-05 03:46:00 -04:00
|
|
|
|
2018-11-01 11:43:57 -04:00
|
|
|
task addRemote(type: LoggedExec) {
|
|
|
|
dependsOn findRemote
|
|
|
|
onlyIf { project.ext.remoteExists == false }
|
|
|
|
workingDir = checkoutDir
|
|
|
|
commandLine = ['git', 'remote', 'add', "${remote}", "https://github.com/${remote}/elasticsearch.git"]
|
2018-01-09 05:58:16 -05:00
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
|
|
|
|
task fetchLatest(type: LoggedExec) {
|
|
|
|
onlyIf { project.gradle.startParameter.isOffline() == false && gitFetchLatest }
|
|
|
|
dependsOn addRemote
|
|
|
|
workingDir = checkoutDir
|
|
|
|
commandLine = ['git', 'fetch', '--all']
|
2018-10-09 17:07:51 -04:00
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
|
|
|
|
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}"
|
|
|
|
}
|
2018-02-23 11:03:17 -05:00
|
|
|
}
|
2018-11-01 11:43:57 -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)
|
|
|
|
String commit = output.toString('UTF-8')
|
|
|
|
buildMetadataFile.setText("${buildMetadataKey}=${commit}", 'UTF-8')
|
|
|
|
println "Checked out elasticsearch commit ${commit}"
|
|
|
|
}
|
2018-01-08 21:47:22 -05:00
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
|
2019-01-24 02:41:21 -05:00
|
|
|
Map<String, File> artifactFiles = [:]
|
2018-11-01 11:43:57 -04:00
|
|
|
List<String> projectDirs = []
|
2019-01-29 14:18:30 -05:00
|
|
|
List<String> projects = ['deb', 'rpm']
|
|
|
|
if (bwcVersion.onOrAfter('7.0.0')) {
|
|
|
|
projects.addAll(['windows-zip', 'darwin-tar', 'linux-tar'])
|
|
|
|
} else {
|
|
|
|
projects.add('zip')
|
|
|
|
}
|
|
|
|
|
2019-01-24 02:41:21 -05:00
|
|
|
for (String projectName : projects) {
|
2018-11-01 11:43:57 -04:00
|
|
|
String baseDir = "distribution"
|
2019-01-29 14:18:30 -05:00
|
|
|
String classifier = ""
|
|
|
|
String extension = projectName
|
|
|
|
if (bwcVersion.onOrAfter('7.0.0') && (projectName.contains('zip') || projectName.contains('tar'))) {
|
|
|
|
int index = projectName.indexOf('-')
|
|
|
|
classifier = "-${projectName.substring(0, index)}-x86_64"
|
|
|
|
extension = projectName.substring(index + 1)
|
|
|
|
if (extension.equals('tar')) {
|
|
|
|
extension += '.gz'
|
|
|
|
}
|
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
if (bwcVersion.onOrAfter('6.3.0')) {
|
2019-01-29 14:18:30 -05:00
|
|
|
baseDir += projectName.endsWith('zip') || projectName.endsWith('tar') ? '/archives' : '/packages'
|
2018-11-01 11:43:57 -04:00
|
|
|
// add oss variant first
|
2019-01-24 02:41:21 -05:00
|
|
|
projectDirs.add("${baseDir}/oss-${projectName}")
|
2019-01-29 14:18:30 -05:00
|
|
|
artifactFiles.put("oss-" + projectName, file("${checkoutDir}/${baseDir}/oss-${projectName}/build/distributions/elasticsearch-oss-${bwcVersion}-SNAPSHOT${classifier}.${extension}"))
|
2018-11-01 11:43:57 -04:00
|
|
|
}
|
2019-01-24 02:41:21 -05:00
|
|
|
projectDirs.add("${baseDir}/${projectName}")
|
2019-01-29 14:18:30 -05:00
|
|
|
artifactFiles.put(projectName,
|
|
|
|
file("${checkoutDir}/${baseDir}/${projectName}/build/distributions/elasticsearch-${bwcVersion}-SNAPSHOT${classifier}.${extension}"))
|
2018-01-08 21:47:22 -05:00
|
|
|
}
|
2019-01-25 07:14:12 -05:00
|
|
|
|
|
|
|
Closure createRunBwcGradleTask = { name, extraConfig ->
|
|
|
|
task "$name"(type: Exec) {
|
|
|
|
dependsOn checkoutBwcBranch, writeBuildMetadata
|
|
|
|
workingDir = checkoutDir
|
|
|
|
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-11-01 11:43:57 -04:00
|
|
|
|
2019-01-25 07:14:12 -05:00
|
|
|
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
|
|
executable 'cmd'
|
|
|
|
args '/C', 'call', new File(checkoutDir, 'gradlew').toString()
|
|
|
|
} else {
|
|
|
|
executable new File(checkoutDir, 'gradlew').toString()
|
|
|
|
}
|
|
|
|
if (gradle.startParameter.isOffline()) {
|
|
|
|
args "--offline"
|
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
|
2019-01-25 07:14:12 -05:00
|
|
|
args "-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"
|
|
|
|
}
|
|
|
|
standardOutput = new IndentingOutputStream(System.out, bwcVersion)
|
|
|
|
errorOutput = new IndentingOutputStream(System.err, bwcVersion)
|
|
|
|
configure extraConfig
|
2018-11-01 11:43:57 -04:00
|
|
|
}
|
2019-01-25 07:14:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
createRunBwcGradleTask("buildBwcVersion") {
|
2018-11-01 11:43:57 -04:00
|
|
|
for (String dir : projectDirs) {
|
|
|
|
args ":${dir.replace('/', ':')}:assemble"
|
|
|
|
}
|
|
|
|
doLast {
|
2019-01-24 02:41:21 -05:00
|
|
|
List missing = artifactFiles.values().grep { file ->
|
2018-11-01 11:43:57 -04:00
|
|
|
false == file.exists()
|
|
|
|
}
|
|
|
|
if (false == missing.empty) {
|
2019-01-25 07:14:12 -05:00
|
|
|
throw new InvalidUserDataException("Building ${bwcVersion} didn't generate expected files ${missing}")
|
2018-11-01 11:43:57 -04:00
|
|
|
}
|
|
|
|
}
|
2017-08-10 14:30:00 -04:00
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
|
2019-01-25 07:14:12 -05:00
|
|
|
createRunBwcGradleTask("resolveAllBwcDependencies") {
|
|
|
|
args 'resolveAllDependencies'
|
|
|
|
}
|
|
|
|
|
|
|
|
resolveAllDependencies.dependsOn resolveAllBwcDependencies
|
|
|
|
|
2019-01-24 02:41:21 -05:00
|
|
|
for (e in artifactFiles) {
|
|
|
|
String projectName = e.key
|
|
|
|
File artifactFile = e.value
|
|
|
|
String artifactFileName = artifactFile.name
|
|
|
|
String artifactName = artifactFileName.contains('oss') ? 'elasticsearch-oss' : 'elasticsearch'
|
2019-01-09 13:57:26 -05:00
|
|
|
String suffix = artifactFile.toString()[-3..-1]
|
2019-01-29 14:18:30 -05:00
|
|
|
int archIndex = artifactFileName.indexOf('x86_64')
|
|
|
|
String classifier = ''
|
|
|
|
if (archIndex != -1) {
|
|
|
|
int osIndex = artifactFileName.lastIndexOf('-', archIndex - 2)
|
|
|
|
classifier = "${artifactFileName.substring(osIndex + 1, archIndex - 1)}-x86_64"
|
|
|
|
}
|
2019-01-24 02:41:21 -05:00
|
|
|
configurations.create(projectName)
|
|
|
|
artifacts {
|
2019-01-29 14:18:30 -05:00
|
|
|
it.add(projectName, [file: artifactFile, name: artifactName, classifier: classifier, type: suffix, builtBy: buildBwcVersion])
|
2019-01-24 02:41:21 -05:00
|
|
|
}
|
2018-02-23 11:03:17 -05:00
|
|
|
}
|
2019-01-09 13:57:26 -05:00
|
|
|
// make sure no dependencies were added to assemble; we want it to be a no-op
|
|
|
|
assemble.dependsOn = []
|
2018-11-01 11:43:57 -04:00
|
|
|
}}
|
2018-07-04 23:24:01 -04:00
|
|
|
|
|
|
|
class IndentingOutputStream extends OutputStream {
|
|
|
|
|
2018-11-01 11:43:57 -04:00
|
|
|
public final byte[] indent
|
|
|
|
private final OutputStream delegate
|
2018-07-04 23:24:01 -04:00
|
|
|
|
2018-11-01 11:43:57 -04:00
|
|
|
public IndentingOutputStream(OutputStream delegate, Object version) {
|
|
|
|
this.delegate = delegate
|
|
|
|
indent = " [${version}] ".getBytes(StandardCharsets.UTF_8)
|
|
|
|
}
|
2018-07-04 23:24:01 -04:00
|
|
|
|
2018-11-01 11:43:57 -04:00
|
|
|
@Override
|
|
|
|
public void write(int b) {
|
|
|
|
write([b] as int[], 0, 1)
|
|
|
|
}
|
2018-07-04 23:24:01 -04:00
|
|
|
|
2018-11-01 11:43:57 -04:00
|
|
|
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-07-04 23:24:01 -04:00
|
|
|
}
|
2019-01-09 13:57:26 -05:00
|
|
|
}
|