@@ -329,24 +329,22 @@ private static void configureEntitlements(Project project) {
329329 .matching (test -> TEST_TASKS_WITH_ENTITLEMENTS .contains (test .getName ()))
330330 .configureEach (test -> {
331331 // See also SystemJvmOptions.maybeAttachEntitlementAgent.
332+ SystemPropertyCommandLineArgumentProvider nonInputSystemProperties = test .getExtensions ()
333+ .getByType (SystemPropertyCommandLineArgumentProvider .class );
332334
333335 // Agent
334- if (agentFiles .isEmpty () == false ) {
335- test .getInputs ().files (agentFiles );
336- test .systemProperty ("es.entitlement.agentJar" , agentFiles .getAsPath ());
337- test .systemProperty ("jdk.attach.allowAttachSelf" , true );
338- }
336+ test .getInputs ().files (agentFiles ).optional (true );
337+ nonInputSystemProperties .systemProperty ("es.entitlement.agentJar" , agentFiles ::getAsPath );
338+ nonInputSystemProperties .systemProperty ("jdk.attach.allowAttachSelf" , () -> agentFiles .isEmpty () ? "false" : "true" );
339339
340340 // Bridge
341- if (bridgeFiles .isEmpty () == false ) {
342- String modulesContainingEntitlementInstrumentation = "java.logging,java.net.http,java.naming,jdk.net" ;
343- test .getInputs ().files (bridgeFiles );
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- );
349- }
341+ String modulesContainingEntitlementInstrumentation = "java.logging,java.net.http,java.naming,jdk.net" ;
342+ test .getInputs ().files (bridgeFiles ).optional (true );
343+ // Tests may not be modular, but the JDK still is
344+ test .jvmArgs (
345+ "--add-exports=java.base/org.elasticsearch.entitlement.bridge=ALL-UNNAMED,"
346+ + modulesContainingEntitlementInstrumentation
347+ );
350348 });
351349 }
352350
0 commit comments