Skip to content

Commit 54952f6

Browse files
authored
Avoid eagerly resolving entitlement agent during test task configuration (#133678) (#133686)
1 parent f070e7e commit 54952f6

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -330,24 +330,22 @@ private static void configureEntitlements(Project project) {
330330
.matching(test -> TEST_TASKS_WITH_ENTITLEMENTS.contains(test.getName()))
331331
.configureEach(test -> {
332332
// See also SystemJvmOptions.maybeAttachEntitlementAgent.
333+
SystemPropertyCommandLineArgumentProvider nonInputSystemProperties = test.getExtensions()
334+
.getByType(SystemPropertyCommandLineArgumentProvider.class);
333335

334336
// Agent
335-
if (agentFiles.isEmpty() == false) {
336-
test.getInputs().files(agentFiles);
337-
test.systemProperty("es.entitlement.agentJar", agentFiles.getAsPath());
338-
test.systemProperty("jdk.attach.allowAttachSelf", true);
339-
}
337+
test.getInputs().files(agentFiles).optional(true);
338+
nonInputSystemProperties.systemProperty("es.entitlement.agentJar", agentFiles::getAsPath);
339+
nonInputSystemProperties.systemProperty("jdk.attach.allowAttachSelf", () -> agentFiles.isEmpty() ? "false" : "true");
340340

341341
// Bridge
342-
if (bridgeFiles.isEmpty() == false) {
343-
String modulesContainingEntitlementInstrumentation = "java.logging,java.net.http,java.naming,jdk.net";
344-
test.getInputs().files(bridgeFiles);
345-
// Tests may not be modular, but the JDK still is
346-
test.jvmArgs(
347-
"--add-exports=java.base/org.elasticsearch.entitlement.bridge=ALL-UNNAMED,"
348-
+ modulesContainingEntitlementInstrumentation
349-
);
350-
}
342+
String modulesContainingEntitlementInstrumentation = "java.logging,java.net.http,java.naming,jdk.net";
343+
test.getInputs().files(bridgeFiles).optional(true);
344+
// Tests may not be modular, but the JDK still is
345+
test.jvmArgs(
346+
"--add-exports=java.base/org.elasticsearch.entitlement.bridge=ALL-UNNAMED,"
347+
+ modulesContainingEntitlementInstrumentation
348+
);
351349
});
352350
}
353351

0 commit comments

Comments
 (0)