From bd00d51a0b225304ae48a2484274cd0bea4a0b77 Mon Sep 17 00:00:00 2001 From: "James R. Perkins" Date: Wed, 20 Nov 2024 14:41:01 -0800 Subject: [PATCH] Allow the CommandBuilderTest to pass on Java 24+. Signed-off-by: James R. Perkins --- .../core/launcher/CommandBuilderTest.java | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/wildfly/core/launcher/CommandBuilderTest.java b/src/test/java/org/wildfly/core/launcher/CommandBuilderTest.java index 6f13284..74df191 100644 --- a/src/test/java/org/wildfly/core/launcher/CommandBuilderTest.java +++ b/src/test/java/org/wildfly/core/launcher/CommandBuilderTest.java @@ -7,6 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.file.Path; @@ -33,18 +34,25 @@ class CommandBuilderTest { @Test void jBossModulesBuilder() { + final int featureVersion = Runtime.version().feature(); // Set up a standalone command builder final JBossModulesCommandBuilder commandBuilder = JBossModulesCommandBuilder.of(WILDFLY_HOME, "org.jboss.as.launcher.test") - .addJavaOption("-Djava.security.manager") .addJavaOption("-Djava.net.preferIPv4Stack=true") .addJavaOption("-Djava.net.preferIPv4Stack=false") .addModuleOption("-javaagent:test-agent1.jar") .addServerArgument("--server=test"); + if (featureVersion < 24) { + commandBuilder.addJavaOption("-Djava.security.manager"); + } else { + assertThrows(IllegalArgumentException.class, () -> commandBuilder.addJavaOption("-Djava.security.manager")); + assertThrows(IllegalArgumentException.class, () -> commandBuilder.setUseSecurityManager(true)); + } + // Get all the commands List commands = commandBuilder.buildArguments(); - assertTrue(commands.contains("-secmgr"), "Missing -secmgr option"); + assertEquals(featureVersion < 24, commands.contains("-secmgr"), "Missing -secmgr option"); assertTrue(commands.stream().anyMatch(entry -> entry.matches("-javaagent:.*jboss-modules.jar$")), "Missing jboss-modules.jar"); assertTrue(commands.contains("-javaagent:test-agent1.jar"), "Missing test-agent1.jar"); @@ -68,18 +76,25 @@ void jBossModulesBuilder() { @Test void standaloneBuilder() { + final int featureVersion = Runtime.version().feature(); // Set up a standalone command builder final StandaloneCommandBuilder commandBuilder = StandaloneCommandBuilder.of(WILDFLY_HOME) .setAdminOnly() .setBindAddressHint("0.0.0.0") .setDebug(true, 5005) .setServerConfiguration("standalone-full.xml") - .addJavaOption("-Djava.security.manager") .addJavaOption("-Djava.net.preferIPv4Stack=true") .addJavaOption("-Djava.net.preferIPv4Stack=false") .addModuleOption("-javaagent:test-agent1.jar") .setBindAddressHint("management", "0.0.0.0"); + if (featureVersion < 24) { + commandBuilder.addJavaOption("-Djava.security.manager"); + } else { + assertThrows(IllegalArgumentException.class, () -> commandBuilder.addJavaOption("-Djava.security.manager")); + assertThrows(IllegalArgumentException.class, () -> commandBuilder.setUseSecurityManager(true)); + } + // Get all the commands List commands = commandBuilder.buildArguments(); @@ -93,7 +108,7 @@ void standaloneBuilder() { assertTrue(commands.contains("-c=standalone-full.xml"), "Missing server configuration file override"); - assertTrue(commands.contains("-secmgr"), "Missing -secmgr option"); + assertEquals(featureVersion < 24, commands.contains("-secmgr"), "Missing -secmgr option"); assertTrue(commands.stream().anyMatch(entry -> entry.matches("-javaagent:.*jboss-modules.jar$")), "Missing jboss-modules.jar"); assertTrue(commands.contains("-javaagent:test-agent1.jar"), "Missing test-agent1.jar"); @@ -186,6 +201,7 @@ void bootableJarBuilder() { @Test void domainBuilder() { + final int featureVersion = Runtime.version().feature(); // Set up a standalone command builder final DomainCommandBuilder commandBuilder = DomainCommandBuilder.of(WILDFLY_HOME) .setAdminOnly() @@ -193,9 +209,15 @@ void domainBuilder() { .setMasterAddressHint("0.0.0.0") .setDomainConfiguration("domain.xml") .setHostConfiguration("host.xml") - .addProcessControllerJavaOption("-Djava.security.manager") .setBindAddressHint("management", "0.0.0.0"); + if (featureVersion < 24) { + commandBuilder.addJavaOption("-Djava.security.manager"); + } else { + assertThrows(IllegalArgumentException.class, () -> commandBuilder.addJavaOption("-Djava.security.manager")); + assertThrows(IllegalArgumentException.class, () -> commandBuilder.setUseSecurityManager(true)); + } + // Get all the commands List commands = commandBuilder.buildArguments(); @@ -209,7 +231,7 @@ void domainBuilder() { assertTrue(commands.contains("-c=domain.xml"), "Missing server configuration file override"); - assertTrue(commands.contains("-secmgr"), "Missing -secmgr option"); + assertEquals(featureVersion < 24, commands.contains("-secmgr"), "Missing -secmgr option"); // If we're using Java 9+ ensure the modular JDK options were added testModularJvmArguments(commands, 2); @@ -280,7 +302,7 @@ void arguments() { } private void testEnhancedSecurityManager(final Collection command, final int expectedCount) { - // If we're using Java 12+ ensure enhanced security manager option was added + // If we're using Java 12+, but less than 24 ensure enhanced security manager option was added if (Jvm.current().enhancedSecurityManagerAvailable()) { assertArgumentExists(command, "-Djava.security.manager=allow", expectedCount); } else {