Make LoggedExec gradle task configuration cache compatible (#87621)

This changes the LoggedExec task to be configuration cache compatible. We changed the implementation
to use `ExecOperations` instead of extending `Exec` task. As double checked with the Gradle team this task
is not planned to be made configuration cache compatible out of the box anytime soon.

This is part of the effort on https://github.com/elastic/elasticsearch/issues/57918
This commit is contained in:
Rene Groeschke 2022-07-11 08:46:54 +02:00 committed by GitHub
parent f99ee51c5d
commit dbf39741a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 381 additions and 127 deletions

View file

@ -475,15 +475,13 @@ subprojects {
if (project.name.contains('deb')) {
checkLicenseMetadataTaskProvider.configure { LoggedExec exec ->
onlyIf dpkgExists
final ByteArrayOutputStream output = new ByteArrayOutputStream()
exec.commandLine 'dpkg-deb', '--info', "${-> buildDist.get().outputs.files.filter(debFilter).singleFile}"
exec.standardOutput = output
exec.getCaptureOutput().set(true)
doLast {
String expectedLicense
expectedLicense = "Elastic-License"
final Pattern pattern = Pattern.compile("\\s*License: (.+)")
final String info = output.toString('UTF-8')
final String[] actualLines = info.split("\n")
final String[] actualLines = getOutput().split("\n")
int count = 0
for (final String actualLine : actualLines) {
final Matcher matcher = pattern.matcher(actualLine)
@ -507,11 +505,10 @@ subprojects {
assert project.name.contains('rpm')
checkLicenseMetadataTaskProvider.configure { LoggedExec exec ->
onlyIf rpmExists
final ByteArrayOutputStream output = new ByteArrayOutputStream()
exec.commandLine 'rpm', '-qp', '--queryformat', '%{License}', "${-> buildDist.get().outputs.files.singleFile}"
exec.standardOutput = output
exec.getCaptureOutput().set(true)
doLast {
String license = output.toString('UTF-8')
String license = getOutput()
String expectedLicense
expectedLicense = "Elastic License"
if (license != expectedLicense) {