Improvement usage of gradle task avoidance api (#56627) (#56981)

Use gradle task avoidance api wherever it is possible as a drop in replacement in the es build
This commit is contained in:
Rene Groeschke 2020-05-25 09:37:33 +02:00 committed by GitHub
parent 47bf95cee3
commit 28920a45f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 109 additions and 92 deletions

View File

@ -116,7 +116,7 @@ subprojects {
} }
} }
task updateCIBwcVersions() { tasks.register("updateCIBwcVersions") {
doLast { doLast {
File yml = file(".ci/bwcVersions") File yml = file(".ci/bwcVersions")
yml.text = "" yml.text = ""
@ -150,7 +150,7 @@ allprojects {
} }
} }
task verifyVersions { tasks.register("verifyVersions") {
doLast { doLast {
if (gradle.startParameter.isOffline()) { if (gradle.startParameter.isOffline()) {
throw new GradleException("Must run in online mode to verify versions") throw new GradleException("Must run in online mode to verify versions")
@ -202,7 +202,7 @@ subprojects {
ext.bwc_tests_enabled = bwc_tests_enabled ext.bwc_tests_enabled = bwc_tests_enabled
} }
task verifyBwcTestsEnabled { tasks.register("verifyBwcTestsEnabled") {
doLast { doLast {
if (bwc_tests_enabled == false) { if (bwc_tests_enabled == false) {
throw new GradleException('Bwc tests are disabled. They must be re-enabled after completing backcompat behavior backporting.') throw new GradleException('Bwc tests are disabled. They must be re-enabled after completing backcompat behavior backporting.')
@ -210,10 +210,10 @@ task verifyBwcTestsEnabled {
} }
} }
task branchConsistency { tasks.register("branchConsistency") {
description 'Ensures this branch is internally consistent. For example, that versions constants match released versions.' description 'Ensures this branch is internally consistent. For example, that versions constants match released versions.'
group 'Verification' group 'Verification'
dependsOn verifyVersions, verifyBwcTestsEnabled dependsOn ":verifyVersions", ":verifyBwcTestsEnabled"
} }
allprojects { allprojects {
@ -414,7 +414,7 @@ class Run extends DefaultTask {
} }
} }
task run(type: Run) { tasks.register("run", Run) {
dependsOn ':distribution:run' dependsOn ':distribution:run'
description = 'Runs elasticsearch in the foreground' description = 'Runs elasticsearch in the foreground'
group = 'Verification' group = 'Verification'
@ -493,7 +493,7 @@ allprojects {
if (realTask == null) { if (realTask == null) {
return return
} }
project.tasks.create(taskName) { project.tasks.register(taskName) {
doLast { doLast {
println("${realTask.path} dependencies:") println("${realTask.path} dependencies:")
for (Task dep : realTask.getTaskDependencies().getDependencies(realTask)) { for (Task dep : realTask.getTaskDependencies().getDependencies(realTask)) {

View File

@ -48,7 +48,7 @@ if (project == rootProject) {
Properties props = VersionPropertiesLoader.loadBuildSrcVersion(project.file('version.properties')) Properties props = VersionPropertiesLoader.loadBuildSrcVersion(project.file('version.properties'))
version = props.getProperty("elasticsearch") version = props.getProperty("elasticsearch")
task generateVersionProperties(type: WriteProperties) { def generateVersionProperties = tasks.register("generateVersionProperties", WriteProperties) {
outputFile = "${buildDir}/version.properties" outputFile = "${buildDir}/version.properties"
comment = 'Generated version properties' comment = 'Generated version properties'
properties(props) properties(props)
@ -237,13 +237,13 @@ if (project != rootProject) {
} }
} }
task integTest(type: Test) { tasks.register("integTest", Test) {
inputs.dir(file("src/testKit")).withPropertyName("testkit dir").withPathSensitivity(PathSensitivity.RELATIVE) inputs.dir(file("src/testKit")).withPropertyName("testkit dir").withPathSensitivity(PathSensitivity.RELATIVE)
systemProperty 'test.version_under_test', version systemProperty 'test.version_under_test', version
onlyIf { org.elasticsearch.gradle.info.BuildParams.inFipsJvm == false } onlyIf { org.elasticsearch.gradle.info.BuildParams.inFipsJvm == false }
maxParallelForks = System.getProperty('tests.jvms', org.elasticsearch.gradle.info.BuildParams.defaultParallel.toString()) as Integer maxParallelForks = System.getProperty('tests.jvms', org.elasticsearch.gradle.info.BuildParams.defaultParallel.toString()) as Integer
} }
check.dependsOn(integTest) check.dependsOn("integTest")
// for now we hardcode the tests for our build to use the gradle jvm. // for now we hardcode the tests for our build to use the gradle jvm.
tasks.withType(Test).configureEach { tasks.withType(Test).configureEach {

View File

@ -1,7 +1,7 @@
apply plugin: 'java' apply plugin: 'java'
jar { jar {
archiveName = "${project.name}.jar" archiveFileName = "${project.name}.jar"
manifest { manifest {
attributes 'Main-Class': 'org.elasticsearch.gradle.reaper.Reaper' attributes 'Main-Class': 'org.elasticsearch.gradle.reaper.Reaper'
} }

View File

@ -26,6 +26,8 @@ import org.gradle.api.GradleException
import org.gradle.api.Task import org.gradle.api.Task
import org.gradle.api.tasks.Exec import org.gradle.api.tasks.Exec
import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.TaskProvider
/** /**
* A fixture for integration tests which runs in a separate process launched by Ant. * A fixture for integration tests which runs in a separate process launched by Ant.
*/ */
@ -79,7 +81,7 @@ class AntFixture extends AntTask implements Fixture {
return tmpFile.exists() return tmpFile.exists()
} }
private final Task stopTask private final TaskProvider stopTask
AntFixture() { AntFixture() {
stopTask = createStopTask() stopTask = createStopTask()
@ -88,7 +90,7 @@ class AntFixture extends AntTask implements Fixture {
@Override @Override
@Internal @Internal
Task getStopTask() { TaskProvider getStopTask() {
return stopTask return stopTask
} }
@ -222,24 +224,29 @@ class AntFixture extends AntTask implements Fixture {
} }
/** Adds a task to kill an elasticsearch node with the given pidfile */ /** Adds a task to kill an elasticsearch node with the given pidfile */
private Task createStopTask() { private TaskProvider createStopTask() {
final AntFixture fixture = this final AntFixture fixture = this
final Object pid = "${ -> fixture.pid }" final Object pid = "${ -> fixture.pid }"
Exec stop = project.tasks.create(name: "${name}#stop", type: LoggedExec) TaskProvider<Exec> stop = project.tasks.register("${name}#stop", LoggedExec)
stop.onlyIf { fixture.pidFile.exists() } stop.configure {
stop.doFirst { onlyIf { fixture.pidFile.exists() }
logger.info("Shutting down ${fixture.name} with pid ${pid}") doFirst {
} logger.info("Shutting down ${fixture.name} with pid ${pid}")
if (Os.isFamily(Os.FAMILY_WINDOWS)) { }
stop.executable = 'Taskkill'
stop.args('/PID', pid, '/F') if (Os.isFamily(Os.FAMILY_WINDOWS)) {
} else { executable = 'Taskkill'
stop.executable = 'kill' args('/PID', pid, '/F')
stop.args('-9', pid) } else {
} executable = 'kill'
stop.doLast { args('-9', pid)
project.delete(fixture.pidFile) }
doLast {
project.delete(fixture.pidFile)
}
} }
return stop return stop
} }

View File

@ -58,10 +58,12 @@ class TestWithDependenciesPlugin implements Plugin<Project> {
String outputDir = "${project.buildDir}/generated-resources/${pluginProject.name}" String outputDir = "${project.buildDir}/generated-resources/${pluginProject.name}"
String camelName = pluginProject.name.replaceAll(/-(\w)/) { _, c -> c.toUpperCase(Locale.ROOT) } String camelName = pluginProject.name.replaceAll(/-(\w)/) { _, c -> c.toUpperCase(Locale.ROOT) }
String taskName = "copy" + camelName[0].toUpperCase(Locale.ROOT) + camelName.substring(1) + "Metadata" String taskName = "copy" + camelName[0].toUpperCase(Locale.ROOT) + camelName.substring(1) + "Metadata"
Copy copyPluginMetadata = project.tasks.create(taskName, Copy.class) project.tasks.register(taskName, Copy.class) {
copyPluginMetadata.into(outputDir) into(outputDir)
copyPluginMetadata.from(pluginProject.tasks.pluginProperties) from(pluginProject.tasks.pluginProperties)
copyPluginMetadata.from(pluginProject.file('src/main/plugin-metadata')) from(pluginProject.file('src/main/plugin-metadata'))
}
project.sourceSets.test.output.dir(outputDir, builtBy: taskName) project.sourceSets.test.output.dir(outputDir, builtBy: taskName)
} }
} }

View File

@ -32,12 +32,16 @@ public class ExportElasticsearchBuildResourcesTaskIT extends GradleIntegrationTe
BuildResult result = getGradleRunner(PROJECT_NAME).withArguments("buildResources", "-s", "-i").build(); BuildResult result = getGradleRunner(PROJECT_NAME).withArguments("buildResources", "-s", "-i").build();
assertTaskSuccessful(result, ":buildResources"); assertTaskSuccessful(result, ":buildResources");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle.xml"); assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle.xml");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle_suppressions.xml");
// using task avoidance api means the task configuration of the sample task is never triggered
assertBuildFileDoesNotExists(result, PROJECT_NAME, "build-tools-exported/checkstyle_suppressions.xml");
result = getGradleRunner(PROJECT_NAME).withArguments("buildResources", "-s", "-i").build(); result = getGradleRunner(PROJECT_NAME).withArguments("buildResources", "-s", "-i").build();
assertTaskUpToDate(result, ":buildResources"); assertTaskUpToDate(result, ":buildResources");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle.xml"); assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle.xml");
assertBuildFileExists(result, PROJECT_NAME, "build-tools-exported/checkstyle_suppressions.xml");
// using task avoidance api means the task configuration of the sample task is never triggered
assertBuildFileDoesNotExists(result, PROJECT_NAME, "build-tools-exported/checkstyle_suppressions.xml");
} }
public void testImplicitTaskDependencyCopy() { public void testImplicitTaskDependencyCopy() {
@ -46,8 +50,10 @@ public class ExportElasticsearchBuildResourcesTaskIT extends GradleIntegrationTe
assertTaskSuccessful(result, ":buildResources"); assertTaskSuccessful(result, ":buildResources");
assertTaskSuccessful(result, ":sampleCopyAll"); assertTaskSuccessful(result, ":sampleCopyAll");
assertBuildFileExists(result, PROJECT_NAME, "sampleCopyAll/checkstyle.xml"); assertBuildFileExists(result, PROJECT_NAME, "sampleCopyAll/checkstyle.xml");
// This is a side effect of compile time reference
assertBuildFileExists(result, PROJECT_NAME, "sampleCopyAll/checkstyle_suppressions.xml"); // using task avoidance api means the task configuration of the sample task is never triggered
// which means buildResource is not configured to copy this file
assertBuildFileDoesNotExists(result, PROJECT_NAME, "sampleCopyAll/checkstyle_suppressions.xml");
} }
public void testImplicitTaskDependencyInputFileOfOther() { public void testImplicitTaskDependencyInputFileOfOther() {

View File

@ -27,13 +27,13 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
// Build the sample jars // Build the sample jars
getGradleRunner("thirdPartyAudit").withArguments("build", "-s").build(); getGradleRunner("thirdPartyAudit").withArguments(":sample_jars:build", "-s").build();
} }
public void testElasticsearchIgnored() { public void testElasticsearchIgnored() {
BuildResult result = getGradleRunner("thirdPartyAudit").withArguments( BuildResult result = getGradleRunner("thirdPartyAudit").withArguments(
"clean", ":clean",
"empty", ":empty",
"-s", "-s",
"-PcompileOnlyGroup=elasticsearch.gradle:broken-log4j", "-PcompileOnlyGroup=elasticsearch.gradle:broken-log4j",
"-PcompileOnlyVersion=0.0.1", "-PcompileOnlyVersion=0.0.1",
@ -44,9 +44,9 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
} }
public void testWithEmptyRules() { public void testWithEmptyRules() {
BuildResult result = getGradleRunner("thirdPartyAudit").withArguments( getGradleRunner("thirdPartyAudit").withArguments(
"clean", ":clean",
"empty", ":empty",
"-s", "-s",
"-PcompileOnlyGroup=other.gradle:broken-log4j", "-PcompileOnlyGroup=other.gradle:broken-log4j",
"-PcompileOnlyVersion=0.0.1", "-PcompileOnlyVersion=0.0.1",
@ -57,8 +57,8 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
public void testViolationFoundAndCompileOnlyIgnored() { public void testViolationFoundAndCompileOnlyIgnored() {
BuildResult result = getGradleRunner("thirdPartyAudit").withArguments( BuildResult result = getGradleRunner("thirdPartyAudit").withArguments(
"clean", ":clean",
"absurd", ":absurd",
"-s", "-s",
"-PcompileOnlyGroup=other.gradle:broken-log4j", "-PcompileOnlyGroup=other.gradle:broken-log4j",
"-PcompileOnlyVersion=0.0.1", "-PcompileOnlyVersion=0.0.1",
@ -73,8 +73,8 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
public void testClassNotFoundAndCompileOnlyIgnored() { public void testClassNotFoundAndCompileOnlyIgnored() {
BuildResult result = getGradleRunner("thirdPartyAudit").withArguments( BuildResult result = getGradleRunner("thirdPartyAudit").withArguments(
"clean", ":clean",
"absurd", ":absurd",
"-s", "-s",
"-PcompileGroup=other.gradle:broken-log4j", "-PcompileGroup=other.gradle:broken-log4j",
"-PcompileVersion=0.0.1", "-PcompileVersion=0.0.1",
@ -94,8 +94,8 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
public void testJarHellWithJDK() { public void testJarHellWithJDK() {
BuildResult result = getGradleRunner("thirdPartyAudit").withArguments( BuildResult result = getGradleRunner("thirdPartyAudit").withArguments(
"clean", ":clean",
"absurd", ":absurd",
"-s", "-s",
"-PcompileGroup=other.gradle:jarhellJdk", "-PcompileGroup=other.gradle:jarhellJdk",
"-PcompileVersion=0.0.1", "-PcompileVersion=0.0.1",
@ -115,8 +115,8 @@ public class ThirdPartyAuditTaskIT extends GradleIntegrationTestCase {
public void testElasticsearchIgnoredWithViolations() { public void testElasticsearchIgnoredWithViolations() {
BuildResult result = getGradleRunner("thirdPartyAudit").withArguments( BuildResult result = getGradleRunner("thirdPartyAudit").withArguments(
"clean", ":clean",
"absurd", ":absurd",
"-s", "-s",
"-PcompileOnlyGroup=elasticsearch.gradle:broken-log4j", "-PcompileOnlyGroup=elasticsearch.gradle:broken-log4j",
"-PcompileOnlyVersion=0.0.1", "-PcompileOnlyVersion=0.0.1",

View File

@ -3,10 +3,10 @@ if (distroConfig != null) {
// setup the test distribution as an artifact of this project // setup the test distribution as an artifact of this project
String distroType = System.getProperty('tests.distro.type') String distroType = System.getProperty('tests.distro.type')
Task buildDistro def buildDistro
File buildFile File buildFile
if (['rpm', 'deb'].contains(distroType)) { if (['rpm', 'deb'].contains(distroType)) {
buildDistro = project.tasks.create("build" + distroType.capitalize(), Copy) { buildDistro = project.tasks.register("build" + distroType.capitalize(), Copy) {
from 'files' from 'files'
into 'build/files' into 'build/files'
include 'fake_elasticsearch.tar.gz' include 'fake_elasticsearch.tar.gz'
@ -21,7 +21,7 @@ if (distroConfig != null) {
extension = "zip" extension = "zip"
} }
// copy file as is // copy file as is
buildDistro = project.tasks.create("buildArchive", Copy) { buildDistro = project.tasks.register("buildArchive", Copy) {
from 'files' from 'files'
include "fake_elasticsearch.${extension}" include "fake_elasticsearch.${extension}"
into 'build/files' into 'build/files'

View File

@ -36,7 +36,7 @@ elasticsearch_distributions {
} }
} }
task assertDistroFile { tasks.register("assertDistroFile") {
dependsOn elasticsearch_distributions.test_distro dependsOn elasticsearch_distributions.test_distro
doLast { doLast {
File distroFile = new File(elasticsearch_distributions.test_distro.toString()) File distroFile = new File(elasticsearch_distributions.test_distro.toString())
@ -50,7 +50,7 @@ task assertDistroFile {
} }
if (['rpm', 'deb'].contains(distroType) == false) { if (['rpm', 'deb'].contains(distroType) == false) {
task assertDistroExtracted { tasks.register("assertDistroExtracted") {
dependsOn elasticsearch_distributions.test_distro.extracted, assertDistroFile dependsOn elasticsearch_distributions.test_distro.extracted, assertDistroFile
doLast { doLast {
File distroExtracted = new File(elasticsearch_distributions.test_distro.extracted.toString()) File distroExtracted = new File(elasticsearch_distributions.test_distro.extracted.toString())

View File

@ -9,13 +9,13 @@ buildResources {
copy 'checkstyle.xml' copy 'checkstyle.xml'
} }
task sampleCopyAll(type: Sync) { tasks.register("sampleCopyAll", Sync) {
/** Note: no explicit dependency. This works with tasks that use the Provider API a.k.a "Lazy Configuration" **/ /** Note: no explicit dependency. This works with tasks that use the Provider API a.k.a "Lazy Configuration" **/
from buildResources from buildResources
into "$buildDir/sampleCopyAll" into "$buildDir/sampleCopyAll"
} }
task sample { tasks.register("sample") {
// This does not work, task dependencies can't be providers // This does not work, task dependencies can't be providers
// dependsOn buildResources.resource('minimumRuntimeVersion') // dependsOn buildResources.resource('minimumRuntimeVersion')
// Nor does this, despite https://github.com/gradle/gradle/issues/3811 // Nor does this, despite https://github.com/gradle/gradle/issues/3811
@ -29,7 +29,7 @@ task sample {
} }
} }
task noConfigAfterExecution { tasks.register("noConfigAfterExecution") {
dependsOn buildResources dependsOn buildResources
doLast { doLast {
println "This should cause an error because we are refferencing " + println "This should cause an error because we are refferencing " +

View File

@ -30,7 +30,7 @@ loggerUsageCheck.enabled = false
// TODO: shouldn't be part of BuildPlugin, should be tested separately // TODO: shouldn't be part of BuildPlugin, should be tested separately
validateNebulaPom.enabled = false validateNebulaPom.enabled = false
task hello { tasks.register("hello") {
doFirst { doFirst {
println "build plugin can be applied" println "build plugin can be applied"
} }

View File

@ -9,7 +9,7 @@ project.gradle.projectsEvaluated {
repository.setUrl(fakeJdkRepo) repository.setUrl(fakeJdkRepo)
} }
task numConfigurations { tasks.register("numConfigurations") {
doLast { doLast {
println "NUM CONFIGS: ${project.configurations.size()}" println "NUM CONFIGS: ${project.configurations.size()}"
} }

View File

@ -26,21 +26,21 @@ jdks {
} }
} }
task getLinuxJdk { tasks.register("getLinuxJdk") {
dependsOn jdks.linux dependsOn jdks.linux
doLast { doLast {
println "JDK HOME: " + jdks.linux println "JDK HOME: " + jdks.linux
} }
} }
task getDarwinJdk { tasks.register("getDarwinJdk") {
dependsOn jdks.darwin dependsOn jdks.darwin
doLast { doLast {
println "JDK HOME: " + jdks.darwin println "JDK HOME: " + jdks.darwin
} }
} }
task getWindowsJdk { tasks.register("getWindowsJdk") {
dependsOn jdks.windows dependsOn jdks.windows
doLast { doLast {
println "JDK HOME: " + jdks.windows println "JDK HOME: " + jdks.windows

View File

@ -2,7 +2,7 @@ plugins {
id 'elasticsearch.reaper' id 'elasticsearch.reaper'
} }
task launchReaper { tasks.register("launchReaper") {
doLast { doLast {
def reaper = project.extensions.getByName('reaper') def reaper = project.extensions.getByName('reaper')
reaper.registerCommand('test', 'true') reaper.registerCommand('test', 'true')

View File

@ -23,7 +23,7 @@ switch (testPreserveFileTimestamps) {
+ testPreserveFileTimestamps + "]") + testPreserveFileTimestamps + "]")
} }
task buildBZip2Tar(type: SymbolicLinkPreservingTar) { SymbolicLinkPreservingTar tar -> tasks.register("buildBZip2Tar", SymbolicLinkPreservingTar) { SymbolicLinkPreservingTar tar ->
tar.archiveExtension = 'tar.bz2' tar.archiveExtension = 'tar.bz2'
tar.compression = Compression.BZIP2 tar.compression = Compression.BZIP2
tar.preserveFileTimestamps = preserveFileTimestamps tar.preserveFileTimestamps = preserveFileTimestamps
@ -33,7 +33,7 @@ task buildBZip2Tar(type: SymbolicLinkPreservingTar) { SymbolicLinkPreservingTar
} }
} }
task buildGZipTar(type: SymbolicLinkPreservingTar) { SymbolicLinkPreservingTar tar -> tasks.register("buildGZipTar", SymbolicLinkPreservingTar) { SymbolicLinkPreservingTar tar ->
tar.archiveExtension = 'tar.gz' tar.archiveExtension = 'tar.gz'
tar.compression = Compression.GZIP tar.compression = Compression.GZIP
tar.preserveFileTimestamps = preserveFileTimestamps tar.preserveFileTimestamps = preserveFileTimestamps
@ -43,7 +43,7 @@ task buildGZipTar(type: SymbolicLinkPreservingTar) { SymbolicLinkPreservingTar t
} }
} }
task buildTar(type: SymbolicLinkPreservingTar) { SymbolicLinkPreservingTar tar -> tasks.register("buildTar", SymbolicLinkPreservingTar) { SymbolicLinkPreservingTar tar ->
tar.archiveExtension = 'tar' tar.archiveExtension = 'tar'
tar.preserveFileTimestamps = preserveFileTimestamps tar.preserveFileTimestamps = preserveFileTimestamps
from fileTree(source) from fileTree(source)

View File

@ -28,9 +28,7 @@ allprojects {
} }
project(':empty_test_task') { project(':empty_test_task') {
task emptyTest(type: Test) { tasks.register("emptyTest", Test)
}
} }
project(':all_classes_in_tasks') { project(':all_classes_in_tasks') {

View File

@ -23,7 +23,7 @@ repositories {
jcenter() jcenter()
} }
configurations.create("forbiddenApisCliJar") configurations.register("forbiddenApisCliJar")
dependencies { dependencies {
forbiddenApisCliJar 'de.thetaphi:forbiddenapis:2.7' forbiddenApisCliJar 'de.thetaphi:forbiddenapis:2.7'
@ -31,12 +31,12 @@ dependencies {
compile "org.${project.properties.compileGroup}:${project.properties.compileVersion}" compile "org.${project.properties.compileGroup}:${project.properties.compileVersion}"
} }
task empty(type: ThirdPartyAuditTask) { tasks.register("empty", ThirdPartyAuditTask) {
targetCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11
signatureFile = file('third-party-audit-empty.txt') signatureFile = file('third-party-audit-empty.txt')
} }
task absurd(type: ThirdPartyAuditTask) { tasks.register("absurd", ThirdPartyAuditTask) {
targetCompatibility = JavaVersion.VERSION_11 targetCompatibility = JavaVersion.VERSION_11
signatureFile = file('third-party-audit-absurd.txt') signatureFile = file('third-party-audit-absurd.txt')
} }

View File

@ -8,14 +8,11 @@ dependencies {
compile 'org.apache.logging.log4j:log4j-core:2.11.1' compile 'org.apache.logging.log4j:log4j-core:2.11.1'
} }
// Tests have to clean mid-test but we don't want the sample jars to go away
clean.enabled = false
["0.0.1", "0.0.2"].forEach { v -> ["0.0.1", "0.0.2"].forEach { v ->
["elasticsearch", "other"].forEach { p -> ["elasticsearch", "other"].forEach { p ->
task "dummy-${p}-${v}"(type: Jar) { tasks.register("dummy-${p}-${v}", Jar) {
destinationDir = file("${buildDir}/testrepo/org/${p}/gradle/dummy-io/${v}/") destinationDir = file("${buildDir}/testrepo/org/${p}/gradle/dummy-io/${v}/")
archiveName = "dummy-io-${v}.jar" archiveFileName = "dummy-io-${v}.jar"
from sourceSets.main.output from sourceSets.main.output
include "**/TestingIO.class" include "**/TestingIO.class"
if (v == "0.0.2") { if (v == "0.0.2") {
@ -32,9 +29,9 @@ clean.enabled = false
["0.0.1"].forEach { v -> ["0.0.1"].forEach { v ->
["elasticsearch", "other"].forEach { p -> ["elasticsearch", "other"].forEach { p ->
task "broken-log4j-${p}-${v}"(type: Jar) { tasks.register("broken-log4j-${p}-${v}", Jar) {
destinationDir = file("${buildDir}/testrepo/org/${p}/gradle/broken-log4j/${v}/") destinationDir = file("${buildDir}/testrepo/org/${p}/gradle/broken-log4j/${v}/")
archiveName = "broken-log4j-${v}.jar" archiveFileName = "broken-log4j-${v}.jar"
from sourceSets.main.output from sourceSets.main.output
include "**/TestingLog4j.class" include "**/TestingLog4j.class"
} }
@ -42,11 +39,11 @@ clean.enabled = false
} }
} }
task jarhellJdk(type: Jar) { tasks.register("jarhellJdk", Jar) {
destinationDir = file("${buildDir}/testrepo/org/other/gradle/jarhellJdk/0.0.1/") destinationDir = file("${buildDir}/testrepo/org/other/gradle/jarhellJdk/0.0.1/")
archiveName = "jarhellJdk-0.0.1.jar" archiveFileName = "jarhellJdk-0.0.1.jar"
from sourceSets.main.output from sourceSets.main.output
include "**/String.class" include "**/String.class"
into "java/lang" into "java/lang"
build.dependsOn("jarhellJdk")
} }
build.dependsOn("jarhellJdk")

View File

@ -157,7 +157,7 @@ BuildParams.bwcVersions.forPreviousUnreleased { BwcVersions.UnreleasedVersionInf
Closure createRunBwcGradleTask = { name, extraConfig -> Closure createRunBwcGradleTask = { name, extraConfig ->
return tasks.create(name: "$name", type: LoggedExec) { return tasks.register("$name", LoggedExec) {
dependsOn checkoutBwcBranch dependsOn checkoutBwcBranch
spoolOutput = true spoolOutput = true
workingDir = checkoutDir workingDir = checkoutDir
@ -225,10 +225,11 @@ BuildParams.bwcVersions.forPreviousUnreleased { BwcVersions.UnreleasedVersionInf
return "buildBwc${projectName.replaceAll(/-\w/) { it[1].toUpperCase() }.capitalize()}" return "buildBwc${projectName.replaceAll(/-\w/) { it[1].toUpperCase() }.capitalize()}"
} }
task buildBwc {} def buildBwc = tasks.register("buildBwc");
Closure createBuildBwcTask = { projectName, projectDir, projectArtifact -> Closure createBuildBwcTask = { projectName, projectDir, projectArtifact ->
Task bwcTask = createRunBwcGradleTask(buildBwcTaskName(projectName)) { def bwcTaskName = buildBwcTaskName(projectName)
createRunBwcGradleTask(bwcTaskName) {
inputs.file("${project.buildDir}/refspec") inputs.file("${project.buildDir}/refspec")
outputs.files(projectArtifact) outputs.files(projectArtifact)
outputs.cacheIf("BWC distribution caching is disabled on 'master' branch") { outputs.cacheIf("BWC distribution caching is disabled on 'master' branch") {
@ -245,7 +246,9 @@ BuildParams.bwcVersions.forPreviousUnreleased { BwcVersions.UnreleasedVersionInf
} }
} }
} }
buildBwc.dependsOn bwcTask buildBwc.configure {
dependsOn(bwcTaskName)
}
} }
Map<String, File> artifactFiles = [:] Map<String, File> artifactFiles = [:]

View File

@ -32,7 +32,7 @@ esplugin {
// No unit tests in this example // No unit tests in this example
test.enabled = false test.enabled = false
task exampleFixture(type: org.elasticsearch.gradle.test.AntFixture) { tasks.register("exampleFixture", org.elasticsearch.gradle.test.AntFixture) {
dependsOn testClasses dependsOn testClasses
env 'CLASSPATH', "${-> project.sourceSets.test.runtimeClasspath.asPath}" env 'CLASSPATH', "${-> project.sourceSets.test.runtimeClasspath.asPath}"
executable = "${BuildParams.runtimeJavaHome}/bin/java" executable = "${BuildParams.runtimeJavaHome}/bin/java"

View File

@ -98,7 +98,7 @@ String krb5conf = project(':test:fixtures:krb5kdc-fixture').ext.krb5Conf("hdfs")
// Create HDFS File System Testing Fixtures for HA/Secure combinations // Create HDFS File System Testing Fixtures for HA/Secure combinations
for (String fixtureName : ['hdfsFixture', 'haHdfsFixture', 'secureHdfsFixture', 'secureHaHdfsFixture']) { for (String fixtureName : ['hdfsFixture', 'haHdfsFixture', 'secureHdfsFixture', 'secureHaHdfsFixture']) {
project.tasks.create(fixtureName, org.elasticsearch.gradle.test.AntFixture) { def tsk = project.tasks.register(fixtureName, org.elasticsearch.gradle.test.AntFixture) {
dependsOn project.configurations.hdfsFixture, project(':test:fixtures:krb5kdc-fixture').tasks.postProcessFixture dependsOn project.configurations.hdfsFixture, project(':test:fixtures:krb5kdc-fixture').tasks.postProcessFixture
executable = "${BuildParams.runtimeJavaHome}/bin/java" executable = "${BuildParams.runtimeJavaHome}/bin/java"
env 'CLASSPATH', "${-> project.configurations.hdfsFixture.asPath}" env 'CLASSPATH', "${-> project.configurations.hdfsFixture.asPath}"
@ -137,6 +137,10 @@ for (String fixtureName : ['hdfsFixture', 'haHdfsFixture', 'secureHdfsFixture',
args miniHDFSArgs.toArray() args miniHDFSArgs.toArray()
} }
// TODO: The task configuration block has side effects that require it currently to be always executed.
// Otherwise tests start failing. Therefore we enforce the task creation for now.
tsk.get()
} }
Set disabledIntegTestTaskNames = [] Set disabledIntegTestTaskNames = []

View File

@ -54,20 +54,20 @@ for (Version bwcVersion : BuildParams.bwcVersions.wireCompatible) {
for (kind in ["follower", "leader"]) { for (kind in ["follower", "leader"]) {
// Attention!! Groovy trap: do not pass `kind` to a closure // Attention!! Groovy trap: do not pass `kind` to a closure
tasks.create("${baseName}#${kind}#clusterTest", RestTestRunnerTask) { tasks.register("${baseName}#${kind}#clusterTest", RestTestRunnerTask) {
systemProperty 'tests.rest.upgrade_state', 'none' systemProperty 'tests.rest.upgrade_state', 'none'
systemProperty 'tests.rest.cluster_name', kind systemProperty 'tests.rest.cluster_name', kind
ext.kindExt = kind ext.kindExt = kind
} }
tasks.create("${baseName}#${kind}#oneThirdUpgradedTest", RestTestRunnerTask) { tasks.register("${baseName}#${kind}#oneThirdUpgradedTest", RestTestRunnerTask) {
systemProperty 'tests.rest.upgrade_state', 'one_third' systemProperty 'tests.rest.upgrade_state', 'one_third'
systemProperty 'tests.rest.cluster_name', kind systemProperty 'tests.rest.cluster_name', kind
dependsOn "${baseName}#leader#clusterTest", "${baseName}#follower#clusterTest" dependsOn "${baseName}#leader#clusterTest", "${baseName}#follower#clusterTest"
ext.kindExt = kind ext.kindExt = kind
} }
tasks.create("${baseName}#${kind}#twoThirdsUpgradedTest", RestTestRunnerTask) { tasks.register("${baseName}#${kind}#twoThirdsUpgradedTest", RestTestRunnerTask) {
systemProperty 'tests.rest.upgrade_state', 'two_third' systemProperty 'tests.rest.upgrade_state', 'two_third'
systemProperty 'tests.rest.cluster_name', kind systemProperty 'tests.rest.cluster_name', kind
dependsOn "${baseName}#${kind}#oneThirdUpgradedTest" dependsOn "${baseName}#${kind}#oneThirdUpgradedTest"