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
|
2019-03-07 06:54:20 -05:00
|
|
|
import org.elasticsearch.gradle.BwcVersions
|
2019-11-01 14:33:11 -04:00
|
|
|
import org.elasticsearch.gradle.info.BuildParams
|
2019-08-20 03:01:03 -04:00
|
|
|
import org.elasticsearch.gradle.info.GlobalBuildInfoPlugin
|
2019-12-12 17:52:36 -05:00
|
|
|
import org.gradle.util.GradleVersion
|
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
|
|
|
|
2020-04-27 15:42:50 -04:00
|
|
|
import static org.elasticsearch.gradle.util.JavaUtil.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
|
|
|
*/
|
2020-05-11 03:39:13 -04:00
|
|
|
BuildParams.bwcVersions.forPreviousUnreleased { BwcVersions.UnreleasedVersionInfo unreleasedVersion ->
|
2019-11-14 06:01:23 -05:00
|
|
|
project("${unreleasedVersion.gradleProjectPath}") {
|
2018-11-01 11:43:57 -04:00
|
|
|
Version bwcVersion = unreleasedVersion.version
|
|
|
|
String bwcBranch = unreleasedVersion.branch
|
|
|
|
apply plugin: 'distribution'
|
|
|
|
// Not published so no need to assemble
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("assemble").configure {
|
|
|
|
enabled = false
|
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
File checkoutDir = file("${buildDir}/bwc/checkout-${bwcBranch}")
|
|
|
|
|
2019-08-16 11:43:14 -04:00
|
|
|
final String remote = System.getProperty("bwc.remote", "elastic")
|
2018-11-01 11:43:57 -04:00
|
|
|
|
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)) {
|
2019-11-14 06:01:23 -05:00
|
|
|
gitFetchLatest = true
|
2018-11-01 11:43:57 -04:00
|
|
|
} else if ("false".equals(gitFetchLatestProperty)) {
|
2019-11-14 06:01:23 -05:00
|
|
|
gitFetchLatest = false
|
2018-11-01 11:43:57 -04:00
|
|
|
} else {
|
2019-11-14 06:01:23 -05:00
|
|
|
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
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("createClone", LoggedExec) {
|
2019-11-14 06:01:23 -05:00
|
|
|
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
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("findRemote", LoggedExec) {
|
|
|
|
dependsOn "createClone"
|
2019-11-14 06:01:23 -05:00
|
|
|
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-11-01 11:43:57 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
2018-01-16 13:45:13 -05:00
|
|
|
}
|
2018-10-05 03:46:00 -04:00
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("addRemote", LoggedExec) {
|
2019-11-14 06:01:23 -05:00
|
|
|
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
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("fetchLatest", LoggedExec) {
|
2019-11-14 06:01:23 -05:00
|
|
|
onlyIf { project.gradle.startParameter.isOffline() == false && gitFetchLatest }
|
2020-07-31 07:09:04 -04:00
|
|
|
dependsOn("addRemote")
|
2019-11-14 06:01:23 -05:00
|
|
|
workingDir = checkoutDir
|
|
|
|
commandLine = ['git', 'fetch', '--all']
|
2018-10-09 17:07:51 -04:00
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
Closure execGit = { Action<ExecSpec> action ->
|
|
|
|
new ByteArrayOutputStream().withStream { os ->
|
|
|
|
ExecResult result = project.exec { spec ->
|
|
|
|
workingDir = checkoutDir
|
|
|
|
standardOutput os
|
|
|
|
action.execute(spec)
|
2018-11-01 11:43:57 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
result.assertNormalExitValue()
|
|
|
|
return os.toString().trim()
|
|
|
|
}
|
2018-02-23 11:03:17 -05:00
|
|
|
}
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.register("checkoutBwcBranch") {
|
|
|
|
dependsOn("fetchLatest")
|
2019-11-14 06:01:23 -05:00
|
|
|
doLast {
|
2020-06-04 08:56:41 -04:00
|
|
|
def refspec = System.getProperty("bwc.refspec." + bwcBranch) ?: System.getProperty("tests.bwc.refspec." + bwcBranch) ?: "${remote}/${bwcBranch}"
|
2019-11-14 06:01:23 -05:00
|
|
|
if (System.getProperty("bwc.checkout.align") != null) {
|
|
|
|
/*
|
|
|
|
We use a time based approach to make the bwc versions built deterministic and compatible with the current hash.
|
|
|
|
Most of the time we want to test against latest, but when running delayed exhaustive tests or wanting
|
|
|
|
reproducible builds we want this to be deterministic by using a hash that was the latest when the current
|
|
|
|
commit was made.
|
|
|
|
|
|
|
|
This approach doesn't work with merge commits as these can introduce commits in the chronological order
|
|
|
|
after the fact e.x. a merge done today can add commits dated with yesterday so the result will no longer be
|
|
|
|
deterministic.
|
|
|
|
|
|
|
|
We don't use merge commits, but for additional safety we check that no such commits exist in the time period
|
|
|
|
we are interested in.
|
|
|
|
|
|
|
|
Timestamps are at seconds resolution. rev-parse --before and --after are inclusive w.r.t the second
|
|
|
|
passed as input. This means the results might not be deterministic in the current second, but this
|
|
|
|
should not matter in practice.
|
|
|
|
*/
|
|
|
|
String timeOfCurrent = execGit { spec ->
|
|
|
|
spec.commandLine 'git', 'show', '--no-patch', '--no-notes', "--pretty='%cD'"
|
|
|
|
spec.workingDir project.rootDir
|
|
|
|
}
|
|
|
|
logger.lifecycle("Commit date of current: {}", timeOfCurrent)
|
|
|
|
String mergeCommits = execGit { spec ->
|
|
|
|
spec.commandLine "git", "rev-list", refspec, "--after", timeOfCurrent, "--merges"
|
|
|
|
}
|
|
|
|
if (mergeCommits.isEmpty() == false) {
|
|
|
|
throw new IllegalStateException(
|
|
|
|
"Found the following merge commits which prevent determining bwc commits: " + mergeCommits
|
|
|
|
)
|
|
|
|
}
|
|
|
|
refspec = execGit { spec ->
|
|
|
|
spec.commandLine "git", "rev-list", refspec, "-n", "1", "--before", timeOfCurrent, "--date-order"
|
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
|
|
|
|
logger.lifecycle("Performing checkout of ${refspec}...")
|
|
|
|
LoggedExec.exec(project) { spec ->
|
|
|
|
spec.workingDir = checkoutDir
|
|
|
|
spec.commandLine "git", "checkout", refspec
|
|
|
|
}
|
2020-04-08 19:47:02 -04:00
|
|
|
String checkoutHash = GlobalBuildInfoPlugin.gitInfo(checkoutDir).revision
|
2019-11-14 06:01:23 -05:00
|
|
|
logger.lifecycle("Checkout hash for ${project.path} is ${checkoutHash}")
|
|
|
|
file("${project.buildDir}/refspec").text = checkoutHash
|
|
|
|
}
|
2018-01-08 21:47:22 -05:00
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
|
2019-08-07 09:37:15 -04:00
|
|
|
|
2020-07-31 07:09:04 -04:00
|
|
|
Closure<TaskProvider> createRunBwcGradleTask = { name, extraConfig ->
|
2020-05-25 03:37:33 -04:00
|
|
|
return tasks.register("$name", LoggedExec) {
|
2020-07-31 07:09:04 -04:00
|
|
|
dependsOn "checkoutBwcBranch"
|
2019-11-14 06:01:23 -05:00
|
|
|
spoolOutput = true
|
|
|
|
workingDir = checkoutDir
|
|
|
|
doFirst {
|
|
|
|
// Execution time so that the checkouts are available
|
|
|
|
List<String> lines = file("${checkoutDir}/.ci/java-versions.properties").readLines()
|
|
|
|
environment(
|
|
|
|
'JAVA_HOME',
|
2020-04-27 15:42:50 -04:00
|
|
|
getJavaHome(Integer.parseInt(
|
2019-11-14 06:01:23 -05:00
|
|
|
lines
|
|
|
|
.findAll({ it.startsWith("ES_BUILD_JAVA=") })
|
|
|
|
.collect({ it.replace("ES_BUILD_JAVA=java", "").trim() })
|
|
|
|
.collect({ it.replace("ES_BUILD_JAVA=openjdk", "").trim() })
|
|
|
|
.join("!!")
|
|
|
|
))
|
|
|
|
)
|
|
|
|
environment(
|
|
|
|
'RUNTIME_JAVA_HOME',
|
2020-04-27 15:42:50 -04:00
|
|
|
getJavaHome(Integer.parseInt(
|
2019-11-14 06:01:23 -05:00
|
|
|
lines
|
|
|
|
.findAll({ it.startsWith("ES_RUNTIME_JAVA=java") })
|
|
|
|
.collect({ it.replace("ES_RUNTIME_JAVA=java", "").trim() })
|
|
|
|
.join("!!")
|
|
|
|
))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
2020-04-02 20:04:56 -04:00
|
|
|
String buildCacheUrl = System.getProperty('org.elasticsearch.build.cache.url')
|
|
|
|
if (buildCacheUrl) {
|
|
|
|
args "-Dorg.elasticsearch.build.cache.url=${buildCacheUrl}"
|
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
|
|
|
|
args "-Dbuild.snapshot=true"
|
2020-01-24 14:00:14 -05:00
|
|
|
args "-Dscan.tag.NESTED"
|
2019-11-14 06:01:23 -05:00
|
|
|
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"
|
2018-11-01 11:43:57 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
if (gradle.getStartParameter().isParallelProjectExecutionEnabled()) {
|
|
|
|
args "--parallel"
|
|
|
|
}
|
|
|
|
standardOutput = new IndentingOutputStream(System.out, bwcVersion)
|
|
|
|
errorOutput = new IndentingOutputStream(System.err, bwcVersion)
|
|
|
|
configure extraConfig
|
|
|
|
}
|
2019-01-25 07:14:12 -05:00
|
|
|
}
|
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
Closure buildBwcTaskName = { projectName ->
|
|
|
|
return "buildBwc${projectName.replaceAll(/-\w/) { it[1].toUpperCase() }.capitalize()}"
|
2019-04-10 13:43:01 -04:00
|
|
|
}
|
|
|
|
|
2020-05-25 03:37:33 -04:00
|
|
|
def buildBwc = tasks.register("buildBwc");
|
2019-04-10 13:43:01 -04:00
|
|
|
|
|
|
|
Closure createBuildBwcTask = { projectName, projectDir, projectArtifact ->
|
2020-05-25 03:37:33 -04:00
|
|
|
def bwcTaskName = buildBwcTaskName(projectName)
|
|
|
|
createRunBwcGradleTask(bwcTaskName) {
|
2019-11-14 06:01:23 -05:00
|
|
|
inputs.file("${project.buildDir}/refspec")
|
|
|
|
outputs.files(projectArtifact)
|
|
|
|
outputs.cacheIf("BWC distribution caching is disabled on 'master' branch") {
|
|
|
|
// Don't bother caching in 'master' since the BWC branches move too quickly to make this cost worthwhile
|
|
|
|
BuildParams.ci && System.getenv('GIT_BRANCH')?.endsWith("master") == false
|
|
|
|
}
|
|
|
|
args ":${projectDir.replace('/', ':')}:assemble"
|
|
|
|
if (project.gradle.startParameter.buildCacheEnabled) {
|
|
|
|
args "--build-cache"
|
|
|
|
}
|
|
|
|
doLast {
|
|
|
|
if (projectArtifact.exists() == false) {
|
|
|
|
throw new InvalidUserDataException("Building ${bwcVersion} didn't generate expected file ${projectArtifact}")
|
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
2020-05-25 03:37:33 -04:00
|
|
|
buildBwc.configure {
|
|
|
|
dependsOn(bwcTaskName)
|
|
|
|
}
|
2019-04-10 13:43:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, File> artifactFiles = [:]
|
|
|
|
List<String> projectDirs = []
|
|
|
|
List<String> projects = ['deb', 'rpm']
|
|
|
|
if (bwcVersion.onOrAfter('7.0.0')) {
|
|
|
|
projects.addAll(['windows-zip', 'darwin-tar', 'linux-tar'])
|
|
|
|
} else {
|
|
|
|
projects.add('zip')
|
2017-08-10 14:30:00 -04:00
|
|
|
}
|
2018-11-01 11:43:57 -04:00
|
|
|
|
2019-04-10 13:43:01 -04:00
|
|
|
for (String projectName : projects) {
|
2019-11-14 06:01:23 -05:00
|
|
|
String baseDir = "distribution"
|
|
|
|
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'
|
2019-04-10 13:43:01 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
|
|
|
if (bwcVersion.onOrAfter('7.0.0') && projectName.contains('deb')) {
|
|
|
|
classifier = "-amd64"
|
|
|
|
}
|
|
|
|
if (bwcVersion.onOrAfter('7.0.0') && projectName.contains('rpm')) {
|
|
|
|
classifier = "-x86_64"
|
|
|
|
}
|
|
|
|
if (bwcVersion.onOrAfter('6.3.0')) {
|
|
|
|
baseDir += projectName.endsWith('zip') || projectName.endsWith('tar') ? '/archives' : '/packages'
|
|
|
|
// add oss variant first
|
|
|
|
projectDirs.add("${baseDir}/oss-${projectName}")
|
|
|
|
File ossProjectArtifact = file("${checkoutDir}/${baseDir}/oss-${projectName}/build/distributions/elasticsearch-oss-${bwcVersion}-SNAPSHOT${classifier}.${extension}")
|
|
|
|
artifactFiles.put("oss-" + projectName, ossProjectArtifact)
|
|
|
|
createBuildBwcTask("oss-${projectName}", "${baseDir}/oss-${projectName}", ossProjectArtifact)
|
|
|
|
}
|
|
|
|
projectDirs.add("${baseDir}/${projectName}")
|
|
|
|
File projectArtifact = file("${checkoutDir}/${baseDir}/${projectName}/build/distributions/elasticsearch-${bwcVersion}-SNAPSHOT${classifier}.${extension}")
|
|
|
|
artifactFiles.put(projectName, projectArtifact)
|
|
|
|
|
|
|
|
createBuildBwcTask(projectName, "${baseDir}/${projectName}", projectArtifact)
|
2019-04-10 13:43:01 -04:00
|
|
|
}
|
|
|
|
|
2020-07-29 13:45:11 -04:00
|
|
|
// Create build tasks for the JDBC driver used for compatibility testing
|
|
|
|
String jdbcProjectDir = 'x-pack/plugin/sql/jdbc'
|
|
|
|
File jdbcProjectArtifact = file("${checkoutDir}/${jdbcProjectDir}/build/distributions/x-pack-sql-jdbc-${bwcVersion}-SNAPSHOT.jar")
|
|
|
|
createBuildBwcTask('jdbc', jdbcProjectDir, jdbcProjectArtifact)
|
|
|
|
|
2019-01-25 07:14:12 -05:00
|
|
|
createRunBwcGradleTask("resolveAllBwcDependencies") {
|
2019-11-14 06:01:23 -05:00
|
|
|
args 'resolveAllDependencies'
|
2019-01-25 07:14:12 -05:00
|
|
|
}
|
2019-05-22 15:00:51 -04:00
|
|
|
Version currentVersion = Version.fromString(version)
|
|
|
|
if (currentVersion.getMinor() == 0 && currentVersion.getRevision() == 0) {
|
2019-11-14 06:01:23 -05:00
|
|
|
// We only want to resolve dependencies for live versions of master, without cascading this to older versions
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("resolveAllDependencies").configure {
|
|
|
|
dependsOn("resolveAllBwcDependencies")
|
|
|
|
}
|
2019-05-22 15:00:51 -04:00
|
|
|
}
|
2019-01-25 07:14:12 -05:00
|
|
|
|
2019-01-24 02:41:21 -05:00
|
|
|
for (e in artifactFiles) {
|
2019-11-14 06:01:23 -05:00
|
|
|
String projectName = e.key
|
|
|
|
String buildBwcTask = buildBwcTaskName(projectName)
|
|
|
|
File artifactFile = e.value
|
|
|
|
String artifactFileName = artifactFile.name
|
|
|
|
String artifactName = artifactFileName.contains('oss') ? 'elasticsearch-oss' : 'elasticsearch'
|
|
|
|
String suffix = artifactFile.toString()[-3..-1]
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
configurations.create(projectName)
|
|
|
|
artifacts {
|
|
|
|
it.add(projectName, [file: artifactFile, name: artifactName, classifier: classifier, type: suffix, builtBy: buildBwcTask])
|
|
|
|
}
|
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
|
2020-07-31 07:09:04 -04:00
|
|
|
tasks.named("assemble").configure {
|
|
|
|
dependsOn = []
|
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
|
|
|
}
|
2018-07-04 23:24:01 -04:00
|
|
|
|
|
|
|
class IndentingOutputStream extends OutputStream {
|
|
|
|
|
2019-11-14 06:01:23 -05:00
|
|
|
public final byte[] indent
|
|
|
|
private final OutputStream delegate
|
|
|
|
|
|
|
|
public IndentingOutputStream(OutputStream delegate, Object version) {
|
|
|
|
this.delegate = delegate
|
|
|
|
indent = " [${version}] ".getBytes(StandardCharsets.UTF_8)
|
|
|
|
}
|
|
|
|
|
|
|
|
@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-07-04 23:24:01 -04:00
|
|
|
}
|
2019-11-14 06:01:23 -05:00
|
|
|
}
|
2019-01-09 13:57:26 -05:00
|
|
|
}
|