You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2022/12/19 14:33:13 UTC

[maven-surefire] branch master updated: [SUREFIRE-2135] Use native.encoding for ps parse

This is an automated email from the ASF dual-hosted git repository.

sjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git


The following commit(s) were added to refs/heads/master by this push:
     new 12b9679dc [SUREFIRE-2135] Use native.encoding for ps parse
12b9679dc is described below

commit 12b9679dcb4c6ca2c573f2d5aa0f98ccf1c33dac
Author: Pabst, Andreas <an...@zeiss.com>
AuthorDate: Sun Dec 18 23:08:28 2022 +0100

    [SUREFIRE-2135] Use native.encoding for ps parse
    
    - Use the value of the system property native.encoding as charset for
      parsing the output of the ps command that ForkedBooter issues on
      Unix-like OSes when checking if the forked process is still alive
    - Fall back to file.encoding if native.encoding is absent (pre-JDK17)
    - Fall back further to UTF-8 if file.encoding is not explicitly given
    - Remove an unnecessary System.out.println in a test that was probably
      committed by accident
    
    This fixes the ConsoleOutputIT on Java 18 and above.
---
 .../src/main/java/org/apache/maven/surefire/booter/PpidChecker.java   | 4 ++--
 .../test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java   | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java
index e21264bd4..d908dab4a 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/PpidChecker.java
@@ -26,7 +26,6 @@ import javax.annotation.Nonnull;
 import java.io.File;
 import java.io.IOException;
 import java.io.InterruptedIOException;
-import java.nio.charset.Charset;
 import java.nio.file.Path;
 import java.text.SimpleDateFormat;
 import java.util.Queue;
@@ -170,7 +169,8 @@ final class PpidChecker
     // http://hg.openjdk.java.net/jdk7/jdk7/jdk/file/9b8c96f96a0f/test/java/lang/ProcessBuilder/Basic.java#L167
     ProcessInfo unix()
     {
-        ProcessInfoConsumer reader = new ProcessInfoConsumer( Charset.defaultCharset().name() )
+        String charset = System.getProperty( "native.encoding", System.getProperty( "file.encoding", "UTF-8" ) );
+        ProcessInfoConsumer reader = new ProcessInfoConsumer( charset )
         {
             @Override
             @Nonnull
diff --git a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java
index c5d916e5e..33dc7f92e 100644
--- a/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java
+++ b/surefire-booter/src/test/java/org/apache/maven/surefire/booter/PpidCheckerTest.java
@@ -122,7 +122,6 @@ public class PpidCheckerTest
     public void shouldHavePid() throws Exception
     {
         String expectedPid = ManagementFactory.getRuntimeMXBean().getName().split( "@" )[0].trim();
-        System.out.println( "java version " + System.getProperty( "java.version" ) + " expectedPid=" + expectedPid );
 
         PpidChecker checker = new PpidChecker( expectedPid );
         setInternalState( checker, "parentProcessInfo",