Skip to content

Commit b1810b6

Browse files
breskebysalvatore-campagna
authored andcommitted
[Gradle] Remove static use of BuildParams (elastic#115122)
Static fields dont do well in Gradle with configuration cache enabled. - Use buildParams extension in build scripts - Keep BuildParams.ci for now for easy serverless migration - Tweak testing doc
1 parent 806480b commit b1810b6

File tree

185 files changed

+965
-615
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

185 files changed

+965
-615
lines changed

TESTING.asciidoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ You can run a group of YAML test by using wildcards:
472472
--tests "org.elasticsearch.test.rest.ClientYamlTestSuiteIT.test {yaml=index/*/*}"
473473
---------------------------------------------------------------------------
474474

475-
or
475+
or
476476

477477
---------------------------------------------------------------------------
478478
./gradlew :rest-api-spec:yamlRestTest \
@@ -564,8 +564,8 @@ Sometimes a backward compatibility change spans two versions.
564564
A common case is a new functionality that needs a BWC bridge in an unreleased versioned of a release branch (for example, 5.x).
565565
Another use case, since the introduction of serverless, is to test BWC against main in addition to the other released branches.
566566
To do so, specify the `bwc.refspec` remote and branch to use for the BWC build as `origin/main`.
567-
To test against main, you will also need to create a new version in link:./server/src/main/java/org/elasticsearch/Version.java[Version.java],
568-
increment `elasticsearch` in link:./build-tools-internal/version.properties[version.properties], and hard-code the `project.version` for ml-cpp
567+
To test against main, you will also need to create a new version in link:./server/src/main/java/org/elasticsearch/Version.java[Version.java],
568+
increment `elasticsearch` in link:./build-tools-internal/version.properties[version.properties], and hard-code the `project.version` for ml-cpp
569569
in link:./x-pack/plugin/ml/build.gradle[ml/build.gradle].
570570

571571
In general, to test the changes, you can instruct Gradle to build the BWC version from another remote/branch combination instead of pulling the release branch from GitHub.
@@ -625,7 +625,7 @@ For specific YAML rest tests one can use
625625
For disabling entire types of tests for subprojects, one can use for example:
626626

627627
------------------------------------------------
628-
if (BuildParams.inFipsJvm){
628+
if (buildParams.inFipsJvm) {
629629
// This test cluster is using a BASIC license and FIPS 140 mode is not supported in BASIC
630630
tasks.named("javaRestTest").configure{enabled = false }
631631
}

benchmarks/build.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import org.elasticsearch.gradle.internal.info.BuildParams
21
import org.elasticsearch.gradle.internal.test.TestUtil
32

43
/*
@@ -78,7 +77,7 @@ tasks.register("copyPainless", Copy) {
7877
}
7978

8079
tasks.named("run").configure {
81-
executable = "${BuildParams.runtimeJavaHome}/bin/java"
80+
executable = "${buildParams.runtimeJavaHome.get()}/bin/java"
8281
args << "-Dplugins.dir=${buildDir}/plugins" << "-Dtests.index=${buildDir}/index"
8382
dependsOn "copyExpression", "copyPainless", configurations.nativeLib
8483
systemProperty 'es.nativelibs.path', TestUtil.getTestLibraryPath(file("../libs/native/libraries/build/platform/").toString())

build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/GUtils.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ public abstract class GUtils {
1616
public static String capitalize(String s) {
1717
return s.substring(0, 1).toUpperCase(Locale.ROOT) + s.substring(1);
1818
}
19+
20+
public static <T> T elvis(T given, T fallback) {
21+
if (given == null) {
22+
return fallback;
23+
} else {
24+
return given;
25+
}
26+
}
1927
}

build-tools-internal/build.gradle

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,13 @@ tasks.named("jar") {
386386

387387
spotless {
388388
java {
389-
// IDEs can sometimes run annotation processors that leave files in
390-
// here, causing Spotless to complain. Even though this path ought not
391-
// to exist, exclude it anyway in order to avoid spurious failures.
392-
toggleOffOn()
389+
390+
// workaround for https://github.com/diffplug/spotless/issues/2317
391+
//toggleOffOn()
392+
target project.fileTree("src/main/java") {
393+
include '**/*.java'
394+
exclude '**/DockerBase.java'
395+
}
393396
}
394397
}
395398

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/InternalDistributionBwcSetupPluginFuncTest.groovy

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,10 @@
99

1010
package org.elasticsearch.gradle.internal
1111

12-
import org.elasticsearch.gradle.Architecture
1312
import org.elasticsearch.gradle.fixtures.AbstractGitAwareGradleFuncTest
1413
import org.gradle.testkit.runner.TaskOutcome
15-
import spock.lang.IgnoreIf
1614
import spock.lang.Unroll
1715

18-
/*
19-
* Test is ignored on ARM since this test case tests the ability to build certain older BWC branches that we don't support on ARM
20-
*/
21-
@IgnoreIf({ Architecture.current() == Architecture.AARCH64 })
2216
class InternalDistributionBwcSetupPluginFuncTest extends AbstractGitAwareGradleFuncTest {
2317

2418
def setup() {

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/PublishPluginFuncTest.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,7 @@ class PublishPluginFuncTest extends AbstractGradleFuncTest {
440440
// scm info only added for internal builds
441441
internalBuild()
442442
buildFile << """
443-
BuildParams.init { it.setGitOrigin("https://some-repo.com/repo.git") }
444-
443+
buildParams.getGitOriginProperty().set("https://some-repo.com/repo.git")
445444
apply plugin:'elasticsearch.java'
446445
apply plugin:'elasticsearch.publish'
447446

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/snyk/SnykDependencyMonitoringGradlePluginFuncTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class SnykDependencyMonitoringGradlePluginFuncTest extends AbstractGradleInterna
161161
},
162162
"target": {
163163
"remoteUrl": "http://acme.org",
164-
"branch": "unknown"
164+
"branch": "$version"
165165
},
166166
"targetReference": "$version",
167167
"projectAttributes": {

build-tools-internal/src/integTest/groovy/org/elasticsearch/gradle/internal/test/rest/LegacyYamlRestTestPluginFuncTest.groovy

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.gradle.internal.test.rest
1111

1212
import spock.lang.IgnoreIf
13+
import spock.lang.IgnoreRest
1314

1415
import org.elasticsearch.gradle.VersionProperties
1516
import org.elasticsearch.gradle.fixtures.AbstractRestResourcesFuncTest
@@ -20,16 +21,16 @@ import org.gradle.testkit.runner.TaskOutcome
2021
class LegacyYamlRestTestPluginFuncTest extends AbstractRestResourcesFuncTest {
2122

2223
def setup() {
24+
configurationCacheCompatible = true
2325
buildApiRestrictionsDisabled = true
2426
}
2527

2628

2729
def "yamlRestTest does nothing when there are no tests"() {
2830
given:
31+
internalBuild()
2932
buildFile << """
30-
plugins {
31-
id 'elasticsearch.legacy-yaml-rest-test'
32-
}
33+
apply plugin: 'elasticsearch.legacy-yaml-rest-test'
3334
"""
3435

3536
when:
@@ -136,7 +137,7 @@ class LegacyYamlRestTestPluginFuncTest extends AbstractRestResourcesFuncTest {
136137
"""
137138

138139
when:
139-
def result = gradleRunner("yamlRestTest", "--console", 'plain', '--stacktrace').buildAndFail()
140+
def result = gradleRunner("yamlRestTest", "--console", 'plain').buildAndFail()
140141

141142
then:
142143
result.task(":distribution:archives:integ-test-zip:buildExpanded").outcome == TaskOutcome.SUCCESS

build-tools-internal/src/main/groovy/elasticsearch.build-scan.gradle

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import java.time.LocalDateTime;
1212

1313
import org.elasticsearch.gradle.Architecture
1414
import org.elasticsearch.gradle.OS
15-
import org.elasticsearch.gradle.internal.info.BuildParams
1615

1716
import java.lang.management.ManagementFactory
1817
import java.time.LocalDateTime
@@ -34,12 +33,15 @@ develocity {
3433
publishing.onlyIf { false }
3534
}
3635

36+
def fips = buildParams.inFipsJvm
37+
def gitRevision = buildParams.gitRevision
38+
3739
background {
3840
tag OS.current().name()
3941
tag Architecture.current().name()
4042

4143
// Tag if this build is run in FIPS mode
42-
if (BuildParams.inFipsJvm) {
44+
if (fips) {
4345
tag 'FIPS'
4446
}
4547

@@ -92,8 +94,8 @@ develocity {
9294
link 'Source', "${prBaseUrl}/tree/${System.getenv('BUILDKITE_COMMIT')}"
9395
link 'Pull Request', "https://github.com/${repository}/pull/${prId}"
9496
} else {
95-
value 'Git Commit ID', BuildParams.gitRevision
96-
link 'Source', "https://github.com/${repository}/tree/${BuildParams.gitRevision}"
97+
value 'Git Commit ID', gitRevision
98+
link 'Source', "https://github.com/${repository}/tree/${gitRevision}"
9799
}
98100

99101
buildFinished { result ->

build-tools-internal/src/main/groovy/elasticsearch.bwc-test.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import org.elasticsearch.gradle.Version
1111
import org.elasticsearch.gradle.internal.ElasticsearchTestBasePlugin
12-
import org.elasticsearch.gradle.internal.info.BuildParams
1312
import org.elasticsearch.gradle.internal.test.rest.InternalJavaRestTestPlugin
1413
import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
1514

@@ -19,7 +18,7 @@ ext.bwcTaskName = { Version version ->
1918

2019
def bwcTestSnapshots = tasks.register("bwcTestSnapshots") {
2120
if (project.bwc_tests_enabled) {
22-
dependsOn tasks.matching { task -> BuildParams.bwcVersions.unreleased.any { version -> bwcTaskName(version) == task.name } }
21+
dependsOn tasks.matching { task -> buildParams.bwcVersions.unreleased.any { version -> bwcTaskName(version) == task.name } }
2322
}
2423
}
2524

0 commit comments

Comments
 (0)