diff --git a/core-feature-pack/common/src/main/resources/content/bin/standalone.sh b/core-feature-pack/common/src/main/resources/content/bin/standalone.sh index d3c0f5c1434..5c221712575 100644 --- a/core-feature-pack/common/src/main/resources/content/bin/standalone.sh +++ b/core-feature-pack/common/src/main/resources/content/bin/standalone.sh @@ -212,8 +212,9 @@ fi # clean server opts for var in $SERVER_OPTS do - if [ "${var//"-Djboss.server.base.dir"/}" != "${var}" ]; then - SERVER_OPTS="${SERVER_OPTS//$var/}" + v=`echo "${var}" | sed 's/-Djboss.server.base.dir//g'` + if [ "${v}" != "${var}" ]; then + SERVER_OPTS=`echo "${SERVER_OPTS}" | sed "s|${var}||g"` fi done diff --git a/testsuite/scripts/src/test/java/org/wildfly/scripts/test/ScriptProcess.java b/testsuite/scripts/src/test/java/org/wildfly/scripts/test/ScriptProcess.java index c566e21993a..06115ba5c5b 100644 --- a/testsuite/scripts/src/test/java/org/wildfly/scripts/test/ScriptProcess.java +++ b/testsuite/scripts/src/test/java/org/wildfly/scripts/test/ScriptProcess.java @@ -234,6 +234,12 @@ public boolean isAlive() { return delegate.isAlive(); } + @Override + public ProcessHandle toHandle() { + checkStatus(); + return delegate.toHandle(); + } + @Override public String toString() { return getCommandString(Collections.emptyList()); diff --git a/testsuite/scripts/src/test/java/org/wildfly/scripts/test/StandaloneScriptTestCase.java b/testsuite/scripts/src/test/java/org/wildfly/scripts/test/StandaloneScriptTestCase.java index f9ac170f9fd..cf021bd0cc1 100644 --- a/testsuite/scripts/src/test/java/org/wildfly/scripts/test/StandaloneScriptTestCase.java +++ b/testsuite/scripts/src/test/java/org/wildfly/scripts/test/StandaloneScriptTestCase.java @@ -8,12 +8,16 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.concurrent.Callable; import java.util.concurrent.TimeoutException; import java.util.function.Function; +import java.util.stream.Collectors; import jakarta.json.JsonObject; @@ -88,11 +92,47 @@ void testScript(final ScriptProcess script) throws InterruptedException, Timeout // seem to work when a directory has a space. An error indicating the trailing quote cannot be found. Removing // the `\ parts and just keeping quotes ends in the error shown in JDK-8215398. Assume.assumeFalse(TestSuiteEnvironment.isWindows() && env.containsKey("GC_LOG") && script.getScript().toString().contains(" ")); - script.start(STANDALONE_CHECK, env, ServerHelper.DEFAULT_SERVER_JAVA_OPTS); + + // Test WFCORE-5917 by adding the jboss.server.base.dir argument + // Due to WFCORE-6684, skip this verification if there are whitespaces in the home directory + if (!script.getContainerHome().toString().contains(" ")) { + List args = new ArrayList<>(Arrays.asList(ServerHelper.DEFAULT_SERVER_JAVA_OPTS)); + Path sbdPath = script.getContainerHome().resolve("standalone"); + args.add("-Djboss.server.base.dir=" + sbdPath); + script.start(STANDALONE_CHECK, env, args.toArray(String[]::new)); + } else { + script.start(STANDALONE_CHECK, env, ServerHelper.DEFAULT_SERVER_JAVA_OPTS); + } Assert.assertNotNull("The process is null and may have failed to start.", script); Assert.assertTrue("The process is not running and should be", script.isAlive()); + // test WFCORE-5917 + if (!script.getContainerHome().toString().contains(" ")) { + ProcessHandle handle = script.toHandle(); + List children = handle.children().collect(Collectors.toList()); + Assert.assertEquals("The standalone process should have started one single process.", 1, children.size()); + ProcessHandle serverProcess = children.get(0); + Optional commandLine = serverProcess.info().commandLine(); + Assert.assertFalse("Server process launch command is not available", commandLine.isEmpty()); + String[] serverArgs = commandLine.get().split("\\s+"); + int occurrences = 0; + outer: + for (int i = 0; i < serverArgs.length; i++) { + if ( !serverArgs[i].contains("-Djboss.server.base.dir=") ) { + continue; + } + occurrences++; + for (int j = i+1; j lines = ServerHelper.readLogFileFromModel("json.log"); Assert.assertEquals("Expected 2 lines found " + lines.size(), 2, lines.size());