Skip to content

Commit 4be45a2

Browse files
committed
Address PR comments
1 parent 4f0bc69 commit 4be45a2

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void execute(Task t) {
177177
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
178178
SourceSet mainSourceSet = sourceSets.findByName(SourceSet.MAIN_SOURCE_SET_NAME);
179179
SourceSet testSourceSet = sourceSets.findByName(SourceSet.TEST_SOURCE_SET_NAME);
180-
if (mainSourceSet != null && testSourceSet != null) {
180+
if ("test".equals(test.getName()) && mainSourceSet != null && testSourceSet != null) {
181181
FileCollection mainRuntime = mainSourceSet.getRuntimeClasspath();
182182
FileCollection testRuntime = testSourceSet.getRuntimeClasspath();
183183
FileCollection testOnlyFiles = testRuntime.minus(mainRuntime);
@@ -236,6 +236,11 @@ public void execute(Task t) {
236236
configureEntitlements(project);
237237
}
238238

239+
/**
240+
* Computes and sets the {@code --patch-module=java.base} JVM command line option.
241+
* <p>
242+
* Since each module can be patched only once, this method computes all patching required for {@code java.base}.
243+
*/
239244
private void configureJavaBasePatch(Project project) {
240245
String patchProject = ":test:immutable-collections-patch";
241246
if (project.findProject(patchProject) == null) {
@@ -255,13 +260,13 @@ private void configureJavaBasePatch(Project project) {
255260
test.getInputs().files(patchedFileCollection);
256261
test.systemProperty("tests.hackImmutableCollections", "true");
257262

258-
Configuration bridgeJarConfig = configurations.findByName("entitlementBridgeJar");
263+
Configuration bridgeConfig = configurations.findByName("entitlementBridge");
259264
String bridgeJarPart;
260-
if (bridgeJarConfig == null) {
265+
if (bridgeConfig == null) {
261266
bridgeJarPart = "";
262267
} else {
263-
test.getInputs().files(bridgeJarConfig);
264-
bridgeJarPart = File.pathSeparator + bridgeJarConfig.getSingleFile().getAbsolutePath();
268+
test.getInputs().files(bridgeConfig);
269+
bridgeJarPart = File.pathSeparator + bridgeConfig.getSingleFile().getAbsolutePath();
265270
}
266271

267272
test.getJvmArgumentProviders()
@@ -274,24 +279,30 @@ private void configureJavaBasePatch(Project project) {
274279
});
275280
}
276281

282+
/**
283+
* Sets the required JVM options and system properties to enable entitlement enforcement on tests.
284+
* <p>
285+
* One command line option is set in {@link #configureJavaBasePatch} out of necessity,
286+
* since the command line can have only one {@code --patch-module} option for a given module.
287+
*/
277288
private static void configureEntitlements(Project project) {
278-
Configuration agentJarConfig = project.getConfigurations().create("entitlementAgentJar");
289+
Configuration agentConfig = project.getConfigurations().create("entitlementAgent");
279290
Project agent = project.findProject(":libs:entitlement:agent");
280291
if (agent != null) {
281-
agentJarConfig.defaultDependencies(
292+
agentConfig.defaultDependencies(
282293
deps -> { deps.add(project.getDependencies().project(Map.of("path", ":libs:entitlement:agent"))); }
283294
);
284295
}
285-
FileCollection agentFiles = agentJarConfig;
296+
FileCollection agentFiles = agentConfig;
286297

287-
Configuration bridgeJarConfig = project.getConfigurations().create("entitlementBridgeJar");
298+
Configuration bridgeConfig = project.getConfigurations().create("entitlementBridge");
288299
Project bridge = project.findProject(":libs:entitlement:bridge");
289300
if (bridge != null) {
290-
bridgeJarConfig.defaultDependencies(
301+
bridgeConfig.defaultDependencies(
291302
deps -> { deps.add(project.getDependencies().project(Map.of("path", ":libs:entitlement:bridge"))); }
292303
);
293304
}
294-
FileCollection bridgeFiles = bridgeJarConfig;
305+
FileCollection bridgeFiles = bridgeConfig;
295306

296307
project.getTasks().withType(Test.class).configureEach(test -> {
297308
// See also SystemJvmOptions.maybeAttachEntitlementAgent.

0 commit comments

Comments
 (0)