Skip to content

Commit 58f5e2b

Browse files
committed
[Gradle] Remove static use of BuildParams
Static fields dont do well in Gradle with configuration cache enabled.
1 parent 39949c1 commit 58f5e2b

File tree

56 files changed

+122
-70
lines changed

Some content is hidden

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

56 files changed

+122
-70
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
}

build-conventions/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ plugins {
2323
id 'java-gradle-plugin'
2424
id 'java-test-fixtures'
2525
id 'eclipse'
26+
id 'org.gradlex.build-parameters' version '1.4.4'
2627
}
2728

2829
group = "org.elasticsearch"
@@ -111,3 +112,10 @@ project.getPlugins().withType(JavaBasePlugin.class) {
111112
tasks.withType(JavaCompile).configureEach {
112113
options.incremental = System.getenv("JENKINS_URL") == null && System.getenv("BUILDKITE_BUILD_URL") == null && System.getProperty("isCI") == null
113114
}
115+
116+
buildParameters {
117+
bool('inFipsJvm') {
118+
description = 'running tests in FIPS mode'
119+
defaultValue = false
120+
}
121+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ develocity {
3939
tag Architecture.current().name()
4040

4141
// Tag if this build is run in FIPS mode
42-
if (BuildParams.inFipsJvm) {
42+
if (buildParams.inFipsJvm) {
4343
tag 'FIPS'
4444
}
4545

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import org.elasticsearch.gradle.testclusters.StandaloneRestIntegTestTask
1515
import org.elasticsearch.gradle.testclusters.TestClustersAware
1616
import org.elasticsearch.gradle.testclusters.TestDistribution
1717

18-
// Common config when running with a FIPS-140 runtime JVM
19-
if (BuildParams.inFipsJvm) {
18+
//apply plugin: org.elasticsearch.gradle.internal.info.GlobalBuildInfoPlugin
2019

20+
// Common config when running with a FIPS-140 runtime JVM
21+
if (buildParams.inFipsJvm) {
2122
allprojects {
2223
String javaSecurityFilename = BuildParams.runtimeJavaDetails.toLowerCase().contains('oracle') ? 'fips_java_oracle.security' : 'fips_java.security'
2324
File fipsResourcesDir = new File(project.buildDir, 'fips-resources')
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.gradle.internal.info;
11+
12+
import org.gradle.api.Task;
13+
import org.gradle.api.provider.Provider;
14+
import org.gradle.api.provider.ProviderFactory;
15+
16+
public class BuildParameterExtension {
17+
18+
private final Provider<Boolean> inFipsJvm;
19+
20+
public BuildParameterExtension(ProviderFactory providers) {
21+
this.inFipsJvm = providers.systemProperty("tests.fips.enabled").map(BuildParameterExtension::parseBoolean);
22+
}
23+
24+
private static boolean parseBoolean(String s) {
25+
if (s == null) {
26+
return false;
27+
}
28+
return Boolean.parseBoolean(s);
29+
}
30+
31+
public boolean getInFipsJvm() {
32+
return inFipsJvm.getOrElse(false);
33+
}
34+
35+
public void withFipsEnabledOnly(Task task) {
36+
task.onlyIf("FIPS mode disabled", task1 -> getInFipsJvm() == false);
37+
}
38+
}

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/BuildParams.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import org.elasticsearch.gradle.internal.BwcVersions;
1212
import org.gradle.api.Action;
1313
import org.gradle.api.JavaVersion;
14-
import org.gradle.api.Task;
1514
import org.gradle.api.provider.Provider;
1615
import org.gradle.jvm.toolchain.JavaToolchainSpec;
1716

@@ -90,13 +89,13 @@ public static String getRuntimeJavaDetails() {
9089
return value(runtimeJavaDetails.get());
9190
}
9291

93-
public static Boolean isInFipsJvm() {
94-
return value(inFipsJvm);
95-
}
92+
// public static Boolean isInFipsJvm() {
93+
// return value(inFipsJvm);
94+
// }
9695

97-
public static void withFipsEnabledOnly(Task task) {
98-
task.onlyIf("FIPS mode disabled", task1 -> isInFipsJvm() == false);
99-
}
96+
// public static void withFipsEnabledOnly(Task task) {
97+
// task.onlyIf("FIPS mode disabled", task1 -> isInFipsJvm() == false);
98+
// }
10099

101100
public static String getGitRevision() {
102101
return value(gitRevision);

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/info/GlobalBuildInfoPlugin.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public void apply(Project project) {
8787
if (project != project.getRootProject()) {
8888
throw new IllegalStateException(this.getClass().getName() + " can only be applied to the root project.");
8989
}
90+
BuildParameterExtension buildParams = project.getExtensions().create("buildParams", BuildParameterExtension.class);
9091
project.getPlugins().apply(JvmToolchainsPlugin.class);
9192
toolChainService = project.getExtensions().getByType(JavaToolchainService.class);
9293
GradleVersion minimumGradleVersion = GradleVersion.version(getResourceContents("/minimumGradleVersion"));
@@ -137,7 +138,6 @@ public void apply(Project project) {
137138
System.getenv("JENKINS_URL") != null || System.getenv("BUILDKITE_BUILD_URL") != null || System.getProperty("isCI") != null
138139
);
139140
params.setDefaultParallel(ParallelDetector.findDefaultParallel(project));
140-
params.setInFipsJvm(Util.getBooleanProperty("tests.fips.enabled", false));
141141
params.setIsSnapshotBuild(Util.getBooleanProperty("build.snapshot", true));
142142
AtomicReference<BwcVersions> cache = new AtomicReference<>();
143143
params.setBwcVersions(
@@ -155,7 +155,7 @@ public void apply(Project project) {
155155
// Print global build info header just before task execution
156156
// Only do this if we are the root build of a composite
157157
if (GradleUtils.isIncludedBuild(project) == false) {
158-
project.getGradle().getTaskGraph().whenReady(graph -> logGlobalBuildInfo());
158+
project.getGradle().getTaskGraph().whenReady(graph -> logGlobalBuildInfo(buildParams));
159159
}
160160
}
161161

@@ -190,7 +190,7 @@ private static BwcVersions resolveBwcVersions(File root) {
190190
}
191191
}
192192

193-
private void logGlobalBuildInfo() {
193+
private void logGlobalBuildInfo(BuildParameterExtension buildParams) {
194194
final String osName = System.getProperty("os.name");
195195
final String osVersion = System.getProperty("os.version");
196196
final String osArch = System.getProperty("os.arch");
@@ -221,7 +221,7 @@ private void logGlobalBuildInfo() {
221221
LOGGER.quiet(" JAVA_TOOLCHAIN_HOME : " + javaToolchainHome);
222222
}
223223
LOGGER.quiet(" Random Testing Seed : " + BuildParams.getTestSeed());
224-
LOGGER.quiet(" In FIPS 140 mode : " + BuildParams.isInFipsJvm());
224+
LOGGER.quiet(" In FIPS 140 mode : " + buildParams.getInFipsJvm());
225225
LOGGER.quiet("=======================================");
226226
}
227227

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/TestWithSslPlugin.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import org.elasticsearch.gradle.internal.ExportElasticsearchBuildResourcesTask;
1313
import org.elasticsearch.gradle.internal.conventions.util.Util;
14-
import org.elasticsearch.gradle.internal.info.BuildParams;
14+
import org.elasticsearch.gradle.internal.info.BuildParameterExtension;
1515
import org.elasticsearch.gradle.internal.precommit.FilePermissionsPrecommitPlugin;
1616
import org.elasticsearch.gradle.internal.precommit.ForbiddenPatternsPrecommitPlugin;
1717
import org.elasticsearch.gradle.internal.precommit.ForbiddenPatternsTask;
@@ -35,6 +35,7 @@ public class TestWithSslPlugin implements Plugin<Project> {
3535
@Override
3636
public void apply(Project project) {
3737
File keyStoreDir = new File(project.getBuildDir(), "keystore");
38+
BuildParameterExtension buildParams = project.getRootProject().getExtensions().getByType(BuildParameterExtension.class);
3839
TaskProvider<ExportElasticsearchBuildResourcesTask> exportKeyStore = project.getTasks()
3940
.register("copyTestCertificates", ExportElasticsearchBuildResourcesTask.class, (t) -> {
4041
t.copy("test/ssl/test-client.crt");
@@ -87,7 +88,7 @@ public void apply(Project project) {
8788
.getExtensions()
8889
.getByName(TestClustersPlugin.EXTENSION_NAME);
8990
clusters.configureEach(c -> {
90-
if (BuildParams.isInFipsJvm()) {
91+
if (buildParams.getInFipsJvm()) {
9192
c.setting("xpack.security.transport.ssl.key", "test-node.key");
9293
c.keystore("xpack.security.transport.ssl.secure_key_passphrase", "test-node-key-password");
9394
c.setting("xpack.security.transport.ssl.certificate", "test-node.crt");

docs/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ext.docsFileTree = fileTree(projectDir) {
2929
// These files simply don't pass yet. We should figure out how to fix them.
3030
exclude 'reference/watcher/reference/actions.asciidoc'
3131
exclude 'reference/rest-api/security/ssl.asciidoc'
32-
if (BuildParams.inFipsJvm) {
32+
if (buildParams.inFipsJvm) {
3333
// We don't support this component in FIPS 140
3434
exclude 'reference/ingest/processors/attachment.asciidoc'
3535
// We can't conditionally control output, this would be missing the ingest-attachment component
@@ -170,7 +170,7 @@ testClusters.matching { it.name == "yamlRestTest"}.configureEach {
170170
return
171171
}
172172
// Do not install ingest-attachment in a FIPS 140 JVM as this is not supported
173-
if (subproj.path.startsWith(':modules:ingest-attachment') && BuildParams.inFipsJvm) {
173+
if (subproj.path.startsWith(':modules:ingest-attachment') && buildParams.inFipsJvm) {
174174
return
175175
}
176176
plugin subproj.path

gradle/verification-metadata.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3632,6 +3632,11 @@
36323632
<sha256 value="17fdeb7e22375a7fb40bb0551306f6dcf2b5743078668adcdf6c642c9a9ec955" origin="Generated by Gradle"/>
36333633
</artifact>
36343634
</component>
3635+
<component group="org.gradlex" name="build-parameters" version="1.4.4">
3636+
<artifact name="build-parameters-1.4.4.jar">
3637+
<sha256 value="54045988848801e84cffd604cfd94f6e2a613248d81ca315c20e74d0ac3b602c" origin="Generated by Gradle"/>
3638+
</artifact>
3639+
</component>
36353640
<component group="org.hamcrest" name="hamcrest" version="2.1">
36363641
<artifact name="hamcrest-2.1.jar">
36373642
<sha256 value="ba93b2e3a562322ba432f0a1b53addcc55cb188253319a020ed77f824e692050" origin="Generated by Gradle"/>

0 commit comments

Comments
 (0)