From 6ab4645f4e27dda7f4a86ecc8cdd874a52942f9e Mon Sep 17 00:00:00 2001 From: Mark Vieira Date: Fri, 1 Nov 2019 11:33:11 -0700 Subject: [PATCH] [7.x] Introduce type-safe and consistent pattern for handling build globals (#48818) This commit introduces a consistent, and type-safe manner for handling global build parameters through out our build logic. Primarily this replaces the existing usages of extra properties with static accessors. It also introduces and explicit API for initialization and mutation of any such parameters, as well as better error handling for uninitialized or eager access of parameter values. Closes #42042 --- benchmarks/build.gradle | 4 +- buildSrc/build.gradle | 4 +- .../elasticsearch/gradle/BuildPlugin.groovy | 63 ++--- .../gradle/plugin/PluginBuildPlugin.groovy | 4 +- .../gradle/precommit/PrecommitTasks.groovy | 16 +- .../gradle/test/ClusterFormationTasks.groovy | 5 +- .../gradle/test/DistroTestPlugin.java | 4 +- .../gradle/test/RestIntegTestTask.groovy | 6 +- .../test/StandaloneRestTestPlugin.groovy | 5 +- .../gradle/DistributionDownloadPlugin.java | 8 +- .../elasticsearch/gradle/ReaperService.java | 4 +- .../gradle/info/BuildParams.java | 239 ++++++++++++++++++ .../gradle/info/GlobalBuildInfoPlugin.java | 34 +-- .../gradle/info/PrintGlobalBuildInfoTask.java | 12 +- .../DistributionDownloadPluginTests.java | 4 +- .../distribution-download/build.gradle | 7 +- distribution/bwc/build.gradle | 3 +- distribution/docker/build.gradle | 7 +- distribution/tools/plugin-cli/build.gradle | 4 +- libs/core/build.gradle | 4 +- modules/reindex/build.gradle | 3 +- modules/repository-url/build.gradle | 3 +- modules/transport-netty4/build.gradle | 4 +- plugins/discovery-azure-classic/build.gradle | 5 +- plugins/discovery-ec2/build.gradle | 4 +- .../discovery-ec2/qa/amazon-ec2/build.gradle | 3 +- plugins/discovery-gce/qa/gce/build.gradle | 3 +- plugins/examples/rest-handler/build.gradle | 4 +- plugins/ingest-attachment/build.gradle | 4 +- plugins/repository-azure/build.gradle | 4 +- .../qa/microsoft-azure-storage/build.gradle | 3 +- .../qa/google-cloud-storage/build.gradle | 5 +- plugins/repository-hdfs/build.gradle | 11 +- plugins/repository-s3/build.gradle | 11 +- plugins/transport-nio/build.gradle | 4 +- qa/die-with-dignity/build.gradle | 4 +- qa/full-cluster-restart/build.gradle | 3 +- qa/mixed-cluster/build.gradle | 3 +- qa/rolling-upgrade/build.gradle | 3 +- qa/verify-version-constants/build.gradle | 3 +- server/build.gradle | 6 +- x-pack/plugin/build.gradle | 5 +- x-pack/plugin/security/build.gradle | 4 +- x-pack/plugin/security/cli/build.gradle | 3 +- .../sql/qa/security/with-ssl/build.gradle | 15 +- x-pack/plugin/sql/sql-cli/build.gradle | 4 +- x-pack/plugin/watcher/build.gradle | 4 +- x-pack/qa/full-cluster-restart/build.gradle | 3 +- .../reindex-tests-with-security/build.gradle | 4 +- x-pack/qa/rolling-upgrade-basic/build.gradle | 3 +- .../build.gradle | 3 +- x-pack/qa/rolling-upgrade/build.gradle | 3 +- x-pack/snapshot-tool/build.gradle | 5 +- 53 files changed, 436 insertions(+), 150 deletions(-) create mode 100644 buildSrc/src/main/java/org/elasticsearch/gradle/info/BuildParams.java diff --git a/benchmarks/build.gradle b/benchmarks/build.gradle index 376ad4d4e67..9756481b621 100644 --- a/benchmarks/build.gradle +++ b/benchmarks/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -44,7 +46,7 @@ compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked,-processi // needs to be added separately otherwise Gradle will quote it and javac will fail compileJava.options.compilerArgs.addAll(["-processor", "org.openjdk.jmh.generators.BenchmarkProcessor"]) -run.executable = new File(project.runtimeJavaHome, 'bin/java') +run.executable = "${BuildParams.runtimeJavaHome}/bin/java" // classes generated by JMH can use all sorts of forbidden APIs but we have no influence at all and cannot exclude these classes forbiddenApisMain.enabled = false diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index 2aca685a3e2..eb72a1bd230 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -220,8 +220,8 @@ if (project != rootProject) { task integTest(type: Test) { inputs.dir(file("src/testKit")).withPropertyName("testkit dir").withPathSensitivity(PathSensitivity.RELATIVE) systemProperty 'test.version_under_test', version - onlyIf { project.inFipsJvm == false } - maxParallelForks = System.getProperty('tests.jvms', project.rootProject.ext.defaultParallel.toString()) as Integer + onlyIf { org.elasticsearch.gradle.info.BuildParams.inFipsJvm == false } + maxParallelForks = System.getProperty('tests.jvms', org.elasticsearch.gradle.info.BuildParams.defaultParallel.toString()) as Integer } check.dependsOn(integTest) diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy index 371d2207f5d..1e69b9b405a 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy @@ -25,6 +25,7 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import groovy.transform.CompileStatic import org.apache.commons.io.IOUtils +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.info.GlobalBuildInfoPlugin import org.elasticsearch.gradle.info.GlobalInfoExtension import org.elasticsearch.gradle.info.JavaHome @@ -140,7 +141,6 @@ class BuildPlugin implements Plugin { configurePrecommit(project) configureDependenciesInfo(project) - configureFips140(project) } @@ -149,9 +149,8 @@ class BuildPlugin implements Plugin { GlobalInfoExtension globalInfo = project.rootProject.extensions.getByType(GlobalInfoExtension) // wait until global info is populated because we don't know if we are running in a fips jvm until execution time globalInfo.ready { - ExtraPropertiesExtension ext = project.extensions.getByType(ExtraPropertiesExtension) // Common config when running with a FIPS-140 runtime JVM - if (ext.has('inFipsJvm') && ext.get('inFipsJvm')) { + if (BuildParams.inFipsJvm) { project.tasks.withType(Test).configureEach { Test task -> task.systemProperty 'javax.net.ssl.trustStorePassword', 'password' task.systemProperty 'javax.net.ssl.keyStorePassword', 'password' @@ -295,8 +294,7 @@ class BuildPlugin implements Plugin { List messages = [] Map> requiredJavaVersions = (Map>) ext.get('requiredJavaVersions') for (Map.Entry> entry : requiredJavaVersions) { - List javaVersions = ext.get('javaVersions') as List - if (javaVersions.find { it.version == entry.key } != null) { + if (BuildParams.javaVersions.find { it.version == entry.key } != null) { continue } List tasks = entry.value.findAll { taskGraph.hasTask(it) }.collect { " ${it.path}".toString() } @@ -311,8 +309,7 @@ class BuildPlugin implements Plugin { }) } else if (ext.has('requiredJavaVersions') == false || ext.get('requiredJavaVersions') == null) { // check directly if the version is present since we are already executing - List javaVersions = ext.get('javaVersions') as List - if (javaVersions.find { it.version == version } == null) { + if (BuildParams.javaVersions.find { it.version == version } == null) { throw new GradleException("JAVA${version}_HOME required to run task:\n${task}") } } else { @@ -323,8 +320,7 @@ class BuildPlugin implements Plugin { /** A convenience method for getting java home for a version of java and requiring that version for the given task to execute */ static String getJavaHome(final Task task, final int version) { requireJavaHome(task, version) - List javaVersions = task.project.property('javaVersions') as List - return javaVersions.find { it.version == version }.javaHome.absolutePath + return BuildParams.javaVersions.find { it.version == version }.javaHome.absolutePath } /** @@ -488,7 +484,7 @@ class BuildPlugin implements Plugin { ExtraPropertiesExtension ext = project.extensions.getByType(ExtraPropertiesExtension) GlobalInfoExtension globalBuildInfo = project.rootProject.extensions.getByType(GlobalInfoExtension) globalBuildInfo.ready { - if ((ext.get('compilerJavaVersion') as JavaVersion) < JavaVersion.VERSION_1_10) { + if (BuildParams.compilerJavaVersion < JavaVersion.VERSION_1_10) { ext.set('compactProfile', 'compact3') } else { ext.set('compactProfile', 'full') @@ -496,20 +492,18 @@ class BuildPlugin implements Plugin { } ext.set('compactProfile', 'full') - project.extensions.getByType(JavaPluginExtension).sourceCompatibility = ext.get('minimumRuntimeVersion') as JavaVersion - project.extensions.getByType(JavaPluginExtension).targetCompatibility = ext.get('minimumRuntimeVersion') as JavaVersion + project.extensions.getByType(JavaPluginExtension).sourceCompatibility = BuildParams.minimumRuntimeVersion + project.extensions.getByType(JavaPluginExtension).targetCompatibility = BuildParams.minimumRuntimeVersion project.afterEvaluate { - File compilerJavaHome = ext.get('compilerJavaHome') as File - project.tasks.withType(JavaCompile).configureEach({ JavaCompile compileTask -> final JavaVersion targetCompatibilityVersion = JavaVersion.toVersion(compileTask.targetCompatibility) // we only fork if the Gradle JDK is not the same as the compiler JDK - if (compilerJavaHome.canonicalPath == Jvm.current().javaHome.canonicalPath) { + if (BuildParams.compilerJavaHome.canonicalPath == Jvm.current().javaHome.canonicalPath) { compileTask.options.fork = false } else { compileTask.options.fork = true - compileTask.options.forkOptions.javaHome = compilerJavaHome + compileTask.options.forkOptions.javaHome = BuildParams.compilerJavaHome } if (targetCompatibilityVersion == JavaVersion.VERSION_1_8) { globalBuildInfo.ready { @@ -543,11 +537,11 @@ class BuildPlugin implements Plugin { // also apply release flag to groovy, which is used in build-tools project.tasks.withType(GroovyCompile).configureEach({ GroovyCompile compileTask -> // we only fork if the Gradle JDK is not the same as the compiler JDK - if (compilerJavaHome.canonicalPath == Jvm.current().javaHome.canonicalPath) { + if (BuildParams.compilerJavaHome.canonicalPath == Jvm.current().javaHome.canonicalPath) { compileTask.options.fork = false } else { compileTask.options.fork = true - compileTask.options.forkOptions.javaHome = compilerJavaHome + compileTask.options.forkOptions.javaHome = BuildParams.compilerJavaHome compileTask.options.compilerArgs << '--release' << JavaVersion.toVersion(compileTask.targetCompatibility).majorVersion } } as Action) @@ -566,11 +560,10 @@ class BuildPlugin implements Plugin { classes.add(javaCompile.destinationDir) } project.tasks.withType(Javadoc).configureEach { Javadoc javadoc -> - File compilerJavaHome = project.extensions.getByType(ExtraPropertiesExtension).get('compilerJavaHome') as File // only explicitly set javadoc executable if compiler JDK is different from Gradle // this ensures better cacheability as setting ths input to an absolute path breaks portability - if (Files.isSameFile(compilerJavaHome.toPath(), Jvm.current().getJavaHome().toPath()) == false) { - javadoc.executable = new File(compilerJavaHome, 'bin/javadoc') + if (Files.isSameFile(BuildParams.compilerJavaHome.toPath(), Jvm.current().getJavaHome().toPath()) == false) { + javadoc.executable = new File(BuildParams.compilerJavaHome, 'bin/javadoc') } javadoc.classpath = javadoc.getClasspath().filter { f -> return classes.contains(f) == false @@ -625,13 +618,13 @@ class BuildPlugin implements Plugin { jarTask.doFirst { // this doFirst is added before the info plugin, therefore it will run // after the doFirst added by the info plugin, and we can override attributes - JavaVersion compilerJavaVersion = ext.get('compilerJavaVersion') as JavaVersion + JavaVersion compilerJavaVersion = BuildParams.compilerJavaVersion jarTask.manifest.attributes( - 'Change': ext.get('gitRevision'), + 'Change': BuildParams.gitRevision, 'X-Compile-Elasticsearch-Version': VersionProperties.elasticsearch, 'X-Compile-Lucene-Version': VersionProperties.lucene, 'X-Compile-Elasticsearch-Snapshot': VersionProperties.isElasticsearchSnapshot(), - 'Build-Date': ext.get('buildDate'), + 'Build-Date': BuildParams.buildDate, 'Build-Java-Version': compilerJavaVersion) } } @@ -718,19 +711,19 @@ class BuildPlugin implements Plugin { project.mkdir(heapdumpDir) project.mkdir(test.workingDir) - if (project.property('inFipsJvm')) { - nonInputProperties.systemProperty('runtime.java', "${-> (ext.get('runtimeJavaVersion') as JavaVersion).getMajorVersion()}FIPS") + if (BuildParams.inFipsJvm) { + nonInputProperties.systemProperty('runtime.java', "${-> BuildParams.runtimeJavaVersion.majorVersion}FIPS") } else { - nonInputProperties.systemProperty('runtime.java', "${-> (ext.get('runtimeJavaVersion') as JavaVersion).getMajorVersion()}") + nonInputProperties.systemProperty('runtime.java', "${-> BuildParams.runtimeJavaVersion.majorVersion}") } - if ((ext.get('runtimeJavaVersion') as JavaVersion) >= JavaVersion.VERSION_1_9) { + if (BuildParams.runtimeJavaVersion >= JavaVersion.VERSION_1_9) { test.jvmArgs '--illegal-access=warn' } //TODO remove once jvm.options are added to test system properties - if ((ext.get('runtimeJavaVersion') as JavaVersion) == JavaVersion.VERSION_1_8) { + if (BuildParams.runtimeJavaVersion == JavaVersion.VERSION_1_8) { test.systemProperty ('java.locale.providers','SPI,JRE') - } else if ((ext.get('runtimeJavaVersion') as JavaVersion) >= JavaVersion.VERSION_1_9) { + } else if (BuildParams.runtimeJavaVersion >= JavaVersion.VERSION_1_9) { test.systemProperty ('java.locale.providers','SPI,COMPAT') } } @@ -738,9 +731,9 @@ class BuildPlugin implements Plugin { test.jvmArgumentProviders.add(nonInputProperties) test.extensions.add('nonInputProperties', nonInputProperties) - test.executable = "${ext.get('runtimeJavaHome')}/bin/java" + test.executable = "${BuildParams.runtimeJavaHome}/bin/java" test.workingDir = project.file("${project.buildDir}/testrun/${test.name}") - test.maxParallelForks = System.getProperty('tests.jvms', project.rootProject.extensions.extraProperties.get('defaultParallel').toString()) as Integer + test.maxParallelForks = System.getProperty('tests.jvms', BuildParams.defaultParallel.toString()) as Integer test.exclude '**/*$*.class' @@ -770,16 +763,16 @@ class BuildPlugin implements Plugin { // ignore changing test seed when build is passed -Dignore.tests.seed for cacheability experimentation if (System.getProperty('ignore.tests.seed') != null) { - nonInputProperties.systemProperty('tests.seed', project.property('testSeed')) + nonInputProperties.systemProperty('tests.seed', BuildParams.testSeed) } else { - test.systemProperty('tests.seed', project.property('testSeed')) + test.systemProperty('tests.seed', BuildParams.testSeed) } // don't track these as inputs since they contain absolute paths and break cache relocatability nonInputProperties.systemProperty('gradle.worker.jar', "${project.gradle.getGradleUserHomeDir()}/caches/${project.gradle.gradleVersion}/workerMain/gradle-worker.jar") nonInputProperties.systemProperty('gradle.user.home', project.gradle.getGradleUserHomeDir()) - nonInputProperties.systemProperty('compiler.java', "${-> (ext.get('compilerJavaVersion') as JavaVersion).getMajorVersion()}") + nonInputProperties.systemProperty('compiler.java', "${-> BuildParams.compilerJavaVersion.majorVersion}") // TODO: remove setting logging level via system property test.systemProperty 'tests.logger.level', 'WARN' diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy index 5e324995336..f36662c092f 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/plugin/PluginBuildPlugin.groovy @@ -24,10 +24,10 @@ import org.elasticsearch.gradle.BuildPlugin import org.elasticsearch.gradle.NoticeTask import org.elasticsearch.gradle.Version import org.elasticsearch.gradle.VersionProperties +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.test.RestIntegTestTask import org.elasticsearch.gradle.testclusters.RunTask import org.elasticsearch.gradle.testclusters.TestClustersPlugin -import org.elasticsearch.gradle.tool.ClasspathUtils import org.gradle.api.InvalidUserDataException import org.gradle.api.Plugin import org.gradle.api.Project @@ -163,7 +163,7 @@ class PluginBuildPlugin implements Plugin { private static void configureDependencies(Project project) { project.dependencies { - if (ClasspathUtils.isElasticsearchProject(project)) { + if (BuildParams.internal) { compileOnly project.project(':server') testCompile project.project(':test:framework') } else { diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy index 17329ec9465..8bc47407b17 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy @@ -23,7 +23,7 @@ import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis import de.thetaphi.forbiddenapis.gradle.ForbiddenApisPlugin import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask import org.elasticsearch.gradle.VersionProperties -import org.elasticsearch.gradle.tool.ClasspathUtils +import org.elasticsearch.gradle.info.BuildParams import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import org.gradle.api.plugins.JavaBasePlugin @@ -46,7 +46,7 @@ class PrecommitTasks { } Configuration jarHellConfig = project.configurations.create("jarHell") - if (ClasspathUtils.isElasticsearchProject(project) && project.path.equals(":libs:elasticsearch-core") == false) { + if (BuildParams.internal && project.path.equals(":libs:elasticsearch-core") == false) { // External plugins will depend on this already via transitive dependencies. // Internal projects are not all plugins, so make sure the check is available // we are not doing this for this project itself to avoid jar hell with itself @@ -132,8 +132,8 @@ class PrecommitTasks { return project.tasks.register('thirdPartyAudit', ThirdPartyAuditTask) { task -> task.dependsOn(buildResources) task.signatureFile = buildResources.copy("forbidden/third-party-audit.txt") - task.javaHome = project.runtimeJavaHome - task.targetCompatibility.set(project.provider({ project.runtimeJavaVersion })) + task.javaHome = BuildParams.runtimeJavaHome + task.targetCompatibility.set(project.provider({ BuildParams.runtimeJavaVersion })) } } @@ -144,13 +144,13 @@ class PrecommitTasks { dependsOn(buildResources) doFirst { // we need to defer this configuration since we don't know the runtime java version until execution time - targetCompatibility = project.runtimeJavaVersion.getMajorVersion() + targetCompatibility = BuildParams.runtimeJavaVersion.majorVersion /* TODO: Reenable once Gradle supports Java 13 or later! - if (project.runtimeJavaVersion > JavaVersion.VERSION_13) { + if (BuildParams.runtimeJavaVersion > JavaVersion.VERSION_13) { project.logger.info( "Forbidden APIs does not support java version past 13. Will use the signatures from 13 for ", - project.runtimeJavaVersion + BuildParams.runtimeJavaVersion` ) targetCompatibility = JavaVersion.VERSION_13.getMajorVersion() } @@ -251,7 +251,7 @@ class PrecommitTasks { } private static TaskProvider configureLoggerUsage(Project project) { - Object dependency = ClasspathUtils.isElasticsearchProject(project) ? project.project(':test:logger-usage') : + Object dependency = BuildParams.internal ? project.project(':test:logger-usage') : "org.elasticsearch.test:logger-usage:${VersionProperties.elasticsearch}" project.configurations.create('loggerUsagePlugin') diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy index 4327cbea767..04c49d24d68 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy @@ -25,6 +25,7 @@ import org.elasticsearch.gradle.BwcVersions import org.elasticsearch.gradle.LoggedExec import org.elasticsearch.gradle.Version import org.elasticsearch.gradle.VersionProperties +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.plugin.PluginBuildPlugin import org.elasticsearch.gradle.plugin.PluginPropertiesExtension import org.gradle.api.AntBuilder @@ -706,7 +707,7 @@ class ClusterFormationTasks { } public static boolean useRuntimeJava(Project project, NodeInfo node) { - return (project.isRuntimeJavaHomeSet || + return (BuildParams.isRuntimeJavaHomeSet || (node.isBwcNode == false && node.nodeVersion.before(Version.fromString("7.0.0"))) || node.config.distribution == 'integ-test-zip') } @@ -762,7 +763,7 @@ class ClusterFormationTasks { start.doLast(elasticsearchRunner) start.doFirst { // If the node runs in a FIPS 140-2 JVM, the BCFKS default keystore will be password protected - if (project.inFipsJvm){ + if (BuildParams.inFipsJvm) { node.config.systemProperties.put('javax.net.ssl.trustStorePassword', 'password') node.config.systemProperties.put('javax.net.ssl.keyStorePassword', 'password') } diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/DistroTestPlugin.java b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/DistroTestPlugin.java index f91257a9730..30b03a4a467 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/DistroTestPlugin.java +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/DistroTestPlugin.java @@ -30,6 +30,7 @@ import org.elasticsearch.gradle.Jdk; import org.elasticsearch.gradle.JdkDownloadPlugin; import org.elasticsearch.gradle.Version; import org.elasticsearch.gradle.VersionProperties; +import org.elasticsearch.gradle.info.BuildParams; import org.elasticsearch.gradle.vagrant.BatsProgressLogger; import org.elasticsearch.gradle.vagrant.VagrantBasePlugin; import org.elasticsearch.gradle.vagrant.VagrantExtension; @@ -163,8 +164,7 @@ public class DistroTestPlugin implements Plugin { return Version.fromString(project.getVersion().toString()); } - ExtraPropertiesExtension rootExtraProperties = project.getRootProject().getExtensions().getByType(ExtraPropertiesExtension.class); - String firstPartOfSeed = rootExtraProperties.get("testSeed").toString().split(":")[0]; + String firstPartOfSeed = BuildParams.getTestSeed().split(":")[0]; final long seed = Long.parseUnsignedLong(firstPartOfSeed, 16); BwcVersions bwcVersions = (BwcVersions) extraProperties.get("bwcVersions"); final List indexCompatVersions = bwcVersions.getIndexCompatible(); diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy index 879a22292d3..b971842defd 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/RestIntegTestTask.groovy @@ -19,10 +19,10 @@ package org.elasticsearch.gradle.test import org.elasticsearch.gradle.VersionProperties +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.testclusters.ElasticsearchCluster import org.elasticsearch.gradle.testclusters.RestTestRunnerTask import org.elasticsearch.gradle.tool.Boilerplate -import org.elasticsearch.gradle.tool.ClasspathUtils import org.gradle.api.DefaultTask import org.gradle.api.Task import org.gradle.api.file.FileCopyDetails @@ -47,7 +47,7 @@ class RestIntegTestTask extends DefaultTask { project.testClusters { "$name" { - javaHome = project.file(project.ext.runtimeJavaHome) + javaHome = BuildParams.runtimeJavaHome } } runner.useCluster project.testClusters."$name" @@ -120,7 +120,7 @@ class RestIntegTestTask extends DefaultTask { Boilerplate.maybeCreate(project.configurations, 'restSpec') { project.dependencies.add( 'restSpec', - ClasspathUtils.isElasticsearchProject(project) ? project.project(':rest-api-spec') : + BuildParams.internal ? project.project(':rest-api-spec') : "org.elasticsearch:rest-api-spec:${VersionProperties.elasticsearch}" ) } diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy index 539b6fa7632..b3d323bf394 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/StandaloneRestTestPlugin.groovy @@ -23,6 +23,7 @@ package org.elasticsearch.gradle.test import groovy.transform.CompileStatic import org.elasticsearch.gradle.BuildPlugin import org.elasticsearch.gradle.ExportElasticsearchBuildResourcesTask +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.info.GlobalBuildInfoPlugin import org.elasticsearch.gradle.precommit.PrecommitTasks import org.elasticsearch.gradle.testclusters.TestClustersPlugin @@ -67,8 +68,8 @@ class StandaloneRestTestPlugin implements Plugin { BuildPlugin.configureFips140(project) ExtraPropertiesExtension ext = project.extensions.getByType(ExtraPropertiesExtension) - project.extensions.getByType(JavaPluginExtension).sourceCompatibility = ext.get('minimumRuntimeVersion') as JavaVersion - project.extensions.getByType(JavaPluginExtension).targetCompatibility = ext.get('minimumRuntimeVersion') as JavaVersion + project.extensions.getByType(JavaPluginExtension).sourceCompatibility = BuildParams.minimumRuntimeVersion + project.extensions.getByType(JavaPluginExtension).targetCompatibility = BuildParams.minimumRuntimeVersion // only setup tests to build SourceSetContainer sourceSets = project.extensions.getByType(SourceSetContainer) diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java index 3bf7b5d67c7..d012aa2b924 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/DistributionDownloadPlugin.java @@ -22,7 +22,7 @@ package org.elasticsearch.gradle; import org.elasticsearch.gradle.ElasticsearchDistribution.Flavor; import org.elasticsearch.gradle.ElasticsearchDistribution.Platform; import org.elasticsearch.gradle.ElasticsearchDistribution.Type; -import org.elasticsearch.gradle.tool.ClasspathUtils; +import org.elasticsearch.gradle.info.BuildParams; import org.gradle.api.GradleException; import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.Plugin; @@ -75,7 +75,7 @@ public class DistributionDownloadPlugin implements Plugin { setupDownloadServiceRepo(project); - if (ClasspathUtils.isElasticsearchProject(project)) { + if (BuildParams.isInternal()) { ExtraPropertiesExtension extraProperties = project.getExtensions().getExtraProperties(); this.bwcVersions = (BwcVersions) extraProperties.get("bwcVersions"); } @@ -179,7 +179,7 @@ public class DistributionDownloadPlugin implements Plugin { return; } addIvyRepo(project, DOWNLOAD_REPO_NAME, "https://artifacts.elastic.co", FAKE_IVY_GROUP); - if (ClasspathUtils.isElasticsearchProject(project) == false) { + if (BuildParams.isInternal() == false) { // external, so add snapshot repo as well addIvyRepo(project, SNAPSHOT_REPO_NAME, "https://snapshots.elastic.co", FAKE_SNAPSHOT_IVY_GROUP); } @@ -198,7 +198,7 @@ public class DistributionDownloadPlugin implements Plugin { */ private Object dependencyNotation(Project project, ElasticsearchDistribution distribution) { - if (ClasspathUtils.isElasticsearchProject(project)) { + if (BuildParams.isInternal()) { // non-external project, so depend on local build if (VersionProperties.getElasticsearch().equals(distribution.getVersion())) { diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/ReaperService.java b/buildSrc/src/main/java/org/elasticsearch/gradle/ReaperService.java index 329534a4dd2..28538efc4e3 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/ReaperService.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/ReaperService.java @@ -19,7 +19,7 @@ package org.elasticsearch.gradle; -import org.elasticsearch.gradle.tool.ClasspathUtils; +import org.elasticsearch.gradle.info.BuildParams; import org.gradle.api.GradleException; import org.gradle.api.Project; import org.gradle.api.logging.Logger; @@ -50,7 +50,7 @@ public class ReaperService { public ReaperService(Project project, Path buildDir, Path inputDir) { this.logger = project.getLogger(); - this.isInternal = ClasspathUtils.isElasticsearchProject(project); + this.isInternal = BuildParams.isInternal(); this.buildDir = buildDir; this.inputDir = inputDir; this.logFile = inputDir.resolve("reaper.log"); diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/info/BuildParams.java b/buildSrc/src/main/java/org/elasticsearch/gradle/info/BuildParams.java new file mode 100644 index 00000000000..2cb5204b8b4 --- /dev/null +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/info/BuildParams.java @@ -0,0 +1,239 @@ +package org.elasticsearch.gradle.info; + +import org.gradle.api.JavaVersion; + +import java.io.File; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.reflect.Modifier; +import java.time.ZonedDateTime; +import java.util.Arrays; +import java.util.List; +import java.util.function.Consumer; + +import static java.util.Objects.requireNonNull; + +public class BuildParams { + private static File compilerJavaHome; + private static File runtimeJavaHome; + private static Boolean isRuntimeJavaHomeSet; + private static List javaVersions; + private static JavaVersion minimumCompilerVersion; + private static JavaVersion minimumRuntimeVersion; + private static JavaVersion gradleJavaVersion; + private static JavaVersion compilerJavaVersion; + private static JavaVersion runtimeJavaVersion; + private static Boolean inFipsJvm; + private static String gitRevision; + private static ZonedDateTime buildDate; + private static String testSeed; + private static Boolean isCi; + private static Boolean isInternal; + private static Integer defaultParallel; + + /** + * Initialize global build parameters. This method accepts and a initialization function which in turn accepts a + * {@link MutableBuildParams}. Initialization can be done in "stages", therefore changes override existing values, and values from + * previous calls to {@link #init(Consumer)} carry forward. In cases where you want to clear existing values + * {@link MutableBuildParams#reset()} may be used. + * + * @param initializer Build parameter initializer + */ + public static void init(Consumer initializer) { + initializer.accept(MutableBuildParams.INSTANCE); + } + + public static File getCompilerJavaHome() { + return value(compilerJavaHome); + } + + public static File getRuntimeJavaHome() { + return value(runtimeJavaHome); + } + + public static Boolean getIsRuntimeJavaHomeSet() { + return value(isRuntimeJavaHomeSet); + } + + public static List getJavaVersions() { + return value(javaVersions); + } + + public static JavaVersion getMinimumCompilerVersion() { + return value(minimumCompilerVersion); + } + + public static JavaVersion getMinimumRuntimeVersion() { + return value(minimumRuntimeVersion); + } + + public static JavaVersion getGradleJavaVersion() { + return value(gradleJavaVersion); + } + + @ExecutionTime + public static JavaVersion getCompilerJavaVersion() { + return value(compilerJavaVersion); + } + + @ExecutionTime + public static JavaVersion getRuntimeJavaVersion() { + return value(runtimeJavaVersion); + } + + @ExecutionTime + public static Boolean isInFipsJvm() { + return value(inFipsJvm); + } + + public static String getGitRevision() { + return value(gitRevision); + } + + public static ZonedDateTime getBuildDate() { + return value(buildDate); + } + + public static String getTestSeed() { + return value(testSeed); + } + + public static Boolean isCi() { + return value(isCi); + } + + public static Boolean isInternal() { + return value(isInternal); + } + + public static Integer getDefaultParallel() { + return value(defaultParallel); + } + + private static T value(T object) { + if (object == null) { + String callingMethod = Thread.currentThread().getStackTrace()[2].getMethodName(); + boolean executionTime; + try { + executionTime = BuildParams.class.getMethod(callingMethod).getAnnotation(ExecutionTime.class) != null; + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + + String message = "Build parameter '" + propertyName(callingMethod) + "' has not been initialized. "; + if (executionTime) { + message += "This property is initialized at execution time, " + + "please ensure you are not attempting to access it during project configuration."; + } else { + message += "Perhaps the plugin responsible for initializing this property has not been applied."; + } + + throw new IllegalStateException(message); + } + + return object; + } + + private static String propertyName(String methodName) { + String propertyName = methodName.substring("get".length()); + return propertyName.substring(0, 1).toLowerCase() + propertyName.substring(1); + } + + public static class MutableBuildParams { + private static MutableBuildParams INSTANCE = new MutableBuildParams(); + + private MutableBuildParams() { } + + /** + * Resets any existing values from previous initializations. + */ + public void reset() { + Arrays.stream(BuildParams.class.getDeclaredFields()) + .filter(f -> Modifier.isStatic(f.getModifiers())) + .forEach(f -> { + try { + f.setAccessible(true); + f.set(null, null); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + }); + } + + public void setCompilerJavaHome(File compilerJavaHome) { + BuildParams.compilerJavaHome = requireNonNull(compilerJavaHome); + } + + public void setRuntimeJavaHome(File runtimeJavaHome) { + BuildParams.runtimeJavaHome = requireNonNull(runtimeJavaHome); + } + + public void setIsRutimeJavaHomeSet(boolean isRutimeJavaHomeSet) { + BuildParams.isRuntimeJavaHomeSet = isRutimeJavaHomeSet; + } + + public void setJavaVersions(List javaVersions) { + BuildParams.javaVersions = requireNonNull(javaVersions); + } + + public void setMinimumCompilerVersion(JavaVersion minimumCompilerVersion) { + BuildParams.minimumCompilerVersion = requireNonNull(minimumCompilerVersion); + } + + public void setMinimumRuntimeVersion(JavaVersion minimumRuntimeVersion) { + BuildParams.minimumRuntimeVersion = requireNonNull(minimumRuntimeVersion); + } + + public void setGradleJavaVersion(JavaVersion gradleJavaVersion) { + BuildParams.gradleJavaVersion = requireNonNull(gradleJavaVersion); + } + + public void setCompilerJavaVersion(JavaVersion compilerJavaVersion) { + BuildParams.compilerJavaVersion = requireNonNull(compilerJavaVersion); + } + + public void setRuntimeJavaVersion(JavaVersion runtimeJavaVersion) { + BuildParams.runtimeJavaVersion = requireNonNull(runtimeJavaVersion); + } + + public void setInFipsJvm(boolean inFipsJvm) { + BuildParams.inFipsJvm = inFipsJvm; + } + + public void setGitRevision(String gitRevision) { + BuildParams.gitRevision = requireNonNull(gitRevision); + } + + public void setBuildDate(ZonedDateTime buildDate) { + BuildParams.buildDate = requireNonNull(buildDate); + } + + public void setTestSeed(String testSeed) { + BuildParams.testSeed = requireNonNull(testSeed); + } + + public void setIsCi(boolean isCi) { + BuildParams.isCi = isCi; + } + + public void setIsInternal(Boolean isInternal) { + BuildParams.isInternal = requireNonNull(isInternal); + } + + public void setDefaultParallel(int defaultParallel) { + BuildParams.defaultParallel = defaultParallel; + } + } + + /** + * Indicates that a build parameter is initialized at task execution time and is not available at project configuration time. + * Attempts to read an uninitialized parameter wil result in an {@link IllegalStateException}. + */ + @Target({ElementType.METHOD, ElementType.FIELD}) + @Retention(RetentionPolicy.RUNTIME) + @Documented + public @interface ExecutionTime {} +} diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java b/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java index 8577305a7b2..4e9e67fb1e8 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/info/GlobalBuildInfoPlugin.java @@ -5,7 +5,6 @@ import org.gradle.api.GradleException; import org.gradle.api.JavaVersion; import org.gradle.api.Plugin; import org.gradle.api.Project; -import org.gradle.api.plugins.ExtraPropertiesExtension; import org.gradle.internal.jvm.Jvm; import java.io.BufferedReader; @@ -88,7 +87,23 @@ public class GlobalBuildInfoPlugin implements Plugin { task.setGlobalInfoListeners(extension.listeners); }); - project.getExtensions().getByType(ExtraPropertiesExtension.class).set("defaultParallel", findDefaultParallel(project)); + // Initialize global build parameters + BuildParams.init(params -> { + params.reset(); + params.setCompilerJavaHome(compilerJavaHome); + params.setRuntimeJavaHome(runtimeJavaHome); + params.setIsRutimeJavaHomeSet(compilerJavaHome.equals(runtimeJavaHome) == false); + params.setJavaVersions(javaVersions); + params.setMinimumCompilerVersion(minimumCompilerVersion); + params.setMinimumRuntimeVersion(minimumRuntimeVersion); + params.setGradleJavaVersion(Jvm.current().getJavaVersion()); + params.setGitRevision(gitRevision(project.getRootProject().getRootDir())); + params.setBuildDate(ZonedDateTime.now(ZoneOffset.UTC)); + params.setTestSeed(testSeed); + params.setIsCi(System.getenv("JENKINS_URL") != null); + params.setIsInternal(GlobalBuildInfoPlugin.class.getResource("/buildSrc.marker") != null); + params.setDefaultParallel(findDefaultParallel(project)); + }); project.allprojects(p -> { // Make sure than any task execution generates and prints build info @@ -97,21 +112,6 @@ public class GlobalBuildInfoPlugin implements Plugin { task.dependsOn(printTask); } }); - - ExtraPropertiesExtension ext = p.getExtensions().getByType(ExtraPropertiesExtension.class); - - ext.set("compilerJavaHome", compilerJavaHome); - ext.set("runtimeJavaHome", runtimeJavaHome); - ext.set("isRuntimeJavaHomeSet", compilerJavaHome.equals(runtimeJavaHome) == false); - ext.set("javaVersions", javaVersions); - ext.set("minimumCompilerVersion", minimumCompilerVersion); - ext.set("minimumRuntimeVersion", minimumRuntimeVersion); - ext.set("gradleJavaVersion", Jvm.current().getJavaVersion()); - ext.set("gitRevision", gitRevision(project.getRootProject().getRootDir())); - ext.set("buildDate", ZonedDateTime.now(ZoneOffset.UTC)); - ext.set("testSeed", testSeed); - ext.set("isCi", System.getenv("JENKINS_URL") != null); - ext.set("isInternal", GlobalBuildInfoPlugin.class.getResource("/buildSrc.marker") != null); }); } diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/info/PrintGlobalBuildInfoTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/info/PrintGlobalBuildInfoTask.java index b83fe29b073..ed0ede14164 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/info/PrintGlobalBuildInfoTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/info/PrintGlobalBuildInfoTask.java @@ -4,7 +4,6 @@ import org.gradle.api.DefaultTask; import org.gradle.api.JavaVersion; import org.gradle.api.file.RegularFileProperty; import org.gradle.api.model.ObjectFactory; -import org.gradle.api.plugins.ExtraPropertiesExtension; import org.gradle.api.resources.TextResource; import org.gradle.api.tasks.InputFile; import org.gradle.api.tasks.TaskAction; @@ -57,7 +56,7 @@ public class PrintGlobalBuildInfoTask extends DefaultTask { getLogger().quiet("======================================="); getLogger().quiet("Elasticsearch Build Hamster says Hello!"); getLogger().quiet(getFileText(getBuildInfoFile()).asString()); - getLogger().quiet(" Random Testing Seed : " + getProject().property("testSeed")); + getLogger().quiet(" Random Testing Seed : " + BuildParams.getTestSeed()); getLogger().quiet("======================================="); setGlobalProperties(); @@ -74,11 +73,10 @@ public class PrintGlobalBuildInfoTask extends DefaultTask { } private void setGlobalProperties() { - getProject().getRootProject().allprojects(p -> { - ExtraPropertiesExtension ext = p.getExtensions().getByType(ExtraPropertiesExtension.class); - ext.set("compilerJavaVersion", JavaVersion.valueOf(getFileText(getCompilerVersionFile()).asString())); - ext.set("runtimeJavaVersion", JavaVersion.valueOf(getFileText(getRuntimeVersionFile()).asString())); - ext.set("inFipsJvm", Boolean.valueOf(getFileText(getFipsJvmFile()).asString())); + BuildParams.init(params -> { + params.setCompilerJavaVersion(JavaVersion.valueOf(getFileText(getCompilerVersionFile()).asString())); + params.setRuntimeJavaVersion(JavaVersion.valueOf(getFileText(getRuntimeVersionFile()).asString())); + params.setInFipsJvm(Boolean.parseBoolean(getFileText(getFipsJvmFile()).asString())); }); } } diff --git a/buildSrc/src/test/java/org/elasticsearch/gradle/DistributionDownloadPluginTests.java b/buildSrc/src/test/java/org/elasticsearch/gradle/DistributionDownloadPluginTests.java index d68869be482..00c9bf20a56 100644 --- a/buildSrc/src/test/java/org/elasticsearch/gradle/DistributionDownloadPluginTests.java +++ b/buildSrc/src/test/java/org/elasticsearch/gradle/DistributionDownloadPluginTests.java @@ -22,6 +22,7 @@ package org.elasticsearch.gradle; import org.elasticsearch.gradle.ElasticsearchDistribution.Flavor; import org.elasticsearch.gradle.ElasticsearchDistribution.Platform; import org.elasticsearch.gradle.ElasticsearchDistribution.Type; +import org.elasticsearch.gradle.info.BuildParams; import org.elasticsearch.gradle.test.GradleUnitTestCase; import org.gradle.api.NamedDomainObjectContainer; import org.gradle.api.Project; @@ -234,7 +235,7 @@ public class DistributionDownloadPluginTests extends GradleUnitTestCase { private Project createProject(BwcVersions bwcVersions, boolean isInternal) { rootProject = ProjectBuilder.builder().build(); - rootProject.getExtensions().getExtraProperties().set("isInternal", isInternal); + BuildParams.init(params -> params.setIsInternal(isInternal)); Project distributionProject = ProjectBuilder.builder().withParent(rootProject).withName("distribution").build(); archivesProject = ProjectBuilder.builder().withParent(distributionProject).withName("archives").build(); packagesProject = ProjectBuilder.builder().withParent(distributionProject).withName("packages").build(); @@ -243,7 +244,6 @@ public class DistributionDownloadPluginTests extends GradleUnitTestCase { if (bwcVersions != null) { project.getExtensions().getExtraProperties().set("bwcVersions", bwcVersions); } - project.getExtensions().getExtraProperties().set("isInternal", isInternal); project.getPlugins().apply("elasticsearch.distribution-download"); return project; } diff --git a/buildSrc/src/testKit/distribution-download/build.gradle b/buildSrc/src/testKit/distribution-download/build.gradle index fd6c8e12de4..fbdddd3f4f3 100644 --- a/buildSrc/src/testKit/distribution-download/build.gradle +++ b/buildSrc/src/testKit/distribution-download/build.gradle @@ -1,5 +1,7 @@ import org.elasticsearch.gradle.BwcVersions import org.elasticsearch.gradle.Version +import org.elasticsearch.gradle.info.BuildParams + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -23,6 +25,7 @@ plugins { id 'elasticsearch.global-build-info' } boolean internal = Boolean.parseBoolean(System.getProperty("tests.internal", "true")) +BuildParams.init { it.setIsInternal(internal) } project.gradle.projectsEvaluated { // wire the download service url to wiremock @@ -41,10 +44,6 @@ project.gradle.projectsEvaluated { } } -allprojects { - ext.isInternal = internal -} - if (internal) { Version currentVersion = Version.fromString("9.0.0") BwcVersions versions = new BwcVersions(new TreeSet<>( diff --git a/distribution/bwc/build.gradle b/distribution/bwc/build.gradle index 3642efa7746..9666c4111a2 100644 --- a/distribution/bwc/build.gradle +++ b/distribution/bwc/build.gradle @@ -21,6 +21,7 @@ import org.apache.tools.ant.taskdefs.condition.Os import org.elasticsearch.gradle.LoggedExec import org.elasticsearch.gradle.Version import org.elasticsearch.gradle.BwcVersions +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.info.GlobalBuildInfoPlugin import java.nio.charset.StandardCharsets @@ -225,7 +226,7 @@ bwcVersions.forPreviousUnreleased { BwcVersions.UnreleasedVersionInfo unreleased 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 - project.ext.isCi && System.getenv('GIT_BRANCH')?.endsWith("master") == false + BuildParams.ci && System.getenv('GIT_BRANCH')?.endsWith("master") == false } args ":${projectDir.replace('/', ':')}:assemble" if (project.gradle.startParameter.buildCacheEnabled) { diff --git a/distribution/docker/build.gradle b/distribution/docker/build.gradle index e813279b3b1..5ef8f212c1d 100644 --- a/distribution/docker/build.gradle +++ b/distribution/docker/build.gradle @@ -1,7 +1,8 @@ import org.elasticsearch.gradle.BuildPlugin import org.elasticsearch.gradle.LoggedExec import org.elasticsearch.gradle.VersionProperties -import org.elasticsearch.gradle.testfixtures.TestFixturesPlugin +import org.elasticsearch.gradle.info.BuildParams +import org.elasticsearch.gradle.testfixtures.TestFixturesPlugin apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.test.fixtures' @@ -26,9 +27,9 @@ ext.expansions = { oss, ubi, local -> final String elasticsearch = oss ? "elasticsearch-oss-${VersionProperties.elasticsearch}-${classifier}.tar.gz" : "elasticsearch-${VersionProperties.elasticsearch}-${classifier}.tar.gz" return [ 'base_image' : ubi ? 'registry.access.redhat.com/ubi7/ubi-minimal:7.7' : 'centos:7', - 'build_date' : project.ext.buildDate, + 'build_date' : BuildParams.buildDate, 'elasticsearch' : elasticsearch, - 'git_revision' : project.ext.gitRevision, + 'git_revision' : BuildParams.gitRevision, 'license' : oss ? 'Apache-2.0' : 'Elastic-License', 'package_manager' : ubi ? 'microdnf' : 'yum', 'source_elasticsearch': local ? "COPY $elasticsearch /opt/" : "RUN cd /opt && curl --retry 8 -s -L -O https://artifacts.elastic.co/downloads/elasticsearch/${elasticsearch} && cd -", diff --git a/distribution/tools/plugin-cli/build.gradle b/distribution/tools/plugin-cli/build.gradle index 9a9436d22fa..700138bb24d 100644 --- a/distribution/tools/plugin-cli/build.gradle +++ b/distribution/tools/plugin-cli/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -43,7 +45,7 @@ test { thirdPartyAudit.onlyIf { // FIPS JVM includes manny classes from bouncycastle which count as jar hell for the third party audit, // rather than provide a long list of exclusions, disable the check on FIPS. - project.inFipsJvm == false + BuildParams.inFipsJvm } /* diff --git a/libs/core/build.gradle b/libs/core/build.gradle index 7159b760b22..79129b4db8c 100644 --- a/libs/core/build.gradle +++ b/libs/core/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -48,7 +50,7 @@ if (!isEclipse && !isIdea) { forbiddenApisJava9 { rootProject.globalInfo.ready { - if (project.runtimeJavaVersion < JavaVersion.VERSION_1_9) { + if (BuildParams.runtimeJavaVersion < JavaVersion.VERSION_1_9) { targetCompatibility = JavaVersion.VERSION_1_9.getMajorVersion() } replaceSignatureFiles 'jdk-signatures' diff --git a/modules/reindex/build.gradle b/modules/reindex/build.gradle index 820910084a4..0c6130b5737 100644 --- a/modules/reindex/build.gradle +++ b/modules/reindex/build.gradle @@ -18,6 +18,7 @@ */ import org.apache.tools.ant.taskdefs.condition.Os +import org.elasticsearch.gradle.info.BuildParams import static org.elasticsearch.gradle.BuildPlugin.getJavaHome @@ -115,7 +116,7 @@ if (Os.isFamily(Os.FAMILY_WINDOWS)) { Task fixture = task("oldEs${version}Fixture", type: org.elasticsearch.gradle.test.AntFixture) { dependsOn project.configurations.oldesFixture dependsOn unzip - executable = new File(project.runtimeJavaHome, 'bin/java') + executable = "${BuildParams.runtimeJavaHome}/bin/java" env 'CLASSPATH', "${ -> project.configurations.oldesFixture.asPath }" env 'JAVA_HOME', "${ -> getJavaHome(it, 8)}" args 'oldes.OldElasticsearch', diff --git a/modules/repository-url/build.gradle b/modules/repository-url/build.gradle index a73af0d2cd0..b17c223dd6a 100644 --- a/modules/repository-url/build.gradle +++ b/modules/repository-url/build.gradle @@ -18,6 +18,7 @@ */ import org.elasticsearch.gradle.PropertyNormalization +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.test.AntFixture esplugin { @@ -35,7 +36,7 @@ task urlFixture(type: AntFixture) { repositoryDir.mkdirs() } env 'CLASSPATH', "${ -> project.sourceSets.test.runtimeClasspath.asPath }" - executable = new File(project.runtimeJavaHome, 'bin/java') + executable = "${BuildParams.runtimeJavaHome}/bin/java" args 'org.elasticsearch.repositories.url.URLFixture', baseDir, "${repositoryDir.absolutePath}" } diff --git a/modules/transport-netty4/build.gradle b/modules/transport-netty4/build.gradle index 9da97bd9970..4308487ba71 100644 --- a/modules/transport-netty4/build.gradle +++ b/modules/transport-netty4/build.gradle @@ -17,6 +17,8 @@ * under the License. */ + +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.test.RestIntegTestTask /* @@ -196,7 +198,7 @@ thirdPartyAudit { } rootProject.globalInfo.ready { - if (project.inFipsJvm == false) { + if (BuildParams.inFipsJvm == false) { // BouncyCastleFIPS provides this class, so the exclusion is invalid when running CI in // a FIPS JVM with BouncyCastleFIPS Provider thirdPartyAudit.ignoreMissingClasses( diff --git a/plugins/discovery-azure-classic/build.gradle b/plugins/discovery-azure-classic/build.gradle index 8fd50e3c5cf..c83cd96c101 100644 --- a/plugins/discovery-azure-classic/build.gradle +++ b/plugins/discovery-azure-classic/build.gradle @@ -1,4 +1,5 @@ import org.elasticsearch.gradle.LoggedExec +import org.elasticsearch.gradle.info.BuildParams /* * Licensed to Elasticsearch under one or more contributor @@ -69,7 +70,7 @@ task createKey(type: LoggedExec) { keystore.parentFile.mkdirs() } outputs.file(keystore).withPropertyName('keystoreFile') - executable = new File(project.runtimeJavaHome, 'bin/keytool') + executable = "${BuildParams.runtimeJavaHome}/bin/keytool" standardInput = new ByteArrayInputStream('FirstName LastName\nUnit\nOrganization\nCity\nState\nNL\nyes\n\n'.getBytes('UTF-8')) args '-genkey', '-alias', 'test-node', @@ -137,7 +138,7 @@ thirdPartyAudit.ignoreMissingClasses ( // jarhell with jdk (intentionally, because jaxb was removed from default modules in java 9) rootProject.globalInfo.ready { - if (project.runtimeJavaVersion <= JavaVersion.VERSION_1_8) { + if (BuildParams.runtimeJavaVersion <= JavaVersion.VERSION_1_8) { thirdPartyAudit.ignoreJarHellWithJDK( 'javax.xml.bind.Binder', 'javax.xml.bind.ContextFinder$1', diff --git a/plugins/discovery-ec2/build.gradle b/plugins/discovery-ec2/build.gradle index 2dcee91c481..30465b01b38 100644 --- a/plugins/discovery-ec2/build.gradle +++ b/plugins/discovery-ec2/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -110,7 +112,7 @@ thirdPartyAudit.ignoreMissingClasses ( ) rootProject.globalInfo.ready { - if (project.runtimeJavaVersion > JavaVersion.VERSION_1_8) { + if (BuildParams.runtimeJavaVersion > JavaVersion.VERSION_1_8) { thirdPartyAudit.ignoreMissingClasses( 'javax.xml.bind.DatatypeConverter', 'javax.xml.bind.JAXBContext' diff --git a/plugins/discovery-ec2/qa/amazon-ec2/build.gradle b/plugins/discovery-ec2/qa/amazon-ec2/build.gradle index 218c9aca292..5257923ee80 100644 --- a/plugins/discovery-ec2/qa/amazon-ec2/build.gradle +++ b/plugins/discovery-ec2/qa/amazon-ec2/build.gradle @@ -19,6 +19,7 @@ import org.elasticsearch.gradle.MavenFilteringHack +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.test.AntFixture import org.elasticsearch.gradle.test.RestIntegTestTask @@ -60,7 +61,7 @@ integTest.enabled = false AntFixture fixture = tasks.create(name: "ec2Fixture${action}", type: AntFixture) { dependsOn compileTestJava env 'CLASSPATH', "${ -> project.sourceSets.test.runtimeClasspath.asPath }" - executable = new File(project.runtimeJavaHome, 'bin/java') + executable = "${BuildParams.runtimeJavaHome}/bin/java" args 'org.elasticsearch.discovery.ec2.AmazonEC2Fixture', baseDir, "${buildDir}/testclusters/integTest${action}-1/config/unicast_hosts.txt" } diff --git a/plugins/discovery-gce/qa/gce/build.gradle b/plugins/discovery-gce/qa/gce/build.gradle index b0231ff7f3c..46e22add7bf 100644 --- a/plugins/discovery-gce/qa/gce/build.gradle +++ b/plugins/discovery-gce/qa/gce/build.gradle @@ -19,6 +19,7 @@ import org.elasticsearch.gradle.MavenFilteringHack +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.test.AntFixture import static org.elasticsearch.gradle.PropertyNormalization.IGNORE_VALUE @@ -36,7 +37,7 @@ dependencies { task gceFixture(type: AntFixture) { dependsOn compileTestJava env 'CLASSPATH', "${ -> project.sourceSets.test.runtimeClasspath.asPath }" - executable = new File(project.runtimeJavaHome, 'bin/java') + executable = "${BuildParams.runtimeJavaHome}/bin/java" args 'org.elasticsearch.cloud.gce.GCEFixture', baseDir, "${buildDir}/testclusters/integTest-1/config/unicast_hosts.txt" } diff --git a/plugins/examples/rest-handler/build.gradle b/plugins/examples/rest-handler/build.gradle index 14a6189f9ad..8f454fd50fa 100644 --- a/plugins/examples/rest-handler/build.gradle +++ b/plugins/examples/rest-handler/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -33,7 +35,7 @@ test.enabled = false task exampleFixture(type: org.elasticsearch.gradle.test.AntFixture) { dependsOn testClasses env 'CLASSPATH', "${ -> project.sourceSets.test.runtimeClasspath.asPath }" - executable = new File(project.runtimeJavaHome, 'bin/java') + executable = "${BuildParams.runtimeJavaHome}/bin/java" args 'org.elasticsearch.example.resthandler.ExampleFixture', baseDir, 'TEST' } diff --git a/plugins/ingest-attachment/build.gradle b/plugins/ingest-attachment/build.gradle index 00a36629be4..8bd7c8e2d39 100644 --- a/plugins/ingest-attachment/build.gradle +++ b/plugins/ingest-attachment/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -89,5 +91,5 @@ thirdPartyAudit{ thirdPartyAudit.onlyIf { // FIPS JVM includes manny classes from bouncycastle which count as jar hell for the third party audit, // rather than provide a long list of exclusions, disable the check on FIPS. - project.inFipsJvm == false + BuildParams.inFipsJvm == false } \ No newline at end of file diff --git a/plugins/repository-azure/build.gradle b/plugins/repository-azure/build.gradle index 84850e318ec..8a36d7b97af 100644 --- a/plugins/repository-azure/build.gradle +++ b/plugins/repository-azure/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -89,7 +91,7 @@ task thirdPartyTest(type: Test) { systemProperty 'test.azure.key', azureKey ? azureKey : "" systemProperty 'test.azure.sas_token', azureSasToken ? azureSasToken : "" systemProperty 'test.azure.container', azureContainer ? azureContainer : "" - systemProperty 'test.azure.base', (azureBasePath ? azureBasePath : "") + "_third_party_tests_" + project.testSeed + systemProperty 'test.azure.base', (azureBasePath ? azureBasePath : "") + "_third_party_tests_" + BuildParams.testSeed } if (azureAccount || azureKey || azureContainer || azureBasePath || azureSasToken) { diff --git a/plugins/repository-azure/qa/microsoft-azure-storage/build.gradle b/plugins/repository-azure/qa/microsoft-azure-storage/build.gradle index 04867765ba5..2425e71fc4a 100644 --- a/plugins/repository-azure/qa/microsoft-azure-storage/build.gradle +++ b/plugins/repository-azure/qa/microsoft-azure-storage/build.gradle @@ -19,6 +19,7 @@ import org.elasticsearch.gradle.MavenFilteringHack +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.test.AntFixture import static org.elasticsearch.gradle.PropertyNormalization.DEFAULT @@ -81,7 +82,7 @@ testClusters.integTest { // in a hacky way to change the protocol and endpoint. We must fix that. setting 'azure.client.integration_test.endpoint_suffix', { "ignored;DefaultEndpointsProtocol=http;BlobEndpoint=${ -> azureAddress() }" }, IGNORE_VALUE - String firstPartOfSeed = project.rootProject.testSeed.tokenize(':').get(0) + String firstPartOfSeed = BuildParams.testSeed.tokenize(':').get(0) setting 'thread_pool.repository_azure.max', (Math.abs(Long.parseUnsignedLong(firstPartOfSeed, 16) % 10) + 1).toString(), System.getProperty('ignore.tests.seed') == null ? DEFAULT : IGNORE_VALUE } } diff --git a/plugins/repository-gcs/qa/google-cloud-storage/build.gradle b/plugins/repository-gcs/qa/google-cloud-storage/build.gradle index 46c5a89cb92..c2055959ad1 100644 --- a/plugins/repository-gcs/qa/google-cloud-storage/build.gradle +++ b/plugins/repository-gcs/qa/google-cloud-storage/build.gradle @@ -19,6 +19,7 @@ import org.elasticsearch.gradle.MavenFilteringHack +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.test.AntFixture import java.nio.file.Files @@ -61,7 +62,7 @@ def encodedCredentials = { task googleCloudStorageFixture(type: AntFixture) { dependsOn testClasses env 'CLASSPATH', "${ -> project.sourceSets.test.runtimeClasspath.asPath }" - executable = new File(project.runtimeJavaHome, 'bin/java') + executable = "${BuildParams.runtimeJavaHome}/bin/java" args 'org.elasticsearch.repositories.gcs.GoogleCloudStorageFixture', baseDir, 'bucket_test' } @@ -89,7 +90,7 @@ task thirdPartyTest (type: Test) { include '**/GoogleCloudStorageThirdPartyTests.class' systemProperty 'tests.security.manager', false systemProperty 'test.google.bucket', gcsBucket - systemProperty 'test.google.base', gcsBasePath + "_third_party_tests_" + project.testSeed + systemProperty 'test.google.base', gcsBasePath + "_third_party_tests_" + BuildParams.testSeed nonInputProperties.systemProperty 'test.google.account', "${ -> encodedCredentials.call() }" } diff --git a/plugins/repository-hdfs/build.gradle b/plugins/repository-hdfs/build.gradle index b24ad28f7a3..bc2b8acbed8 100644 --- a/plugins/repository-hdfs/build.gradle +++ b/plugins/repository-hdfs/build.gradle @@ -18,6 +18,7 @@ */ import org.apache.tools.ant.taskdefs.condition.Os +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.test.RestIntegTestTask import java.nio.file.Files @@ -93,10 +94,10 @@ String krb5conf = project(':test:fixtures:krb5kdc-fixture').ext.krb5Conf("hdfs") for (String fixtureName : ['hdfsFixture', 'haHdfsFixture', 'secureHdfsFixture', 'secureHaHdfsFixture']) { project.tasks.create(fixtureName, org.elasticsearch.gradle.test.AntFixture) { dependsOn project.configurations.hdfsFixture, project(':test:fixtures:krb5kdc-fixture').tasks.postProcessFixture - executable = new File(project.runtimeJavaHome, 'bin/java') + executable = "${BuildParams.runtimeJavaHome}/bin/java" env 'CLASSPATH', "${ -> project.configurations.hdfsFixture.asPath }" maxWaitInSeconds 60 - onlyIf { project(':test:fixtures:krb5kdc-fixture').buildFixture.enabled && project.inFipsJvm == false } + onlyIf { project(':test:fixtures:krb5kdc-fixture').buildFixture.enabled && BuildParams.inFipsJvm == false } waitCondition = { fixture, ant -> // the hdfs.MiniHDFS fixture writes the ports file when // it's ready, so we can just wait for the file to exist @@ -108,7 +109,7 @@ for (String fixtureName : ['hdfsFixture', 'haHdfsFixture', 'secureHdfsFixture', if (fixtureName.equals('secureHdfsFixture') || fixtureName.equals('secureHaHdfsFixture')) { miniHDFSArgs.add("-Djava.security.krb5.conf=${project(':test:fixtures:krb5kdc-fixture').ext.krb5Conf("hdfs")}"); rootProject.globalInfo.ready { - if (project.runtimeJavaVersion == JavaVersion.VERSION_1_9) { + if (BuildParams.runtimeJavaVersion == JavaVersion.VERSION_1_9) { miniHDFSArgs.add('--add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED') } } @@ -154,7 +155,7 @@ for (String integTestTaskName : ['integTestHa', 'integTestSecure', 'integTestSec } runner { - onlyIf { project.inFipsJvm == false } + onlyIf { BuildParams.inFipsJvm == false } if (integTestTaskName.contains("Ha")) { if (integTestTaskName.contains("Secure")) { Path path = buildDir.toPath() @@ -226,7 +227,7 @@ if (legalPath == false) { // Always ignore HA integration tests in the normal integration test runner, they are included below as // part of their own HA-specific integration test tasks. integTest.runner { - onlyIf { project.inFipsJvm == false } + onlyIf { BuildParams.inFipsJvm == false } exclude('**/Ha*TestSuiteIT.class') } diff --git a/plugins/repository-s3/build.gradle b/plugins/repository-s3/build.gradle index 96be32277f4..72e97250f55 100644 --- a/plugins/repository-s3/build.gradle +++ b/plugins/repository-s3/build.gradle @@ -1,4 +1,5 @@ import org.elasticsearch.gradle.MavenFilteringHack +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.test.AntFixture import org.elasticsearch.gradle.test.RestIntegTestTask @@ -99,7 +100,7 @@ String s3EC2BasePath = System.getenv("amazon_s3_base_path_ec2") String s3ECSBucket = System.getenv("amazon_s3_bucket_ecs") String s3ECSBasePath = System.getenv("amazon_s3_base_path_ecs") -boolean s3DisableChunkedEncoding = (new Random(Long.parseUnsignedLong(project.rootProject.testSeed.tokenize(':').get(0), 16))).nextBoolean() +boolean s3DisableChunkedEncoding = (new Random(Long.parseUnsignedLong(BuildParams.testSeed.tokenize(':').get(0), 16))).nextBoolean() // If all these variables are missing then we are testing against the internal fixture instead, which has the following // credentials hard-coded in. @@ -141,7 +142,7 @@ task thirdPartyTest(type: Test) { systemProperty 'test.s3.account', s3PermanentAccessKey systemProperty 'test.s3.key', s3PermanentSecretKey systemProperty 'test.s3.bucket', s3PermanentBucket - systemProperty 'test.s3.base', s3PermanentBasePath + "_third_party_tests_" + project.testSeed + systemProperty 'test.s3.base', s3PermanentBasePath + "_third_party_tests_" + BuildParams.testSeed } if (useFixture) { @@ -225,7 +226,7 @@ File s3FixtureFile = new File(parentFixtures, 's3Fixture.properties') task s3FixtureProperties { outputs.file(s3FixtureFile) def s3FixtureOptions = [ - "tests.seed" : project.testSeed, + "tests.seed" : BuildParams.testSeed, "s3Fixture.permanent_bucket_name" : s3PermanentBucket, "s3Fixture.permanent_key" : s3PermanentAccessKey, "s3Fixture.temporary_bucket_name" : s3TemporaryBucket, @@ -248,7 +249,7 @@ task s3Fixture(type: AntFixture) { inputs.file(s3FixtureFile) env 'CLASSPATH', "${ -> project.sourceSets.test.runtimeClasspath.asPath }" - executable = new File(project.runtimeJavaHome, 'bin/java') + executable = "${BuildParams.runtimeJavaHome}/bin/java" args 'org.elasticsearch.repositories.s3.AmazonS3Fixture', baseDir, s3FixtureFile.getAbsolutePath() } @@ -354,7 +355,7 @@ thirdPartyAudit.ignoreMissingClasses ( // jarhell with jdk (intentionally, because jaxb was removed from default modules in java 9) rootProject.globalInfo.ready { - if (project.runtimeJavaVersion <= JavaVersion.VERSION_1_8) { + if (BuildParams.runtimeJavaVersion <= JavaVersion.VERSION_1_8) { thirdPartyAudit.ignoreJarHellWithJDK( 'javax.xml.bind.Binder', 'javax.xml.bind.ContextFinder$1', diff --git a/plugins/transport-nio/build.gradle b/plugins/transport-nio/build.gradle index 1c92623976f..139047c8f09 100644 --- a/plugins/transport-nio/build.gradle +++ b/plugins/transport-nio/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -154,7 +156,7 @@ thirdPartyAudit { ) } rootProject.globalInfo.ready { - if (project.inFipsJvm == false) { + if (BuildParams.inFipsJvm == false) { // BouncyCastleFIPS provides this class, so the exclusion is invalid when running CI in // a FIPS JVM with BouncyCastleFIPS Provider thirdPartyAudit.ignoreMissingClasses( diff --git a/qa/die-with-dignity/build.gradle b/qa/die-with-dignity/build.gradle index a40f6366e65..a628c3742af 100644 --- a/qa/die-with-dignity/build.gradle +++ b/qa/die-with-dignity/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -29,7 +31,7 @@ integTest.runner { systemProperty 'tests.security.manager', 'false' systemProperty 'tests.system_call_filter', 'false' nonInputProperties.systemProperty 'log', "${-> testClusters.integTest.singleNode().getServerLog()}" - systemProperty 'runtime.java.home', "${project.runtimeJavaHome}" + systemProperty 'runtime.java.home', BuildParams.runtimeJavaHome } testClusters.integTest { diff --git a/qa/full-cluster-restart/build.gradle b/qa/full-cluster-restart/build.gradle index 44bb06fc7fd..5409961e591 100644 --- a/qa/full-cluster-restart/build.gradle +++ b/qa/full-cluster-restart/build.gradle @@ -19,6 +19,7 @@ import org.elasticsearch.gradle.Version +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.testclusters.RestTestRunnerTask import org.elasticsearch.gradle.testclusters.TestDistribution @@ -41,7 +42,7 @@ for (Version bwcVersion : bwcVersions.indexCompatible) { setting 'indices.memory.shard_inactive_time', '20m' setting 'http.content_type.required', 'true' setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}" - javaHome = project.file(project.ext.runtimeJavaHome) + javaHome = BuildParams.runtimeJavaHome } } diff --git a/qa/mixed-cluster/build.gradle b/qa/mixed-cluster/build.gradle index 5f3690c293d..5783e0e0399 100644 --- a/qa/mixed-cluster/build.gradle +++ b/qa/mixed-cluster/build.gradle @@ -19,6 +19,7 @@ import org.elasticsearch.gradle.Version import org.elasticsearch.gradle.VersionProperties +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.testclusters.RestTestRunnerTask apply plugin: 'elasticsearch.testclusters' @@ -58,7 +59,7 @@ for (Version bwcVersion : bwcVersions.wireCompatible) { numberOfNodes = 4 setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}" - javaHome = project.file(project.ext.runtimeJavaHome) + javaHome = BuildParams.runtimeJavaHome } } diff --git a/qa/rolling-upgrade/build.gradle b/qa/rolling-upgrade/build.gradle index 5776fcca8e1..6e0672005e6 100644 --- a/qa/rolling-upgrade/build.gradle +++ b/qa/rolling-upgrade/build.gradle @@ -18,6 +18,7 @@ */ import org.elasticsearch.gradle.Version +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.testclusters.RestTestRunnerTask apply plugin: 'elasticsearch.testclusters' @@ -69,7 +70,7 @@ for (Version bwcVersion : bwcVersions.wireCompatible) { setting 'repositories.url.allowed_urls', 'http://snapshot.test*' setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}" setting 'http.content_type.required', 'true' - javaHome = project.file(project.ext.runtimeJavaHome) + javaHome = BuildParams.runtimeJavaHome } } diff --git a/qa/verify-version-constants/build.gradle b/qa/verify-version-constants/build.gradle index 7e472e4f01d..075e47922e2 100644 --- a/qa/verify-version-constants/build.gradle +++ b/qa/verify-version-constants/build.gradle @@ -19,6 +19,7 @@ import org.elasticsearch.gradle.Version import org.elasticsearch.gradle.VersionProperties +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.testclusters.RestTestRunnerTask apply plugin: 'elasticsearch.testclusters' @@ -36,7 +37,7 @@ for (Version bwcVersion : bwcVersions.indexCompatible) { "${baseName}" { version = bwcVersion.toString() setting 'http.content_type.required', 'true' - javaHome = project.file(project.ext.runtimeJavaHome) + javaHome = BuildParams.runtimeJavaHome } } diff --git a/server/build.gradle b/server/build.gradle index 551b1484567..c2b1c85b55b 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with @@ -57,7 +59,7 @@ if (!isEclipse && !isIdea) { forbiddenApisJava9 { doFirst { - if (project.runtimeJavaVersion < JavaVersion.VERSION_1_9) { + if (BuildParams.runtimeJavaVersion < JavaVersion.VERSION_1_9) { targetCompatibility = JavaVersion.VERSION_1_9.getMajorVersion() } } @@ -301,7 +303,7 @@ thirdPartyAudit.ignoreMissingClasses ( ) rootProject.globalInfo.ready { - if (project.runtimeJavaVersion > JavaVersion.VERSION_1_8) { + if (BuildParams.runtimeJavaVersion > JavaVersion.VERSION_1_8) { thirdPartyAudit.ignoreMissingClasses 'javax.xml.bind.DatatypeConverter' } } diff --git a/x-pack/plugin/build.gradle b/x-pack/plugin/build.gradle index 28405359bc8..30d074f86d1 100644 --- a/x-pack/plugin/build.gradle +++ b/x-pack/plugin/build.gradle @@ -1,4 +1,5 @@ import org.elasticsearch.gradle.LoggedExec +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.plugin.PluginBuildPlugin import java.nio.charset.StandardCharsets @@ -28,7 +29,7 @@ subprojects { dependsOn project.configurations.featureAwarePlugin outputs.file(successMarker) - executable = "${project.runtimeJavaHome}/bin/java" + executable = "${BuildParams.runtimeJavaHome}/bin/java" // default to main class files if such a source set exists final List files = [] @@ -45,7 +46,7 @@ subprojects { * anything above JDK 12 as JDK 13). So, to exclude JDK 14 until a newer version of ASM is available, we also have to exclude JDK * 13. See https://github.com/elastic/elasticsearch/issues/45927. */ - Integer.parseInt(project.runtimeJavaVersion.getMajorVersion()) < 13 + Integer.parseInt(BuildParams.runtimeJavaVersion.majorVersion) < 13 } doFirst { args('-cp', project.configurations.featureAwarePlugin.asPath, 'org.elasticsearch.xpack.test.feature_aware.FeatureAwareCheck') diff --git a/x-pack/plugin/security/build.gradle b/x-pack/plugin/security/build.gradle index 268234d5484..30ca038fb22 100644 --- a/x-pack/plugin/security/build.gradle +++ b/x-pack/plugin/security/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + evaluationDependsOn(xpackModule('core')) apply plugin: 'elasticsearch.esplugin' @@ -292,7 +294,7 @@ thirdPartyAudit { } rootProject.globalInfo.ready { - if (project.runtimeJavaVersion > JavaVersion.VERSION_1_8) { + if (BuildParams.runtimeJavaVersion > JavaVersion.VERSION_1_8) { thirdPartyAudit.ignoreMissingClasses( 'javax.xml.bind.JAXBContext', 'javax.xml.bind.JAXBElement', diff --git a/x-pack/plugin/security/cli/build.gradle b/x-pack/plugin/security/cli/build.gradle index af4f0ce7ed1..8f9776b2165 100644 --- a/x-pack/plugin/security/cli/build.gradle +++ b/x-pack/plugin/security/cli/build.gradle @@ -1,4 +1,5 @@ import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis +import org.elasticsearch.gradle.info.BuildParams apply plugin: 'elasticsearch.build' @@ -19,7 +20,7 @@ dependencyLicenses { } rootProject.globalInfo.ready { - if (project.inFipsJvm) { + if (BuildParams.inFipsJvm) { test.enabled = false testingConventions.enabled = false // Forbiden APIs non-portable checks fail because bouncy castle classes being used from the FIPS JDK since those are diff --git a/x-pack/plugin/sql/qa/security/with-ssl/build.gradle b/x-pack/plugin/sql/qa/security/with-ssl/build.gradle index 6a6179ae393..6b6d518b6ca 100644 --- a/x-pack/plugin/sql/qa/security/with-ssl/build.gradle +++ b/x-pack/plugin/sql/qa/security/with-ssl/build.gradle @@ -1,5 +1,6 @@ import org.elasticsearch.gradle.BuildPlugin import org.elasticsearch.gradle.LoggedExec +import org.elasticsearch.gradle.info.BuildParams import javax.net.ssl.HttpsURLConnection import javax.net.ssl.KeyManagerFactory @@ -31,7 +32,7 @@ task createNodeKeyStore(type: LoggedExec) { delete nodeKeystore } } - executable = new File(project.runtimeJavaHome, 'bin/keytool') + executable = "${BuildParams.runtimeJavaHome}/bin/keytool" standardInput = new ByteArrayInputStream('FirstName LastName\nUnit\nOrganization\nCity\nState\nNL\nyes\n\n'.getBytes('UTF-8')) args '-genkey', '-alias', 'test-node', @@ -56,7 +57,7 @@ task createClientKeyStore(type: LoggedExec) { delete clientKeyStore } } - executable = new File(project.runtimeJavaHome, 'bin/keytool') + executable = "${BuildParams.runtimeJavaHome}/bin/keytool" standardInput = new ByteArrayInputStream('FirstName LastName\nUnit\nOrganization\nCity\nState\nNL\nyes\n\n'.getBytes('UTF-8')) args '-genkey', '-alias', 'test-client', @@ -82,7 +83,7 @@ task exportNodeCertificate(type: LoggedExec) { delete nodeCertificate } } - executable = new File(project.runtimeJavaHome, 'bin/keytool') + executable = "${BuildParams.runtimeJavaHome}/bin/keytool" args '-export', '-alias', 'test-node', '-keystore', nodeKeystore, @@ -93,7 +94,7 @@ task exportNodeCertificate(type: LoggedExec) { // Import the node certificate in the client's keystore task importNodeCertificateInClientKeyStore(type: LoggedExec) { dependsOn createClientKeyStore, exportNodeCertificate - executable = new File(project.runtimeJavaHome, 'bin/keytool') + executable = "${BuildParams.runtimeJavaHome}/bin/keytool" args '-import', '-alias', 'test-node', '-keystore', clientKeyStore, @@ -114,7 +115,7 @@ task exportClientCertificate(type: LoggedExec) { delete clientCertificate } } - executable = new File(project.runtimeJavaHome, 'bin/keytool') + executable = "${BuildParams.runtimeJavaHome}/bin/keytool" args '-export', '-alias', 'test-client', '-keystore', clientKeyStore, @@ -125,7 +126,7 @@ task exportClientCertificate(type: LoggedExec) { // Import the client certificate in the node's keystore task importClientCertificateInNodeKeyStore(type: LoggedExec) { dependsOn createNodeKeyStore, exportClientCertificate - executable = new File(project.runtimeJavaHome, 'bin/keytool') + executable = "${BuildParams.runtimeJavaHome}/bin/keytool" args '-import', '-alias', 'test-client', '-keystore', nodeKeystore, @@ -148,7 +149,7 @@ integTest.runner { // Do not attempt to form a cluster in a FIPS JVM, as doing so with a JKS keystore will fail. // TODO Revisit this when SQL CLI client can handle key/certificate instead of only Keystores. // https://github.com/elastic/elasticsearch/issues/32306 - project.inFipsJvm == false + BuildParams.inFipsJvm == false } } diff --git a/x-pack/plugin/sql/sql-cli/build.gradle b/x-pack/plugin/sql/sql-cli/build.gradle index 4751240756b..0017848d7bb 100644 --- a/x-pack/plugin/sql/sql-cli/build.gradle +++ b/x-pack/plugin/sql/sql-cli/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + /* * This project is named sql-cli because it is in the "org.elasticsearch.plugin" * group and it'd be super confusing for it to just be called "cli" there. @@ -63,7 +65,7 @@ task runcli { description = 'Run the CLI and connect to elasticsearch running on 9200' dependsOn shadowJar doLast { - List command = [new File(project.runtimeJavaHome, 'bin/java').absolutePath] + List command = ["${BuildParams.runtimeJavaHome}/bin/java"] if ('true'.equals(System.getProperty('debug', 'false'))) { command += '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000' } diff --git a/x-pack/plugin/watcher/build.gradle b/x-pack/plugin/watcher/build.gradle index 33171bdbf5e..fc891b30e5a 100644 --- a/x-pack/plugin/watcher/build.gradle +++ b/x-pack/plugin/watcher/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + evaluationDependsOn(xpackModule('core')) apply plugin: 'elasticsearch.esplugin' @@ -73,7 +75,7 @@ forbiddenPatterns { // pulled in as external dependency to work on java 9 rootProject.globalInfo.ready { - if (project.runtimeJavaVersion <= JavaVersion.VERSION_1_8) { + if (BuildParams.runtimeJavaVersion <= JavaVersion.VERSION_1_8) { thirdPartyAudit.ignoreJarHellWithJDK( // pulled in as external dependency to work on java 9 'com.sun.activation.registries.LineTokenizer', diff --git a/x-pack/qa/full-cluster-restart/build.gradle b/x-pack/qa/full-cluster-restart/build.gradle index 4df2edce169..07c4f2f9363 100644 --- a/x-pack/qa/full-cluster-restart/build.gradle +++ b/x-pack/qa/full-cluster-restart/build.gradle @@ -1,4 +1,5 @@ import org.elasticsearch.gradle.Version +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.testclusters.RestTestRunnerTask @@ -65,7 +66,7 @@ for (Version bwcVersion : bwcVersions.indexCompatible) { versions = [bwcVersion.toString(), project.version] numberOfNodes = 2 setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}" - javaHome = project.file(project.ext.runtimeJavaHome) + javaHome = BuildParams.runtimeJavaHome user username: "test_user", password: "x-pack-test-password" setting 'path.repo', "${buildDir}/cluster/shared/repo/${baseName}" diff --git a/x-pack/qa/reindex-tests-with-security/build.gradle b/x-pack/qa/reindex-tests-with-security/build.gradle index 0a81e29088f..4a29494084e 100644 --- a/x-pack/qa/reindex-tests-with-security/build.gradle +++ b/x-pack/qa/reindex-tests-with-security/build.gradle @@ -1,3 +1,5 @@ +import org.elasticsearch.gradle.info.BuildParams + apply plugin: 'elasticsearch.testclusters' apply plugin: 'elasticsearch.standalone-rest-test' apply plugin: 'elasticsearch.rest-test' @@ -38,7 +40,7 @@ testClusters.integTest { // Workaround for JDK-8212885 rootProject.globalInfo.ready { - if (project.ext.runtimeJavaVersion.isJava12Compatible() == false) { + if (BuildParams.runtimeJavaVersion.isJava12Compatible() == false) { setting 'reindex.ssl.supported_protocols', 'TLSv1.2' } } diff --git a/x-pack/qa/rolling-upgrade-basic/build.gradle b/x-pack/qa/rolling-upgrade-basic/build.gradle index 4b376e74813..2bf41aeaa89 100644 --- a/x-pack/qa/rolling-upgrade-basic/build.gradle +++ b/x-pack/qa/rolling-upgrade-basic/build.gradle @@ -1,4 +1,5 @@ import org.elasticsearch.gradle.Version +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.testclusters.RestTestRunnerTask apply plugin: 'elasticsearch.testclusters' @@ -47,7 +48,7 @@ for (Version bwcVersion : bwcVersions.wireCompatible) { setting 'xpack.ml.enabled', 'false' setting 'xpack.watcher.enabled', 'false' setting 'xpack.license.self_generated.type', 'basic' - javaHome = project.file(project.ext.runtimeJavaHome) + javaHome = BuildParams.runtimeJavaHome } } diff --git a/x-pack/qa/rolling-upgrade-multi-cluster/build.gradle b/x-pack/qa/rolling-upgrade-multi-cluster/build.gradle index 4467cf5d0a5..c5ec5907bc4 100644 --- a/x-pack/qa/rolling-upgrade-multi-cluster/build.gradle +++ b/x-pack/qa/rolling-upgrade-multi-cluster/build.gradle @@ -1,4 +1,5 @@ import org.elasticsearch.gradle.Version +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.testclusters.RestTestRunnerTask apply plugin: 'elasticsearch.testclusters' @@ -53,7 +54,7 @@ for (Version bwcVersion : bwcVersions.wireCompatible) { setting 'xpack.watcher.enabled', 'false' setting 'xpack.license.self_generated.type', 'trial' - javaHome = project.file(project.ext.runtimeJavaHome) + javaHome = BuildParams.runtimeJavaHome } tasks.withType(RestTestRunnerTask).matching{it.name.startsWith(baseName)}.configureEach { diff --git a/x-pack/qa/rolling-upgrade/build.gradle b/x-pack/qa/rolling-upgrade/build.gradle index 469c3ca60d0..c55074075a9 100644 --- a/x-pack/qa/rolling-upgrade/build.gradle +++ b/x-pack/qa/rolling-upgrade/build.gradle @@ -1,4 +1,5 @@ import org.elasticsearch.gradle.Version +import org.elasticsearch.gradle.info.BuildParams import org.elasticsearch.gradle.testclusters.RestTestRunnerTask apply plugin: 'elasticsearch.testclusters' @@ -100,7 +101,7 @@ for (Version bwcVersion : bwcVersions.wireCompatible) { jvmArgs '-da:org.elasticsearch.xpack.monitoring.exporter.http.HttpExportBulk' } - javaHome = project.file(project.ext.runtimeJavaHome) + javaHome = BuildParams.runtimeJavaHome } } diff --git a/x-pack/snapshot-tool/build.gradle b/x-pack/snapshot-tool/build.gradle index c68cde1510e..54edaf847ee 100644 --- a/x-pack/snapshot-tool/build.gradle +++ b/x-pack/snapshot-tool/build.gradle @@ -3,6 +3,9 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ + +import org.elasticsearch.gradle.info.BuildParams + import java.nio.file.Files import java.nio.file.Paths import org.elasticsearch.gradle.ElasticsearchDistribution @@ -179,7 +182,7 @@ thirdPartyAudit.ignoreMissingClasses( ) rootProject.globalInfo.ready { - if (project.runtimeJavaVersion <= JavaVersion.VERSION_1_8) { + if (BuildParams.runtimeJavaVersion <= JavaVersion.VERSION_1_8) { thirdPartyAudit.ignoreJarHellWithJDK( 'javax.xml.bind.Binder', 'javax.xml.bind.ContextFinder$1',