From fb98acf09f3942fa380e2234b54c9441e82452fb Mon Sep 17 00:00:00 2001 From: Brian Stansberry Date: Tue, 10 Oct 2023 13:45:14 -0500 Subject: [PATCH] [WFCORE-6552] Add missing search for WARNING to Windows package availability check --- .../src/main/resources/content/bin/common.bat | 4 +++- .../src/main/resources/content/bin/common.ps1 | 8 +++++--- .../src/main/resources/content/bin/common.sh | 2 ++ .../scripts/test/CliScriptTestCase.java | 18 ++++++++++++++---- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/core-feature-pack/common/src/main/resources/content/bin/common.bat b/core-feature-pack/common/src/main/resources/content/bin/common.bat index f2f81831773..8196fb5321d 100644 --- a/core-feature-pack/common/src/main/resources/content/bin/common.bat +++ b/core-feature-pack/common/src/main/resources/content/bin/common.bat @@ -16,7 +16,9 @@ if exist "%COMMON_CONF%" ( goto :eof :setPackageAvailable - "%JAVA%" --add-opens=%~1=ALL-UNNAMED -version >nul 2>&1 && (set PACKAGE_AVAILABLE=true) || (set PACKAGE_AVAILABLE=false) + rem java -version actually writes what we all read in our terminals to stderr, not stdout! + rem So we redirect it to stdout with 2>&1 before piping to findstr + "%JAVA%" --add-opens=%~1=ALL-UNNAMED -version 2>&1 | findstr /i /c:"WARNING" >nul 2>&1 && (set PACKAGE_AVAILABLE=false) || (set PACKAGE_AVAILABLE=true) goto :eof :setEnhancedSecurityManager diff --git a/core-feature-pack/common/src/main/resources/content/bin/common.ps1 b/core-feature-pack/common/src/main/resources/content/bin/common.ps1 index f27763e3483..3d75a8dd293 100644 --- a/core-feature-pack/common/src/main/resources/content/bin/common.ps1 +++ b/core-feature-pack/common/src/main/resources/content/bin/common.ps1 @@ -112,10 +112,12 @@ Function Get-Java-Opts { } Function SetPackageAvailable($packageName) { - $PACKAGE_AVAILABLE = $false - & $JAVA "--add-opens=$packageName=ALL-UNNAMED" -version >$null 2>&1 + $PACKAGE_AVAILABLE = $true + # java -version actually writes what we all read in our terminals to stderr, not stdout! + # So we redirect it to stdout with 2>&1 before piping to Out-String and Select-String + & $JAVA "--add-opens=$packageName=ALL-UNNAMED" -version 2>&1 | Out-String -Stream | Select-String 'WARNING' -SimpleMatch -Quiet >$null 2>&1 if ($LastExitCode -eq 0){ - $PACKAGE_AVAILABLE = $true + $PACKAGE_AVAILABLE = $false } return $PACKAGE_AVAILABLE } diff --git a/core-feature-pack/common/src/main/resources/content/bin/common.sh b/core-feature-pack/common/src/main/resources/content/bin/common.sh index cda8b8c5148..36dd36c1a4f 100755 --- a/core-feature-pack/common/src/main/resources/content/bin/common.sh +++ b/core-feature-pack/common/src/main/resources/content/bin/common.sh @@ -13,6 +13,8 @@ if [ -r "$COMMON_CONF" ]; then fi setPackageAvailable() { + # java -version actually writes what we all read in our terminals to stderr, not stdout! + # So we redirect it to stdout with 2>&1 before piping to grep PACKAGE_STRING=`"$JAVA" --add-opens=$1=ALL-UNNAMED -version 2>&1 | $GREP "WARNING"` if [ "x$PACKAGE_STRING" = "x" ]; then PACKAGE_AVAILABLE=true diff --git a/testsuite/scripts/src/test/java/org/wildfly/scripts/test/CliScriptTestCase.java b/testsuite/scripts/src/test/java/org/wildfly/scripts/test/CliScriptTestCase.java index 1e36c3bb7c4..3b9af9ab727 100644 --- a/testsuite/scripts/src/test/java/org/wildfly/scripts/test/CliScriptTestCase.java +++ b/testsuite/scripts/src/test/java/org/wildfly/scripts/test/CliScriptTestCase.java @@ -39,6 +39,14 @@ void testScript(final ScriptProcess script) throws InterruptedException, Timeout validateProcess(script); + final ModelNode result = outputToModelNode(script); + if (!Operations.isSuccessfulOutcome(result)) { + Assert.fail(result.asString()); + } + Assert.assertEquals(ClientConstants.CONTROLLER_PROCESS_STATE_RUNNING, Operations.readResult(result).asString()); + } + + private static ModelNode outputToModelNode(final ScriptProcess script) throws IOException { StringBuilder builder = new StringBuilder(); // Read the output lines which should be valid DMR for (String line : script.getStdout()) { @@ -48,10 +56,12 @@ void testScript(final ScriptProcess script) throws InterruptedException, Timeout } builder.append(line); } - final ModelNode result = ModelNode.fromString(builder.toString()); - if (!Operations.isSuccessfulOutcome(result)) { - Assert.fail(result.asString()); + final String modelNodeInput = builder.toString(); + try { + return ModelNode.fromString(modelNodeInput); + } catch (Exception e) { + Assert.fail(String.format("Cannot convert %s into a ModelNode -- %s", modelNodeInput, e)); + throw new IllegalStateException("unreachable"); } - Assert.assertEquals(ClientConstants.CONTROLLER_PROCESS_STATE_RUNNING, Operations.readResult(result).asString()); } }