@@ -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